简体   繁体   English

如何调试本机Android平台代码?

[英]How can I debug native Android platform code?

I'm interested in learning about the Android runtime (ART) and I'd like to be able to put a debugger on it so I can step through the code. 我对了解Android运行时(ART)感兴趣,并且希望能够在其上放置调试器,以便逐步完成代码。 I have an AOSP build that I've been running on an emulator. 我有一个已经在模拟器上运行的AOSP构建。

What's the best way to attach and run source? 附加和运行源代码的最佳方法是什么? Should I just use gdbserver on the emulator? 我应该只在模拟器上使用gdbserver吗? Are there any IDEs that people use for native debugging? 人们是否使用任何IDE进行本机调试?

If you want to debug native code, you're going to need the source, which of course means getting the AOSP. 如果要调试本机代码,则将需要源代码,这当然意味着要获得AOSP。 After you've setup the AOSP, do the following: 设置AOSP之后,请执行以下操作:

  1. In your AOSP directory, run "choosecombo". 在您的AOSP目录中,运行“ choosecombo”。 Select "debug" and pick an "eng" build of your choice. 选择“调试”,然后选择一个“ eng”版本。
  2. Build the AOSP 建立AOSP
  3. Start the emulator (ie: on Linux, "emulator &") 启动模拟器(即:在Linux上为“模拟器&”)
  4. adb shell into the emulator and run "setprop debug.db.uid 32767". 将adb shell插入仿真器并运行“ setprop debug.db.uid 32767”。 This prevents debuggerd from attaching to a process that it thinks has halted and causing problems. 这样可以防止调试器附加到它认为已停止并导致问题的进程。 See system/core/debuggerd/debuggerd.cpp in the AOSP for more info. 有关更多信息,请参阅AOSP中的system / core / debuggerd / debuggerd.cpp。
  5. In the same shell that you built the AOSP, run "gdbclient [process name]". 在构建AOSP的同一外壳中,运行“ gdbclient [进程名称]”。 This will attach and load the debugging information for the process you are interested in. You can also attach to a pid, but you will end up having to load the symbol information yourself. 这将为您感兴趣的过程附加并加载调试信息。您也可以附加到pid,但是最终将不得不自己加载符号信息。
  6. Enjoy debugging native Android platform code 享受调试本机Android平台代码的乐趣

看起来您已经明白了,但仅出于完整性考虑,以下是一些官方文档的链接,这些文档基本上涵盖了您所说的内容: http : //source.android.com/devices/tech/debug/index.html

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

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