Android NDK + GDB

时间:2013-04-29 18:11:08

标签: android android-ndk gdb native ndk-gdb

请帮我使用ndk-gdb!

我搜索了StackOverflow和其他互联网=)但仍然做错了。

配置:MacOSX 64 +最新SDK +最新NDK +最新IDEA + Nexus 7 +巨大C ++项目。

我做了所有共同的安排:

  • -g -ggdb -O0LOCAL_CFLAGS(仅尝试了-g
  • APP_OPTIM := debug
  • 清单中的
  • debuggable=«true»
  • ndk-build NDK_DEBUG=1

我得到了预期的gdb.setup和gdbserver文件,但是nm命令在我的* .so文件中给出零输出。

我在项目的根文件夹中运行ndk-gdb并开始使用GDB - 例如我可以暂停应用程序并恢复它,可以在地址上获取ASM代码等等。即使我用break Class::method设置制动点,gdb也会告诉我正确的文件名和行号。

但断点没有达到99%。 Backstack总是显然是错误的(错误的方法名称)。看起来所有符号名称和地址映射错误。

我错过了什么?

UPD。 gdb在开始时输出两个命令info sharedlibraryC

:ndk-gdb

/android-ndk-macosx/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than >android:minSdkVersion 8 in ./AndroidManifest.xml
/android-ndk-macosx/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than >android:minSdkVersion 8 in ./AndroidManifest.xml
/android-ndk-macosx/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than >android:minSdkVersion 8 in ./AndroidManifest.xml
/android-ndk-macosx/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than >android:minSdkVersion 8 in ./AndroidManifest.xml

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: .dynamic section for "/Users/<...>/android/obj/local/armeabi/lib1.so" is not at the expected address (wrong library or version >mismatch?)
warning: Could not load shared library symbols for 73 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 0x400aca53 to 0x400aca52.
0x401a7ee4 in epoll_wait () from /Users/<...>/android/obj/local/armeabi/libc.so
(gdb) info sharedlibrary
From        To          Syms Read   Shared Object Library
0x400aa220  0x400b2978  Yes (*)     /Users/<...>/android/obj/local/armeabi/linker
0x4019c860  0x401cc184  Yes (*)     /Users/<...>/android/obj/local/armeabi/libc.so
                        No          libstdc++.so
                        No          libm.so

<...dozens of system libs with "no"...>

                        No          libjnigraphics.so
0x6749c160  0x67527844  Yes (*)     /Users/<...>/android/obj/local/armeabi/lib1.so
0x65c487f8  0x65c6634c  Yes (*)     /Users/<...>/android/obj/local/armeabi/lib2.so
0x693e62e8  0x699dcd90  Yes         /Users/<...>/android/obj/local/armeabi/lib3.so
(*): Shared library is missing debugging information.
(gdb) C
Continuing.>

你可以看到

  • lib3.so(主lib)加载最正确(或不是?)
  • 调整断点地址(这是什么意思?)

1 个答案:

答案 0 :(得分:6)

好的,最后我做到了。该点位于APP_ABI的{​​{1}}行。有两个ABI,不知怎的,这混淆了GDB。现在它适用于一个abi(我选择了Application.mk)。

还有一点,我也想注意

  • 你真的不需要做任何事情来使GDB工作。只是不要打扰他=)
  • 每个变量(cflag或清单标签等)都有适合调试的默认值,但不管怎样,我建议你在{{1}中明确设置armeabi-v7aAPP_OPTIM := debug };清单中为APP_CFLAG := -g -ggdb -O0Application.mkandroid:debuggable="true"。我还没弄清楚他们是否能以某种方式帮助GDB更好地工作。其中一些是彼此重复的。当然,没有一个人不会做得更糟。
  • NDK_DEBUG=1
  • 是正常的
  • ndk-build命令。我也不太了解它,但它一直给我在我想要检查的每个文件上的零输出。真正重要的是 - 在工作GDB中输出Breakpoint address adjusted命令。检查您的图书馆是否有符号(例如上面示例中的NM)。这是必要的,但还不够。