c – Android调试本机代码

我正在使用ndk-r9,我正在努力让ndk-gdb为我工作.我已经启动了一个名为“Littlest
Android”的小型
Android应用程序,它可以简单地调用返回硬编码字符串的本机C方法.该应用程序构建/安装/运行就好了.现在我正在重新利用该应用程序来了解ndk-gdb.我在清单中设置了debuggable =“true”.我在我的作品中设置了这些env vars:

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的相对路径或仅指示文件基本名称?)或如何解决我看到的错误.

UPDATE
我刚刚发现了this question,这似乎表明ndk-r9存在问题.我将下载一个早期版本并试一试.

最佳答案 是的,最新的ndk-r9调试工具确实存在问题.在降级到版本8e后,一切似乎都像宣传的那样有效.

更新

我刚刚尝试了最新的9d NDK,问题仍然存在,尽管错误略有不同.我试图在运行4.4的Motorola G上调试我的应用程序,并且调试器在尝试建立连接时抛出了套接字错误.

第二次更新
我正在考虑这个古老的问题,想知道NDK是否与特定操作系统有亲和力.换句话说,最新的NDK版本是否适用于后来的操作系统?我在4.4上尝试了V9并且失败了,但是9会在5.0或5.5上工作吗?值得思考的东西……

点赞