如何使用Android NDK在线程上插入断点而不会崩溃?

时间:2012-08-02 14:45:03

标签: android debugging android-ndk gdb

我正在使用我的android项目调试一些代码。

我遇到了让gdb在次要线程上遇到断点的问题。当它们被设置在主线程上时,一切正常,但是一旦在次要线程上遇到断点,我的应用程序就会崩溃。

我在网上搜索过,有些人说ndk使用旧版本的GDB,但现在这似乎无关紧要(因为ndk r8附带的版本给出了7.3.1)。另一个网站曾说过,包含的gdb版本是在没有多线程支持的情况下编译的,但我似乎无法验证这一点。

其他详情:

  • 设备:Nexus S
  • 操作系统:Android 4.1.1

我不确定这是否相关,但是当我将调试器附加到正在运行的应用程序时,我得到以下输出(似乎只有符号问题):

warning: .dynamic section for "/home/sandy/workspace/tumbleweed/obj/local/armeabi-v7a/linker" is not at the expected address (wrong library or version mismatch?)
warning: Could not load shared library symbols for 78 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: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers and track explicitly loaded dynamic code.

另外,这是运行ndk-gdb时的详细输出--verbose:

Android NDK installation path: /home/sandy/workspace/android-ndk-r8b
Using default adb command: /home/sandy/workspace/android-sdk/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.29
Using ADB flags: 
Using auto-detected project path: .
Found package name: com.sandroid.tumbleweed
ABIs targetted by application: jni/../libs
/home/sandy/workspace/tumbleweed/libs/gtest-1.6.0
/home/sandy/workspace/tumbleweed/libs/gtest-1.6.0/lib/.libs/libgtest.a
armeabi-v7a
Device API Level: 16
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi-v7a
Using gdb setup init: ./libs/armeabi-v7a/gdb.setup
Using toolchain prefix: /home/sandy/workspace/android-ndk-r8b/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi-v7a
Found debuggable flag: true
Found device gdbserver: /data/data/com.sandroid.tumbleweed/lib/gdbserver
Found data directory: '/data/data/com.sandroid.tumbleweed'
Found running PID: 3539
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: adb_cmd shell run-as com.sandroid.tumbleweed lib/gdbserver +debug-socket --attach 3539
## COMMAND: adb_cmd forward tcp:5039 localfilesystem:/data/data/com.sandroid.tumbleweed/debug-socket
## COMMAND: adb_cmd pull /system/bin/app_process ./obj/local/armeabi-v7a/app_process
Attached; pid = 3539
Listening on sockaddr socket debug-socket
118 KB/s (9572 bytes in 0.078s)
Pulled app_process from device/emulator.
## COMMAND: adb_cmd pull /system/bin/linker ./obj/local/armeabi-v7a/linker
844 KB/s (79976 bytes in 0.092s)
Pulled linker from device/emulator.
## COMMAND: adb_cmd pull /system/lib/libc.so ./obj/local/armeabi-v7a/libc.so
1662 KB/s (286500 bytes in 0.168s)
Pulled libc.so from device/emulator.

当应用程序崩溃时,我明白了:

Child terminated with signal = 5 
Child terminated with signal = 0x5 (SIGTRAP)
GDBserver exiting

1 个答案:

答案 0 :(得分:0)

我发布这篇文章已经有一段时间了,但我想我还记得搞清楚了。事实证明我最近更新了NDK版本,并没有完全迁移到旧NDK目录的所有引用。在将旧的NDK目录完全移动到备份目录后,我修复了Eclipse项目中的延迟引用。重建后,这似乎解决了我的问题。

TL; DR:确保您的NDK引用正确无误。