Android:使用 KGDB 进行内核调试

发布于 2024-10-16 18:34:01 字数 202 浏览 1 评论 0原文

我正在尝试对 Nexus One 进行内核调试,并且一直遵循 http://bootloader 中的说明。 wikidot.com/android:kgdb。我想知道是否有人真正做到了这一点?有没有人做过使用 KGDB 调试内核的更新解决方案?

I'm trying to do kernel debugging for my Nexus One, and have been following instructions from http://bootloader.wikidot.com/android:kgdb. I was wondering if someone has actually got this to work? And has anyone done a more up to date solution for using KGDB to debug the kernel?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

度的依靠╰つ 2024-10-23 18:34:01

当我在 Android 上查找 KGDB 的信息时,我发现了这篇文章,因此,尽管它已有几年历史,但我认为值得发布一个指向我为在 Nexus 6 上启动并运行它所做的一些工作的链接。

http://www.contextis.com/resources/blog/kgdb-android -debugging-kernel-boss/

我希望这可以帮助任何其他寻找类似答案的人。

编辑了以下反馈(谢谢大家):

为了让这个工作正常工作,我必须制作一个基于 此 Accuvant 博客。这是一个相当简单的电路,由一个 FTDI 3.3v 基本分线器(在撰写本文时可从 SparkFun 获得)、4 个电阻器(2 x 1K Ohm、1 x 1.2K Ohm 和 1 x 100Ohm)以及一个4 元件头-环-环-套 (TRRS) 耳机插孔。这些电阻本质上是提供一个分压器,将 3.3V 电压降低到对您的手机来说更安全的电压。通过插入音频插孔并将另一端连接到电路板,音频子系统会识别其中一个引脚上的电压 (~2.8V),并知道通过该电缆提供 UART 接口。 FTDI 分线器通过 USB 插入您的 PC,从这里您可以通过 minicom 等终端仿真器访问控制台消息。但是,您现在通过相同的机制拥有一个串行接口,这就是我们可以用于 KGDB 连接的接口。

因此,此时需要对 Nexus 6 的串行驱动程序 (msm_serial_hs_lite.c) 进行一些相对较小的更改,以支持 KGDB(具体来说,执行原子字符 I/O 操作的能力)。我刚刚作为一个名叫 Stephen Boyd 的小伙子从 Linux 内核主线代码中移植了这些更改已经完成了完整的 MSM(高通)串行驱动程序 msm_serial.c 的艰苦工作。他的更改可以在这里找到,或者只需在 Google 上搜索“msm_serial:添加对 poll_ 的支持”即可。移植并不困难,我的代码可以在 github 上找到

除此之外,您需要能够为您的 N6 构建自定义内核,谷歌提供了大量信息。然后,您需要创建一个启动映像,其中包含 github 存储库中的 KGDB 修改。我从 https://developers.google.com/android/nexus/images,提取它(使用 abootimg -x),然后使用以下命令使用我的自定义内核(zImage-dtb)和其他命令行参数重新打包它,以确保加载 KGDB 并指向我的串行端口,如下所示

abootimg -u boot.img -k zImage-dtb -c 'cmdline=console=ttyHSL0,115200,n8 kgdboc=ttyHSL0,115200 kgdbretry=4'

:我创建了 boot.img 我可以使用命令 fastboot boot boot.img 启动它,打开 adb shell,然后使用以下命令在 Android 内核中触发断点:

echo -n g > /proc/sysrq-trigger

值得一提的是,为了完整性,您需要超级用户权限才能访问 / proc/sysrq-trigger 所以你需要有root权限。

电话停止并连接调试电缆后,在主机 PC 上启动用于 ARM 的 GDB 版本,并将未压缩的内核作为参数(例如,arm-eabi-gdb ./vmlinux)。注意:我正在运行 Ubuntu 14.04 并使用 AOSP 源存储库中“prebuilts”目录中的 arm-eabi-gdb。最后,输入以下命令:

set remoteflow off
set remotebaud 115200
target remote /dev/ttyUSB0

一切顺利的话,这应该会立即中断到 kgdb 断点(即您对 /proc/sysrq-trigger 的写入所产生的断点),并且您可以开始调试。

I found this post when I was looking for information of KGDB on Android so, despite it being a few years old, I thought it worth posting a link to some work I did to get this up and running on the Nexus 6.

