I'm using ndk-r9 and I am struggling trying to get ndk-gdb to work for me. I've started a small android app called "LittlestAndroid" which makes a simple call to a native C++ method that returns a hardcoded string. The app builds/installs/run just fine. Now I'm repurposing the app to learn about ndk-gdb. I've set debuggable="true" in the manifest. I've set these env vars in my make:
APP_OPTIM=debug
LOCAL_CFLAGS := -g
and I've hacked the $NDK_HOME/build/core/build-binary.mk file to conditionally strip debug symbols using the following:
$(LOCAL_INSTALLED): $(LOCAL_BUILT_MODULE) clean-installed-binaries
@$(HOST_ECHO) "Install : $(PRIVATE_NAME) => $(call pretty-dir,$(PRIVATE_DST))"
$(hide) $(call host-install,$(PRIVATE_SRC),$(PRIVATE_DST))
# $(hide) $(PRIVATE_STRIP_CMD)
# CCC Modifications start
ifneq ($(APP_OPTIM),debug)
@ $(HOST_ECHO) "Stripping the library for the release mode....."
$(hide) $(PRIVATE_STRIP_CMD)
endif
# CCC Modifications end
#$(hide) $(PRIVATE_OBJCOPY_CMD)
$(call generate-file-dir,$(LOCAL_INSTALLED))
endif
When I try to debug against the emulator I get this:
~/workspace/LittlestAndroid$ ndk-gdb -s emulator-5554 --start
java.io.IOException: handshake failed - connection prematurally closed
at com.sun.tools.jdi.SocketTransportService.handshake(SocketTransportService.java:136)
at com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:232)
at com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:116)
at com.sun.tools.jdi.SocketAttachingConnector.attach(SocketAttachingConnector.java:90)
at com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:519)
at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:328)
at com.sun.tools.example.debug.tty.Env.init(Env.java:63)
at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1066)
Fatal error:
Unable to attach to target VM.
GNU gdb (GDB) 7.3.1-gg2
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin --target=arm-linux-android".
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>.
warning: Could not load shared library symbols for 66 libraries, e.g. libstdc++.so.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
warning: Breakpoint address adjusted from 0x40005a53 to 0x40005a52.
0x400380e0 in __futex_syscall3 () from /Users/clifton/workspace/LittlestAndroid/obj/local/armeabi/libc.so
(gdb) quit
A debugging session is active.
Inferior 1 [Remote target] will be detached.
Quit anyway? (y or n) y
Ending remote debugging.
After quitting and attempting to attach gdb again (without clicking "force close" on the emulator) I get this:
~/workspace/LittlestAndroid$ ndk-gdb -s emulator-5554
GNU gdb (GDB) 7.3.1-gg2
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin --target=arm-linux-android".
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>.
warning: Could not load shared library symbols for 66 libraries, e.g. libstdc++.so.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
warning: Breakpoint address adjusted from 0x40005a53 to 0x40005a52.
0x400380e0 in __futex_syscall3 () from /Users/clifton/workspace/LittlestAndroid/obj/local/armeabi/libc.so
(gdb) c
Continuing.
Am I missing something or doing something wrong? In either case I cannot get the debugger to connect and/or resume executing my app. I've also tried setting breakpoints after starting ndk-gdb but I get the following:
(gdb) b libs/info.cpp:7
No symbol table is loaded. Use the "file" command.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (libs/info.cpp:7) pending.
(gdb)
Has anyone ever successfully run ndk-gdb and if so could you provide guidance? I've googled all over but I could find nothing other than the most basic tutorials and nothing goes into depth explaining how to actually set breakpoints (do I use relative paths to my cpp as above or just indicate the file base name?) or how to resolve the errors I'm seeing.
UPDATE I just found this question which seems to indicate a problem in ndk-r9. I'll download an earlier version and give it a shot.
Yes, there is indeed an issue with the latest ndk-r9 debugging tools. After downgrading to revision 8e everything seems to work as advertised.
Update
I just tried the latest 9d NDK and the problem still exists, though the error is slightly different. I attempted to debug my app on a Motorola G running 4.4 and the debugger threw a socket error trying to establish a connection.
2nd Update I was thinking about this ancient issue wondering if the NDK has an affinity to the particular OS. In other words do the latest NDK versions work with the later OSes? I tried V9 on 4.4 and failed, but would 9 work on 5.0 or 5.5? Food for thought...