50

I have an app that runs perfectly fine on a device without a debugger attached. However, I have a problem when debugging in Eclipse:

When the main thread is suspended for about 10 seconds or more (for example after hitting a breakpoint), the main thread throws a SIGABRT, apparently coming from libc.

The only explanation I could think of is that the message queue on the main thread, when not being polled, is overflowing with messages coming from another thread. However, I don't see the heap growing when the main thread is suspended. Moreover, while my app has about 20 threads between all services, content providers, broadcast receivers, http and map worker threads, etc., I can't really think of a source of any excessive messages.

So my question is: How do I fix this problem? What tools can I use and how do I go about finding what is causing my app to crash while sitting suspended in the debugger?

Edit 1:

The only thing in logcat is:

02-05 22:23:54.861: I/dalvikvm(26795): threadid=3: reacting to signal 3
02-05 22:23:54.901: D/dalvikvm(26795): threadid=1: still suspended after undo (sc=1 dc=1)
02-05 22:23:54.901: I/dalvikvm(26795): Wrote stack traces to '/data/anr/traces.txt'
02-05 22:23:58.905: A/libc(26795): Fatal signal 6 (SIGABRT) at 0x000002f5 (code=0), thread 26795 (om.myapp)

Edit 2:

Further investigation leads me to believe it is android intentionally killing my process because it mistakenly thinks the UI thread is hung. The problem is NOT in my app. So now my question is: How do I stop Android from killing my process while debugging?

zyamys
  • 1,609
  • 1
  • 21
  • 23
  • I have found no solution so far. – zyamys Apr 17 '14 at 10:05
  • My problem had something to do with threads, calling a function at the wrong time or recursive calls itself (stack overflow). Changing this solves the problem. – Codebeat Apr 22 '15 at 19:38
  • @zyamys Is your problem solved? I have the same issue. Please let me if you solved . – Md Maidul Islam Sep 11 '15 at 09:45
  • @Maid786 Same problem here, did you find a way to fix it? – Virthuss Oct 30 '15 at 02:13
  • I faced with the same problem. The reason was unavailable proxy server. I used fiddler to sniff API requests and when I had closed Fiddler on my computer, I got crash on Android device. Device is LG E988 (Android 4.4) – John Smith Sep 28 '16 at 07:08
  • Check your logcat. If you see repetitive logs suggesting some exception is happening in a infinite loop causing log buffer overflow, that could be the reason why you are not able to attach debugger to your process. The same thing happened to me and I noticed a part of my app's code was being executed in a loop. I just commented it out and voila! debugger works. – kdas Jun 01 '18 at 16:42

3 Answers3

27

android intentionally kills the process because it thinks the UI thread is hung, so its a ANR right. for debugging purposes you can,

Go to Settings -> Developer options and check Show all ANRs.

This will show an App Not Responding dialog for apps running in the background. You can click the Wait button in the dialog to prevent the system from killing your process until the debugger attaches. Note that the dialog is opened automatically for apps running in the foreground. For background apps, you have to enable this option

Aditya P
  • 1,024
  • 11
  • 10
  • 4
    Still crashes with the `fatal signal 6` on an LG optimus G v4.4.2. A good explanation though. – AlikElzin-kilaka Oct 22 '14 at 15:52
  • 18
    The problem is that if a garbage collect takes up to three seconds (have that happen regularly) that the OS will kill the VM (and thus your app). There is _nothing_ you as a programmer can do about that except to curse google for their insistence on killing your app because of their incompetence. –  May 07 '15 at 20:11
9

This started happening to me in android 7.1.1

When attaching debugger my app always crashed, same when starting app in debug mode.

What fixed it for me is simply:

  • Run your app
  • Click on "Mute Breakpoints" in Debug
  • Attach the debugger
  • Re-Click on "Mute Breakpoints" to unmute
  • Done, debugging works again
sam
  • 4,357
  • 5
  • 29
  • 34
  • Ran into this same issue, using a Nexus 5x on Android 7.1.1, though I am also seeing similar behavior in a Galaxy S6 Edge on Android 6.0.1. Muting the breakpoints as stated worked well. Likewise, starting the debugger without any breakpoints assigned is a similar approach that also works – Brad Jan 11 '17 at 22:10
  • I'm also seeing this with 7.1.1 using an emulator when running in debug mode from Android Studio. App starts ok, but when i go into an activity with a ListView it sh!ts itself. If I run in normal mode from Android Studio it's fine. – Nick Wright Jan 12 '17 at 17:00
2

I had similar issues, but what Sam suggested didn't help - I had to actually REMOVE the breakpoints and then it worked for me.

DustinB
  • 11,037
  • 5
  • 46
  • 54