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

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

问题描述

我是内核开发的新手,我想知道如何使用 QEMU 和 gdb 运行/调试 linux 内核.我实际上正在阅读 Robert Love 的书,但不幸的是它并没有帮助读者了解如何安装适当的工具来运行或调试内核......所以我所做的是遵循本教程 http://opensourceforu.efytimes.com/2011/02/kernel-development-debugging-using-eclipse/.我使用 Eclipse 作为 IDE 在内核上进行开发,但我想首先让它在 QEMU/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) 编译内核:

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

2) 编译结束后,我使用以下命令运行 Qemu:

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

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

以停止"状态启动内核

3) 因此我必须使用 gdb,我尝试以下命令:

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

gdb ./vmlinux

哪个运行正确但是...现在我不知道该怎么做...我知道我必须在端口 1234(Qemu 使用的默认端口)上使用远程调试,使用 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.

所以我的问题是:我应该怎么做才能在 Qemu 上运行内核,将我的调试器连接到它,从而让它们协同工作,让我的内核开发工作更轻松.

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.

推荐答案

我会尝试:

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

使用 '-s' 选项使 qemu 监听端口 tcp::1234,如果您在同一台机器上,您可以作为 localhost:1234 连接到该端口.Qemu 的-S"选项使 Qemu 停止执行,直到您发出 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.

最好的办法可能是看看一个像样的 GDB 教程来了解你正在做的事情.这个看起来很不错.

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天全站免登陆