简体   繁体   English

Android:调试共享库

[英]Android: debug shared library

I'd like to debug android NDK application, more precisely - I want to check what arguments ( r4 - r8 r1 - r4 registers) are passed to function from shared library in apk. 我想调试android NDK应用程序,更确切地说 - 我想检查哪些参数( r4-r8 r1-r4寄存器)从apk中的共享库传递给函数。

What I have tried: 我尝试过的:

  • I've run gdbserver :1234 --attach on the device 我在设备上运行了gdbserver:1234 --attach
  • I've run arm-linux-androideabi-gdb from ndk package by Google on the PC 我在PC上运行了来自谷歌的ndk软件包中的arm-linux-androideabi-gdb
  • I've set solib-search-path and written target remote :1234 我已经设置了solib-search-path和写入目标远程:1234

So far, so good. 到现在为止还挺好。 Now I try to set breakpoint ( break <function name> ) (function name from objdump), but I get repond: Cannot access memory at address <...> . 现在我尝试设置断点( break <function name> )(来自objdump的函数名),但是我得到了repond: Cannot access memory at address <...> info shared says the library is loaded, Does it mean I can't set breakpoint there? info shared表示库已加载,这是否意味着我无法在那里设置断点? Or am I doing something wrong? 或者我做错了什么?

The ndk-build skript does much more then you would expect. ndk-build skript比你期望的要多得多。
One of the things it to copy both the gdbserver , a file called gbd.setup and the generated .so 它是复制gdbserver ,一个名为gbd.setup的文件和生成的.so的东西之一
into a hidden folder called . 进入一个名为的隐藏文件夹 obj/armei/ OBJ / armei /
There you will have to add the libraries you would like to debug because the symbols are 在那里,您必须添加要调试的库,因为符号是
referencing them. 引用它们。
The libraries are copied from the device to your PC by some adb shell pull - commands. 通过一些adb shell pull-commands将库从设备复制到PC。
I wrote an article about the topic at: http://www.professional-android-development.com/articles/android-ndk-large-c-projects 我写了一篇关于这个主题的文章: http //www.professional-android-development.com/articles/android-ndk-large-c-projects
When placing the libraries into the right folder, you can set your breakpoints. 将库放入正确的文件夹时,您可以设置断点。
Still, for some internal reasons, they can fail. 不过,由于某些内部原因,他们可能会失败。
In this case run ndk-gdb --start (the first try will also fail), enforce the application to close and rerun ndk-gdb --start (this time not forcing the application to close). 在这种情况下运行ndk-gdb --start(第一次尝试也将失败),强制应用程序关闭并重新运行ndk-gdb --start(这次不强制关闭应用程序)。

"Cannot access memory at address <...>" usually means there is a mismatch between the .so file on your PC and the .so file that is on Android. “无法访问地址<...>处的内存”通常表示PC上的.so文件与Android上的.so文件不匹配。 Did you recompile and reinstall? 你重新编译并重新安装了吗?

Btw, what is the reason you're not using "ndk-gdb"? 顺便问一下,你没有使用“ndk-gdb”的原因是什么? That's a script (part of the NDK) that takes care of all the gory details for you. 这是一个脚本(NDK的一部分),可以为您处理所有的血腥细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM