使用Windows主机在VMWare中调试Linux内核 [英] Debugging Linux Kernel in VMWare with Windows host

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

问题描述

我正在开发我的第一个内核模块,所以在这个方面我有点新...

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

我的模块偶尔会产生紧急情况,而我无法使用printk深入了解它.据我所知,我的调试选项是:

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.)找到生成的OOPS消息并使用ksymoops

1.) Find the generated OOPS message and use ksymoops

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

2.) Try at remote debug using kgdb

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

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?

就像我说的那样,我对此有点陌生(和Linux一样),所以我真的可以使用一些指导.谢谢!

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

推荐答案

前一段时间,我成功使用了"alinrus"所指的技术.他提到的部分将在以下位置进行详细说明: http://stackframe.blogspot.com/2007/04/debugging-linux-kernels-with.html

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

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

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. 在Windows机器上安装最新的gdb(我在Cygwin中使用了该gdb).
  2. 从vmlinux文件启动gdb,然后执行"target remote localhost:8832"以连接VM(运行时).

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

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.在加载模块之后(并在将其崩溃之前:)在.ko文件上运行以下脚本.

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

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

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.

脚本来自 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可以找到它.到此为止,您可以使用一些技巧来编译模块而无需优化.

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.

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

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

这篇关于使用Windows主机在VMWare中调试Linux内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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