简体   繁体   English

如何在Android上使用GDB运行Dalvik可执行文件?

[英]How to run a Dalvik executable with GDB on Android?

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. 我想用GDB调试Android上的应用程序,我可以使用gdb和进程号对其进行挂钩,但是我想从一开始就了解它的作用。

Would there be any way to do that? 有什么办法可以做到吗?

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. 在具有root用户权限的设备或仿真器上,您可能能够将gdb附加到zygote,并在新分叉的进程将要假定正在启动的应用程序的位置处放置一个断点。

It would probably be easiest if you modified zygote to wait for the debugger to attach. 如果您修改了zygote以等待调试器附加,这可能是最简单的。 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. 我相信Jdwp调试系统中有这样的东西可以让您在启动该代码的早期就进入Java调试器,但是我不知道已经可以与内置的gdb相提并论。尽管我想您可以等待它。 for jdwp,并在附加(然后分离)java调试器之前附加gdb。

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. 更新:我通过使用gdb附加到zygote并修改将由孩子早期执行的单字代码进入无限循环,然后从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. 我想我会在新孩子出现在“ ps”中后立即对其进行gdb并将其还原,以便继续进行。 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's Android Debugging page has a good overview of using gdbclient. OMAPpedia的Android调试页面全面介绍了如何使用gdbclient。

gdbclient <executable name> <port number> <task name>
  • executable name: file name in system/bin dir 可执行文件名称: system / bin目录中的文件名
  • port number: default is :5039 (need the colon before the number) 端口号:默认为:5039(需要在冒号之前加上冒号)
  • task name: obtained by running "ps" on the target. 任务名称:通过在目标上运行“ ps”获得。 GDB uses it to identify the PID internally. GDB使用它在内部识别PID。

You may need to set up a port forward with adb first, like so: 您可能需要先使用adb设置端口转发,如下所示:

adb forward tcp:5039 tcp:5039

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

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