如何在 Android 上使用 GDB 运行 Dalvik 可执行文件?
我想用 GDB 调试 Android 上的应用程序,我可以用 gdb 和进程号来连接它,但我想从一开始就看看它做了什么。
有什么办法可以做到这一点吗?
I want to debug an application on Android with GDB, I can hook on it with gdb and the process number but I want to see what it does from the start.
Would there be any way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 root 设备或模拟器上,您可以将 gdb 附加到 zygote,并在新分叉的进程即将假定正在启动的应用程序的身份的位置放置一个断点。
如果您修改 zygote 以等待调试器附加,这可能是最简单的。我相信 Jdwp 调试系统中有类似的东西,可以让您在该代码启动的早期进入 Java 调试器,但我不知道与已经内置的 gdb 类似的东西。尽管我想您可以等待它对于 jdwp,并在附加(然后分离)java 调试器之前附加 gdb。
更新:我尝试了这一点,通过使用 gdb 连接到 zygote 并修改将由子进程早期执行的单个代码字以进入无限循环,然后从 zygote 分离。我想我会在新子项出现在“ps”中时立即对其进行 gdb 并恢复它,以便它可以继续。问题是孩子被杀死(大概是因为没有反应)的速度比我输入所有命令的速度要快。所以这必须通过程序来完成。如果你不停下来并杀死它,你可能不会在早期看到那么多 - 我的意思是你可能会在那里得到一些线索,但是你希望学到什么是你无法从阅读源代码中学到的?
On a rooted device or emulator you might be able to attach gdb to zygote and put a breakpoint right where the newly forked process is about to assume the identity of the application being launched.
It would probably be easiest if you modified zygote to wait for the debugger to attach. I believe there's something like this in the Jdwp debugging system that can get you into the Java debugger early in the startup of that code, but I don't know of something comparable for gdb already built in. Though I suppose you could get it waiting for jdwp, and attach gdb before you attach (and then detach) the java debugger.
Update: I tried this, by attaching to zygote with gdb and modifying a single word of code that will be executed early on by the child to go into an infinite loop, then detaching from zygote. I figured I would gdb the new child as soon as it shows up in 'ps' and restore it so that it can continue. The problem is that the child is being killed (presumably for being unresponsive) faster than I can get all the commands entered. So it would have to be done by a program. And there may not be that much you can see early on without stopping and getting it killed - I mean you could presumably get an strace in there, but what do you hope to learn that you can't learn from reading the source?
OMAPpedia 的 Android 调试 页面很好地概述了如何使用 gdbclient。
您可能需要先使用
adb
设置端口转发,如下所示:OMAPpedia's Android Debugging page has a good overview of using gdbclient.
You may need to set up a port forward with
adb
first, like so: