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

发布于 2024-11-05 09:09:27 字数 90 浏览 0 评论 0原文

我想用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜柠檬 2024-11-12 09:09:27

在 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?

桃扇骨 2024-11-12 09:09:27

OMAPpedia 的 Android 调试 页面很好地概述了如何使用 gdbclient。

gdbclient <executable name> <port number> <task name>
  • 可执行文件名称:系统/bin目录下的文件名
  • 端口号:默认为:5039(数字前需要冒号)
  • 任务名称:获取通过在目标上运行“ps”。 GDB用它来内部识别PID。

您可能需要先使用 adb 设置端口转发,如下所示:

adb forward tcp:5039 tcp:5039

OMAPpedia's Android Debugging page has a good overview of using gdbclient.

gdbclient <executable name> <port number> <task name>
  • executable name: file name in system/bin dir
  • port number: default is :5039 (need the colon before the number)
  • task name: obtained by running "ps" on the target. GDB uses it to identify the PID internally.

You may need to set up a port forward with adb first, like so:

adb forward tcp:5039 tcp:5039
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文