我正在使用 ndk-r9,我正在努力让 ndk-gdb 为我工作。我已经启动了一个名为“LittlestAndroid”的小型 android 应用程序,它对返回硬编码字符串的本机 C++ 方法进行简单调用。该应用程序构建/安装/运行得很好。现在我重新利用该应用程序来了解 ndk-gdb。我在清单中设置了 debuggable="true" 。我在我的 make 中设置了这些环境变量:
APP_OPTIM=debug
LOCAL_CFLAGS := -g
我已经破解了 $NDK_HOME/build/core/build-binary.mk 文件,使用以下命令有条件地去除调试符号:
$(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
当我尝试对模拟器进行调试时,我得到了这个:
~/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.
退出并尝试再次附加 gdb 后(没有在模拟器上单击“强制关闭”),我得到了这个:
~/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.
我错过了什么或做错了什么?在任何一种情况下,我都无法让调试器连接和/或继续执行我的应用程序。我也尝试在启动 ndk-gdb 后设置断点,但我得到以下信息:
(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)
有没有人成功运行过 ndk-gdb,如果有,你能提供指导吗?我已经到处搜索了,但除了最基本的教程外,我什么也找不到,也没有深入解释如何实际设置断点(我是像上面那样使用我的 cpp 的相对路径还是只指示文件基名?)或如何解决我看到的错误。
更新 我刚刚发现这个问题似乎表明 ndk-r9 中存在问题。我会下载一个较早的版本并试一试。