ndk-gdb: unable to connect before a crash

488 views
Skip to first unread message

Jon Paul Schelter

unread,
Feb 14, 2011, 10:58:02 AM2/14/11
to android-ndk
I have an application which crashes fairly early on when run on a device (Nexus One, 2.2.3 rooted)  - the application mixes java initialization and native code, and I'm trying to debug with ndk-gdb.  

On the emulator, the debugger would connect before the application got very far, but on the device, the application launches much faster, and the crash occurs before the debugger can attach. 

If I modify the ndk-gdb script to launch the application with "adb shell am -D ...", the application does not seem to detect the fact that gdb has actually attached. - it ends up stuck at the "Waiting For Debugger" dialog.  

The application does not explicitly wait for the debugger to attach in code, and adding Debug.watiForDebugger() to the OnCreate method seems to give the same behaviour, minus the modal dialog - the application "waits for the debugger" and despite the fact that gdb _is_ attached, does not proceed. 

<<
## COMMAND: /Developer/android-sdk-mac_x86/platform-tools/adb shell am start -n com.example.app/.MainActivity
Starting: Intent { cmp=com.example.app/.MainActivity }
## COMMAND: /Developer/android-sdk-mac_x86/platform-tools/adb shell sleep 2
Found running PID: 1482
Killing existing debugging session
## COMMAND: /Developer/android-sdk-mac_x86/platform-tools/adb shell kill -9 1412
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: /Developer/android-sdk-mac_x86/platform-tools/adb forward tcp:5039 localfilesystem:/data/data/com.example.app/debug-socket
## COMMAND: /Developer/android-sdk-mac_x86/platform-tools/adb shell run-as com.example.app.lib/gdbserver +debug-socket --attach 1482
## COMMAND: /Developer/android-sdk-mac_x86/platform-tools/adb pull /system/bin/app_process /Developer/Projects/ECS/DIGG/Projects/droid/obj/local/armeabi/app_process
Attached; pid = 1482
Listening on sockaddr socket debug-socket
896 KB/s (5680 bytes in 0.006s)
Pulled app_process from device/emulator.
## COMMAND: /Developer/android-sdk-mac_x86/platform-tools/adb pull /system/lib/libc.so /Developer/Projects/Application/droid/obj/local/armeabi/libc.so
1626 KB/s (278268 bytes in 0.167s)
Pulled libc.so from device/emulator.
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=i686-apple-darwin --target=arm-elf-linux".
(no debugging symbols found)
Error while mapping shared library sections:
/system/bin/linker: No such file or directory.
Error while mapping shared library sections:
libstdc++.so: No such file or directory.
....

warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0xafd0eb68 in __futex_syscall3 ()
   from /Developer/Projects/Application/droid/obj/local/armeabi/libc.so
(gdb) info thr
  7 Thread 1489  0xafd0dbac in __ioctl ()
   from /Developer/Projects/Application/droid/obj/local/armeabi/libc.so
  6 Thread 1488  0xafd0dbac in __ioctl ()
   from /Developer/Projects/Application/droid/obj/local/armeabi/libc.so
  5 Thread 1487  0xafd0eb68 in __futex_syscall3 ()
   from /Developer/Projects/Application/droid/obj/local/armeabi/libc.so
  4 Thread 1486  0xafd0dcd4 in select ()
   from /Developer/Projects/Application/droid/obj/local/armeabi/libc.so
  3 Thread 1485  0xafd0e45c in __rt_sigtimedwait ()
   from /Developer/Projects/Application/droid/obj/local/armeabi/libc.so
  2 Thread 1484  0xafd0eb68 in __futex_syscall3 ()
   from /Developer/Projects/Application/droid/obj/local/armeabi/libc.so
  1 Thread 1482  0xafd0eb68 in __futex_syscall3 ()
   from /Developer/Projects/Application/droid/obj/local/armeabi/libc.so
(gdb) bt
#0  0xafd0eb68 in __futex_syscall3 ()
   from /Developer/Projects/Application/droid/obj/local/armeabi/libc.so
#1  0xafd10634 in __pthread_cond_timedwait_relative ()
   from /Developer/Projects/Application/droid/obj/local/armeabi/libc.so
#2  0xafd10708 in __pthread_cond_timedwait ()
   from /Developer/Projects/Application/droid/obj/local/armeabi/libc.so
#3  0x8084d474 in ?? ()
>>

Any pointers?

As I mentioned in a previous post, I don't seem to be able to run the Development.apk from the 2.2. emulator on this device, and I've also tried adding   <uses-permission android:name="android.permission.SET_DEBUG_APP"></uses-permission> to my manifest, to no avail.

thanks in advance!

JP

alan

unread,
Feb 14, 2011, 11:39:29 AM2/14/11
to andro...@googlegroups.com
set a breakpoint in the java before you load the native library. run the project so that eclipse is sat on the java breakpoint. at this point you should be able to attach gdb

Jon Paul Schelter

unread,
Feb 14, 2011, 12:00:07 PM2/14/11
to andro...@googlegroups.com
Thanks for the suggestion Alan! I'll have to use that if nothing else
works, but I'm trying _not_ to use eclipse.

The docs claim that you can launch the application with ndk-gdb
(--force --start) - that would seem to be fairly useless if there was
no way that gdb could connect before the app crashes.

Does anyone know if "adb -D" or "waitForDebugger()" are *supposed* to
wait for a gdb connection too? I haven't found any documentation that
is clear on it.

best, JP
----------------
http://forksandhope.com/
"This isn't right; it isn't even wrong." - W. Pauli

> --
> You received this message because you are subscribed to the Google Groups
> "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to
> android-ndk...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/android-ndk?hl=en.
>

Jon Paul Schelter

unread,
Feb 14, 2011, 12:13:32 PM2/14/11
to andro...@googlegroups.com
Oh, and just FYI, my current solution is to just do a "sleep(8);" in
my native code to give gdb time to attach. It's hacky, but works for
now.

best,
JP
----------------

Reply all
Reply to author
Forward
0 new messages