如何让 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:05:11  来源:igfitidea点击:

How to get ndk-gdb working on Android?

androidandroid-ndkgdbsymbols

提问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 开关。您需要执行以下操作之一:

  1. put android:debuggable="true"to the <application>tag in AndroidManifest.xmlfile
  2. use NDK_DEBUG=1after ndk-build
  3. put APP_OPTIM := debugin Application.mk file
  1. 放入文件中android:debuggable="true"<application>标签AndroidManifest.xml
  2. NDK_DEBUG=1在 ndk-build 后使用
  3. 放入APP_OPTIM := debugApplication.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 吗?它包括以下步骤:

  1. pushing gdbserverfile to /data/localfolder on device
  2. running your application & invoking in adb shellfollowing command gdbserver :5055 --attach PID, where PID is your application process id.
  3. running adb forward tcp:5055 tcp:5055on host
  4. running arm-linux-androideabi-gdb.exefrom your app folder
  5. entering following commands in gdb
  6. set solib-search-path obj/local/armeabi
  7. file obj/local/armeabi/libMySharedLib.so
  8. target remote :5055
  1. gdbserver文件推送到/data/local设备上的文件夹
  2. 运行您的应用程序并在adb shell以下命令中调用gdbserver :5055 --attach PID,其中 PID 是您的应用程序进程 ID。
  3. adb forward tcp:5055 tcp:5055在主机上运行
  4. arm-linux-androideabi-gdb.exe从您的应用程序文件夹运行
  5. 在 gdb 中输入以下命令
  6. set solib-search-path obj/local/armeabi
  7. file obj/local/armeabi/libMySharedLib.so
  8. 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/libfolder) to your obj/local/armeabifolder.

如果您想查看您的库正在使用的其他共享库的符号,例如libc.so,请将它们从设备(从/system/lib文件夹)拉到您的obj/local/armeabi文件夹。