如何让 ndk-gdb 在 Android 上运行? [英] How to get ndk-gdb working on Android?
问题描述
我正在尝试让 NDK 调试器正常工作,但目前没有成功.
I'm trying to get the NDK debugger working but with no success so far.
为了确保我的调试符号存在且有效,我使用了编译器选项 -O0 和 -g,以及 ndk-build 参数 NDK_DEBUG=1.
To make sure my debug symbols are present and valid, I use the compiler options -O0 and -g, and the ndk-build parameter NDK_DEBUG=1.
ndk-gdb 脚本运行没有问题并启动 GDB.当执行sharedlibrary"命令时,我得到这个:
The ndk-gdb script runs with out issues and launches GDB. When do a "sharedlibrary" command, I get this:
Symbols already loaded for /bla/bla/libMySharedLib.so
但是,当我尝试中断执行或例如添加段错误进行测试,我从未在调用堆栈中从该库中获取任何符号.我得到的唯一符号来自 libc,例如,如果我在等待互斥锁时中断执行.还尝试在没有运气的情况下添加断点.GDB 允许我添加断点,并且代码运行良好,但从未触发断点.
However when I try breaking execution or e.g. adding a segfault to test, I never get any of the symbols from that library in the call stack. The only symbols I've gotten are from libc, if I break execution while it's waiting for a mutex for instance. Also tried adding breakpoints with no luck. GDB lets me add the breakpoints, and the code runs fine, but the breakpoints are never triggered.
我使用 API 级别 8,因为我需要支持 Android 2.2 (Froyo).
I'm using API level 8 as I need to support Android 2.2 (Froyo).
推荐答案
您不需要使用 -O0 或 -g 开关.您需要执行以下操作之一:
You don't need to use -O0 or -g switches. You need to do one of following:
- 将
android:debuggable="true"
放到AndroidManifest.xml
文件中的
标签 - 在 ndk-build 之后使用
NDK_DEBUG=1
- 将
APP_OPTIM := debug
放入 Application.mk 文件中
- put
android:debuggable="true"
to the<application>
tag inAndroidManifest.xml
file - use
NDK_DEBUG=1
after ndk-build - put
APP_OPTIM := debug
in Application.mk file
执行这三件事中的任何一件都会自动使用 -O0 和 -g 开关.
Doing anyone of these three things will automatically use -O0 and -g switches.
您可以尝试在没有 gdb 脚本的情况下手动运行 gdb 吗?它包括以下步骤:
Can you try running gdb manually, without gdb script? It involves following steps:
- 将
gdbserver
文件推送到设备上的/data/local
文件夹 - 运行您的应用程序 &在
adb shell
中调用以下命令gdbserver :5055 --attach PID
,其中 PID 是您的应用程序进程 ID. - 在主机上运行
adb forward tcp:5055 tcp:5055
- 从你的应用程序文件夹运行
arm-linux-androideabi-gdb.exe
- 在 gdb 中输入以下命令
设置solib-search-path obj/local/armeabi
文件 obj/local/armeabi/libMySharedLib.so
目标远程:5055
- pushing
gdbserver
file to/data/local
folder on device - running your application & invoking in
adb shell
following commandgdbserver :5055 --attach PID
, where PID is your application process id. - running
adb forward tcp:5055 tcp:5055
on host - running
arm-linux-androideabi-gdb.exe
from your app folder - entering following commands in gdb
set solib-search-path obj/local/armeabi
file obj/local/armeabi/libMySharedLib.so
target remote :5055
然后看看你是否可以调试.
And see if you can debug then.
如果您想查看您的库正在使用的其他共享库的符号,例如 libc.so
,请将它们从设备(从 /system/lib
文件夹)拉到您的obj/local/armeabi
文件夹.
If you want see symbols for other shared libraries your library is using like libc.so
, then pull them from device (from /system/lib
folder) to your obj/local/armeabi
folder.
这篇关于如何让 ndk-gdb 在 Android 上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!