如何让 ndk-gdb 在 Android 上工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10534367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get ndk-gdb working on Android?
提问by Simplex
I'm trying to get the NDK debugger working but with no success so far.
我试图让 NDK 调试器工作,但到目前为止没有成功。
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.
为了确保我的调试符号存在且有效,我使用编译器选项 -O0 和 -g,以及 ndk-build 参数 NDK_DEBUG=1。
The ndk-gdb script runs with out issues and launches GDB. When do a "sharedlibrary" command, I get this:
ndk-gdb 脚本运行没有问题并启动 GDB。执行“sharedlibrary”命令时,我得到以下信息:
Symbols already loaded for /bla/bla/libMySharedLib.so
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.
但是,当我尝试中断执行或添加段错误以进行测试时,我从未在调用堆栈中从该库中获取任何符号。我得到的唯一符号来自 libc,如果我在等待互斥锁时中断执行。还尝试在没有运气的情况下添加断点。GDB 允许我添加断点,并且代码运行良好,但从未触发断点。
I'm using API level 8 as I need to support Android 2.2 (Froyo).
我使用 API 级别 8,因为我需要支持 Android 2.2 (Froyo)。
回答by Mārti?? Mo?eiko
You don't need to use -O0 or -g switches. You need to do one of following:
您不需要使用 -O0 或 -g 开关。您需要执行以下操作之一:
- 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
- 放入文件中
android:debuggable="true"
的<application>
标签AndroidManifest.xml
NDK_DEBUG=1
在 ndk-build 后使用- 放入
APP_OPTIM := debug
Application.mk 文件
Doing anyone of these three things will automatically use -O0 and -g switches.
执行这三件事中的任何一件都会自动使用 -O0 和 -g 开关。
Can you try running gdb manually, without gdb script? It involves following steps:
您可以尝试在没有 gdb 脚本的情况下手动运行 gdb 吗?它包括以下步骤:
- 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
- 将
gdbserver
文件推送到/data/local
设备上的文件夹 - 运行您的应用程序并在
adb shell
以下命令中调用gdbserver :5055 --attach PID
,其中 PID 是您的应用程序进程 ID。 adb forward tcp:5055 tcp:5055
在主机上运行arm-linux-androideabi-gdb.exe
从您的应用程序文件夹运行- 在 gdb 中输入以下命令
set solib-search-path obj/local/armeabi
file obj/local/armeabi/libMySharedLib.so
target remote :5055
And see if you can debug then.
然后看看你是否可以调试。
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.
如果您想查看您的库正在使用的其他共享库的符号,例如libc.so
,请将它们从设备(从/system/lib
文件夹)拉到您的obj/local/armeabi
文件夹。