如何用GDB和QEMU调试Linux内核? [英] How to debug the Linux kernel with GDB and QEMU?

查看:182
本文介绍了如何用GDB和QEMU调试Linux内核?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是内核开发新手,我想知道如何使用QEMU和gdb运行/调试Linux内核。我实际上阅读了罗伯特·洛夫的书,但不幸的是,它并没有帮助读者如何安装合适的工具来运行或调试内核......所以我所做的就是遵循本教程 http://opensourceforu.efytimes.com/2011/02/kernel-development-debugging-using-eclipse / 。我使用eclipse作为IDE在内核上开发,但我首先想让它在QEMU / gdb下运行。所以我到目前为止做的是:
$ b $ 1)用以下内容编译内核:
$ b $

  make defconfig(然后在.config中设置CONFIG_DEBUG_INFO = y)
make -j4

2)编译完成后,我运行Qemu:

pre $ q $ qemu-system-x86_64 -s -S / dev / zero -kernel / arch / x86 / boot / bzImage

state



3)因此我必须使用gdb,我尝试下面的命令:
$ b $

  gdb ./vmlinux 

正确运行它,但是...现在我不用不知道该怎么做......我知道我必须在端口1234(Qemu使用的默认端口)上使用远程调试,使用vmlinux作为符号表文件进行调试。



所以我的问题是:我应该怎么做才能在Qemu上运行内核,将我的调试器附加到它上面,从而让它们一起工作,使内核开发更轻松。



 (gdb)目标远程本地主机:1234 
(gdb)continue

使用'-s'选项可以让qemu监听端口tcp :: 1234,如果你在同一台机器上,你可以连接到localhost:1234。 Qemu的'-S'选项让Qemu停止执行,直到你给出continue命令为止。



最好的事情可能是看看体面的GDB教程以相处你在做什么。 这一张看起来相当不错。


I'm new to kernel development and I would like to know how to run/debug the linux kernel using QEMU and gdb. I'm actually reading Robert Love's book but unfortunately it doesn't help the reader on how to install proper tools to run or debug the kernel... So what I did was to follow this tutorial http://opensourceforu.efytimes.com/2011/02/kernel-development-debugging-using-eclipse/. I'm using eclipse as an IDE to develop on the kernel but I wanted first to get it work under QEMU/gdb. So what I did so far was:

1) To compile the kernel with:

make defconfig (then setting the CONFIG_DEBUG_INFO=y in the .config)
make -j4

2) Once the compilation is over I run Qemu using:

qemu-system-x86_64 -s -S /dev/zero -kernel /arch/x86/boot/bzImage

which launch the kernel in "stopped" state

3) Thus I have to use gdb, I try the following command:

gdb ./vmlinux

which run it correctly but... Now I don't know what to do... I know that I have to use remote debugging on the port 1234 (default port used by Qemu), using the vmlinux as the symbol table file for debugging.

So my question is: What should I do to run the kernel on Qemu, attach my debugger to it and thus, get them work together to make my life easier with kernel development.

解决方案

I'd try:

(gdb) target remote localhost:1234
(gdb) continue

Using the '-s' option makes qemu listen on port tcp::1234, which you can connect to as localhost:1234 if you are on the same machine. Qemu's '-S' option makes Qemu stop execution until you give the continue command.

Best thing would probably be to have a look at a decent GDB tutorial to get along with what you are doing. This one looks quite nice.

这篇关于如何用GDB和QEMU调试Linux内核?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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