http://www.contextis.com/resources/blog/kgdb-android-debugging-kernel-boss/

I hope this helps anyone else looking for similar answers.

Edited following feedback (thanks all):

To get this working I had to make a UART debug cable based on this Accuvant blog. This is quite a simple circuit which consists of a FTDI 3.3v basic breakout (available from SparkFun at the time of writing), as well as 4 resistors (2 x 1K Ohm, 1 x 1.2K Ohm and 1 x 100Ohm), and a 4-element Tip-Ring-Ring-Sleeve (TRRS) headphone jack. The resistors are essentially providing a voltage divider to reduce the 3.3v down to something a little safer for your phone. By inserting the audio jack with the other end connected to your circuit board, the audio subsystem recognises that a voltage (~2.8V) on the one of the pins and it knows to provide a UART interface via that cable. The FTDI breakout plugs into your PC via USB and from here you can access console messages via a terminal emulator like minicom. However, you now have a serial interface through the same mechanism and that's what we can use for a KGDB connection.

So at this point some relatively minor changes are required to the Nexus 6's serial driver (msm_serial_hs_lite.c) to support KGDB (specifically, the ability to perform atomic character I/O operations). I just ported these changes from the Linux Kernel mainline code as a chap called Stephen Boyd had done the hard work to the full MSM (Qualcomm) serial driver msm_serial.c. His changes can be found here or just search for "msm_serial: add support for poll_" on Google. The port wasn't difficult and my code can be found on github.

Aside from that you need to be able to build a custom kernel for your N6 which google provides lots of information on. You then need to create a boot image which contains the KGDB modifications in the github repo. I took the stock kernel from https://developers.google.com/android/nexus/images, extracted it (using abootimg -x) and then used the following command to repack it with my custom kernel (zImage-dtb) and additional command line params to ensure KGDB would be loaded and point to my serial port like so:

abootimg -u boot.img -k zImage-dtb -c 'cmdline=console=ttyHSL0,115200,n8 kgdboc=ttyHSL0,115200 kgdbretry=4'

With my boot.img created I could boot into it using the command fastboot boot boot.img, open an adb shell and then trigger a breakpoint in the Android kernel using the command:

echo -n g > /proc/sysrq-trigger

It is worth mentioning for completeness that you need superuser privileges to access /proc/sysrq-trigger so you need to have root.

With the phone halted, and your debug cable connected, launch a version of GDB for ARM on your host PC with your uncompressed kernel as an argument (e.g. arm-eabi-gdb ./vmlinux). Note: I'm running Ubuntu 14.04 and using arm-eabi-gdb from the 'prebuilts' directory in my AOSP source repository. Finally, enter the following commands:

set remoteflow off
set remotebaud 115200
target remote /dev/ttyUSB0

All being well this should immediately break into the kgdb breakpoint (that your write to /proc/sysrq-trigger produced) and you can start debugging.

随波逐流 2024-10-23 18:34:01

我知道您已经在 Android 内核开发列表中提出了一个问题,但没有得到答案,但是您是否在档案中搜索过有关 kgdb 和调试的帖子?: http://groups.google.com/group/android-kernel/search ?group=android-kernel&q=kgdb&qt_g=Search+this+group

特别是,您可能需要查看这篇文章:http://groups.google.com/group/android-kernel/browse_thread/thread/5233e03391867c98/320beef11e737a62

这是其他一些可能有用的随机链接:

无论如何,这个这是一个有趣的问题,我真的很难找到任何相关内容。您可能想尝试在某个时候跳上 IRC(#android-dev 或 #android-root on freenode)并向那里的一些人寻求指导(请张贴您在这里找到的内容),或者也许在 xda-developers Android 论坛

I know that you've already asked a question at the Android Kernel Dev list and got no answers, but did you search through the archives for posts about kgdb and debugging?: http://groups.google.com/group/android-kernel/search?group=android-kernel&q=kgdb&qt_g=Search+this+group

In particular, you might want to look at this post: http://groups.google.com/group/android-kernel/browse_thread/thread/5233e03391867c98/320beef11e737a62

Here's a few other random links that might be helpful:

Anyhow, this is an interesting question, and I'm really having a hard time finding anything on it. You might want want to try hopping on IRC sometime (#android-dev or #android-root on freenode) and asking some people there for pointers (please post up what you find here), or maybe asking on the xda-developers Android forums.

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