Android:使用KGDB进行内核调试 [英] Android: Kernel Debugging with KGDB

查看:973
本文介绍了Android:使用KGDB进行内核调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Nexus One进行内核调试,并遵循 http:/ /bootloader.wikidot.com/android:kgdb 。我想知道有没有人有这个工作吗?有没有人使用KGDB来调试内核的更新的解决方案?

解决方案

当我发现这篇文章在Android上查找KGDB的信息,尽管已经是几岁,但我觉得值得发布一些链接,以便我在Nexus 6上进行一些工作。



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



我希望这有助于其他人寻找类似的答案。 b
$ b

编辑以下反馈(感谢所有):



为了得到这个工作,我必须根据此Accuvant博客。这是一个非常简单的电路,它包括一个FTDI 3.3v基本突破(在写入时可从SparkFun获得),以及4个电阻(2 x 1K欧姆,1 x 1.2K欧姆和1×100Ohm),以及4芯尖端环形环(TRRS)耳机插孔。电阻器本质上是提供一个分压器,以将3.3v降低到一些更安全的手机。通过插入另一端连接到电路板的音频插孔,音频子系统可识别其中一个引脚上的电压(〜2.8V),并且它知道通过该电缆提供UART接口。 FTDI突破通过USB插入您的PC,从这里您可以通过终端仿真器(如minicom)访问控制台消息。但是,您现在可以通过相同的机制使用串行接口,这就是我们可以用于KGDB连接的一个串行接口。



所以在这一点上,需要一些相对较小的更改Nexus 6的串行驱动程序(msm_serial_hs_lite.c)来支持KGDB(具体来说,执行原子字符I / O操作的能力)。我刚从Linux内核主线代码移植了这些更改,作为一个叫Stephen Boyd的章节已经为完整的MSM(Qualcomm)串行驱动程序msm_serial.c做了艰苦的工作。他的更改可以在这里找到,或者只是在Google上搜索msm_serial:添加对poll_的支持。端口不难,我的代码可以在github上找到



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

  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 -ng> / proc / sysrq-trigger 

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



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

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

所有这一切都应该立即进入kgdb断点(你写到/ proc / sysrq -trigger生成),您可以开始调试。


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?

解决方案

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.

这篇关于Android:使用KGDB进行内核调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