关闭

Debugging the linux kernel using kgdb and VirtualBox

349人阅读 评论(0) 收藏 举报
分类:


https://fotisl.com/blog/2009/09/debugging-the-linux-kernel-using-kgdb-and-virtualbox/


September 6th, 2009


Kgdb is a source level debugger for the linux kernel. It requires two machines, one running a kernel compiled with kgdb enabled and the second one running gdb. It can be found at sourceforge and a light version has been merged into the 2.6.26 kernel. There is an article at kerneltrap which contains all the appropriate information about this light version and it’s differences from the full one. I am going to describe how you can debug a linux kernel running under VirtualBox using the kgdb-light debugger.

First of all you must define a serial port. Go to the settings of your virtual machine, then at the “Serial Ports” and enable “Port 1”. Use port number COM1, port mode ‘Host Pipe’, check ‘Create Pipe’ and enter a path, e.g. /home/fotisl/virtualbox/myvm/serial1. You can use another port number, e.g. COM2, but then you’ll have to change the device below to ttyS1, ttyS2 for COM3 etc. Furthermore, you can create the pipe yourself and not automatically using:

At your virtual machine you must have a kernel compiled with the option CONFIG_KGDB. You can find this under the “Kernel debugging” menu. I also advise you to enable the CONFIG_DEBUG_INFO to insert debug symbols.

At the host machine you only need to install socat and of course gdb. Socat is a multipurpose relay which can be found here. You should also transfer the uncompressed image of the kernel running at the vm. It can be found at the directory where you compiled the kernel and it’s name will be vmlinux.

You are now ready to start. At the host machine run:

You must note the PTY, in this case /dev/pts/4. Now fire gdb and load vmlinux. Then set the remote baud to 115200 and attach to the serial port.

Now switch to the virtual machine. You must first set the serial port that kgdb will use.

You’re ready to start debugging! When you want to break use the Alt-SysRq-G key combination or use

If you want to start the debugging when the kernel starts loading, append

to the command line parameters of the kernel. You must use this order! First you must register the I/O driver and then kgdb will be able to wait.

You can now explore the linux kernel! Warning, messing with various structures and executing code that you shouldn’t can cause kernel panics and mess up your virtual machine! But you already know that, that’s why you use virtualbox!


0
0
查看评论

imx6 KGDB调试方法总结(光谷王凯的博客)

1,平台环境 PC:ubuntu12.04 单板:imx6(android4.4.2) 2,imx6的kernel编译加gdb调试 make menuconfig,然后按照Kernelhacking-->KGDB: kernel debugger-->KGDB: use kg...
  • kao2406
  • kao2406
  • 2016-04-07 11:50
  • 1255

通过KGDB进行双机内核调试

原理原理结构图原理过程Kgdb是双机在线调试,一端是Host端(linux),运行GDB,另一端是Target端,运行带Kgdb的linux内核。 两边通过串口(KGDBoc)或网络口(KGDBoE)相连接,kgdb实现了远程调试的功能,主要部件有:stubstub可卸任是一个运行在target端...
  • java211
  • java211
  • 2016-09-05 20:24
  • 875

ubuntu kgdb kernel 调试环境搭建

<!-- @page {margin:2cm} p {margin-bottom:0.21cm} a:link {color:#0000ff} --> 调试环境(末尾还有ubuntu下vmware的环境搭建方法): 主机:WindowsXP Profe...
  • dndxhej
  • dndxhej
  • 2012-01-02 19:38
  • 5943

使用virtualbox + kgdb调试kernel

主机环境: T400/Ubuntu9.10(2.6.31-21) 1、安装VirtualBox,        System->Administation->Synaptic Package Manager  ...
  • nancygreen
  • nancygreen
  • 2013-10-04 21:15
  • 2038

Debug of the kernel with VMWare and kgdb

转自(部分修改):http://blog.csdn.net/jie12310/archive/2009/09/18/4564853.aspx           1.前言 最近几天学习Linux-...
  • u011839461
  • u011839461
  • 2013-09-25 10:00
  • 1990

kernel debug

 调试是软件开发过程中一个必不可少的环节,在 Linux 内核开发的过程中也不可避免地会面对如何调试内核的问题。但是,Linux 系统的开发者出于保证内核代码正确性的考虑,不愿意在 Linux 内核源代码树中加入一个调试器。他们认为内核中的调试器会误导开发者,从而引入不良的修正[1].所以对 ...
  • prike
  • prike
  • 2016-07-30 17:32
  • 794

VirtualBox中的虚拟机在Ubuntu 13.10下无法启动之问题解决

解决在Ubuntu/Linux下无法启动VirtualBox中的虚拟机的错误。
  • blueheart20
  • blueheart20
  • 2014-03-04 08:26
  • 7598

The Kernel Newbie Corner: Kernel Debugging with proc "Sequence" Files--Part 3

Finally, after two installments of the basics of debugging with sequence files, we're going to finish off by demonstrating the power of sequen...
  • CaspianSea
  • CaspianSea
  • 2014-06-30 03:41
  • 670

Debugging the kernel using Ftrace - part 2

 Debugging the kernel using Ftrace - part 2 使用ftrace调试kernel-第二部分 The Ftrace tracing utility has many different features that will assist in trac...
  • mounter625
  • mounter625
  • 2014-05-20 21:28
  • 523

使用VirtualBox和KGDB调试内核

使用VirtualBox和KGDB调试内核
  • ztguang
  • ztguang
  • 2016-08-29 11:27
  • 390
    个人资料
    • 访问:1706982次
    • 积分:23111
    • 等级:
    • 排名:第362名
    • 原创:1829篇
    • 转载:1045篇
    • 译文:0篇
    • 评论:70条
    相册/老博客
    最新评论