在 Windows 主机上调试 VMWare 中的 Linux 内核

发布于 2024-08-18 15:10:45 字数 363 浏览 8 评论 0原文

我正在开发我的第一个内核模块,所以我对此有点陌生......

我的模块偶尔会产生恐慌,我无法使用 printk 深入了解它。据我所知,我的调试选项是:

1.) 查找生成的 OOPS 消息并使用 ksymoops

2.) 尝试使用 kgdb 进行远程调试

我正在 Windows 主机上工作并在 VMWare 中运行 Ubuntu,因此事情变得复杂一点。我想先尝试 OOPS 消息,但我不知道如何捕获它。发生这种情况时我是否需要运行串行控制台?如果是这样,我该如何在 Windows 主机上做到这一点?我需要两个虚拟机吗?

就像我说的,我对此(以及一般的 Linux)有点陌生,所以我真的可以使用一些指导。谢谢!

I'm working on my first ever kernel module so I'm a bit new at this...

My module is occasionally producing a panic and I cannot get to the bottom of it using printk. As far as I can tell my options for debugging are:

1.) Find the generated OOPS message and use ksymoops

or

2.) Try at remote debug using kgdb

I'm working on a windows host and running Ubuntu in VMWare so that complicates things a bit. I'd like to try the OOPS message first but I don't know how to capture it. Do I need to be running a serial console when it happens? If so, how can I do that with Windows host? Do I need two VM's?

Like I said, I'm a bit new to this (and Linux in general) so I could really use some guidance. Thanks!

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

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

发布评论

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

评论(3

憧憬巴黎街头的黎明 2024-08-25 15:10:46

我不确定这是否对您在 Winblowz 上有帮助,但如果您可以将虚拟机移动到 Linux 机器上:

使用 Workstation 6.0 调试 Linux 内核

我们只是悄悄添加了一个令人兴奋的
工作站 6.0 的功能。我相信
它将使 WS6 成为一个出色的工具
Linux内核开发。你现在可以
在你的主机上使用 gdb 来调试
Linux 内核在虚拟机内运行。不
kdb,无需重新编译,无需
第二台机器。您所需要的只是一个
VM配置中的单行
文件。

我认为这可能也适用于其他最新的 VMware 产品。

由于它也适用于 Mac OSX,我怀疑它也适用于 Winblowz:

调试 linux 内核(在 vmware 内)来自 Mac OSX

正如此线程所建议的,您还可以从同一计算机上运行的第二个 Linux VM 远程调试一个 Linux VM。

I'm not sure if this will help you on Winblowz, but if you can move your VM to a linux box:

Debugging Linux kernels with Workstation 6.0

We just quietly added an exciting
feature to Workstation 6.0. I believe
it will make WS6 a great tool for
Linux kernel development. You can now
use gdb on your host to debug the
Linux kernel running inside the VM. No
kdb, no recompiling and no need for
second machine. All you need is a
single line in VM's configuration
file.

I think this probably works on other recent VMware products as well.

Since it works on Mac OSX as well I suspect it would work on Winblowz also:

Debugging linux kernel (inside vmware) from Mac OSX

As this thread suggests, you might also remotely debug one linux VM from a second linux VM running on the same machine.

一梦浮鱼 2024-08-25 15:10:45

不久前我成功地使用了“alinrus”所指的技术。他提到的部分详细解释在:
http://stackframe.blogspot.com/2007/04/ debug-linux-kernels-with.html

我实际上直接从 Windows 主机使用它。因此,在设置虚拟机之后(主要是启用远程调试和下载内核(vmlinux 文件,不是 gdb 无法解释的 vmlinuz 文件)),您需要执行以下操作

  1. : Windows 机器上最新的 gdb(我在 Cygwin 中使用过)。
  2. 使用 vmlinux 文件启动 gdb,然后执行“target remote localhost:8832”来连接虚拟机(当虚拟机运行时)。

这就是调试静态链接到内核的代码所需的。您可以尝试静态链接您的模块,上面的内容就足够了。为动态链接模块设置调试需要额外的步骤来通知 gdb 使用模块文件,以及如何解释文件的部分。

3a.加载模块后(在导致模块崩溃之前:)),在 .ko 文件上运行下面的脚本。

3b.将生成的“add-symbol-file mymodule.ko 0xe8884000 ...”行粘贴到 gdb 中。然后,gdb 将加载您的模块,只要它可以在当前目录或您指定的路径中找到它。

脚本来自 http://anomit.com/ 2009/11/04/kernel-module-debugging-a-simple-technique/

#!/bin/sh
#
# gdbline module image
#
# Outputs an add-symbol-file line suitable for pasting into gdb to examine
# a loaded module.
#
cd /sys/module/$1/sections
PROG=${1}.ko
echo -n add-symbol-file ${PROG} `/bin/cat .text`
#echo -n add-symbol-file $2 `/bin/cat .text`  #Take second argument to be gdb name of program/object file

for section in .[a-z]* *; do
    if [ $section != ".text" ]; then
        echo  " \\"
        echo -n "       -s" $section `/bin/cat $section`
    fi
done
echo

您可能还想做更多的事情。要进行实际的源代码级调试,您需要获取所有内核和模块源代码,以便 gdb 可以找到它。一旦你做到了这一点,你可以使用一些技巧来编译你的模块而无需优化。

您可能还想查看 Workstation 7.0 关于重播调试的技术说明,其中包含有关调试内核模块的信息。 VMware 了解他们的东西。
http://www.vmware.com/pdf/ws7_replay_linux_technote.pdf

A while ago I successfully used the technique "alinrus" refers to. The part he mentioned is explained in detail at:
http://stackframe.blogspot.com/2007/04/debugging-linux-kernels-with.html

I actually used it directly from a Windows host. So after setting up the VM (mainly enabling remote debugging and downloading the kernel (the vmlinux file, not the vmlinuz file which cannot be interpreted by gdb)), you would need to do the following:

  1. Install a recent gdb on your Windows machine (I used the one in Cygwin).
  2. Start gdb with the vmlinux file, and then do "target remote localhost:8832" to connect the VM (when it's running).

That is what you need to debug code which is statically linked into the kernel. You could try statically linking your module and the above would be sufficient. Setting up debugging for a dynamically-linked module requires an additional step to inform to gdb to use your module file as well, and how to interpret the file's sections.

3a. Run the script below on your .ko file, after loading the module (and before crashing it :) ).

3b. Paste the resulting "add-symbol-file mymodule.ko 0xe8884000 ..." lines into gdb. gdb will then load your module, as long as it can find it in the current directory or path you specify.

Script is from http://anomit.com/2009/11/04/kernel-module-debugging-a-simple-technique/

#!/bin/sh
#
# gdbline module image
#
# Outputs an add-symbol-file line suitable for pasting into gdb to examine
# a loaded module.
#
cd /sys/module/$1/sections
PROG=${1}.ko
echo -n add-symbol-file ${PROG} `/bin/cat .text`
#echo -n add-symbol-file $2 `/bin/cat .text`  #Take second argument to be gdb name of program/object file

for section in .[a-z]* *; do
    if [ $section != ".text" ]; then
        echo  " \\"
        echo -n "       -s" $section `/bin/cat $section`
    fi
done
echo

There are more things you may want to do. To do actual source-level debugging you'll want to suck down all the kernel and module source code so that gdb can find it. And there are some tricks you can use to compile your module without optimization once you get this far.

You may also want to look at Workstation 7.0's tech note on replay debugging, which contains information on debugging kernel modules. VMware knows their stuff.
http://www.vmware.com/pdf/ws7_replay_linux_technote.pdf

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