【问题标题】:Android Debugging native codeAndroid 调试原生代码
【发布时间】:2013-10-05 14:44:25
【问题描述】:

我正在使用 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 的相对路径还是只指示文件基名?)或如何解决我看到的错误。

更新 我刚刚发现this question 似乎表明ndk-r9 中存在问题。我会下载一个较早的版本并试一试。

【问题讨论】:

    标签: c++ debugging android-ndk ndk-gdb


    【解决方案1】:

    是的,最新的 ndk-r9 调试工具确实存在问题。降级到修订版 8e 后,一切似乎都像宣传的那样工作。

    更新

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

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

    【讨论】:

    • Moto G 2-gen 和 Android Studio/JDK 存在同样的问题。
    • 是的,问题出在工具集中。我最近没有尝试过,但我希望他们能在最新的更新中修复它。
    • 好吧,他们没有。我正在使用最新的 SDK。
    • r10d 中的同样问题。我必须降级到 r8... :|
    • 哇,我应该看看是否有关于此的错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-26
    • 1970-01-01
    相关资源
    最近更新 更多