如何包括一个内核模块code C回溯? [英] How to include C backtrace in a kernel module code?

查看:96
本文介绍了如何包括一个内核模块code C回溯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图找出内核进程在块驱动程序调用一些功能。我想包括回溯()在C库将使它容易。但我无法加载回溯。

So I am trying to find out what kernel processes are calling some functions in a block driver. I thought including backtrace() in the C library would make it easy. But I am having trouble to load the backtrace.

我复制这个例子功能显示回溯:

I copied this example function to show the backtrace:

<一个href=\"http://www.linuxjournal.com/files/linuxjournal.com/linuxjournal/articles/063/6391/6391l1.html\">http://www.linuxjournal.com/files/linuxjournal.com/linuxjournal/articles/063/6391/6391l1.html

所有尝试编译有错误在一个地方,或其他的文件不能被发现,或功能没有限定。

All attempts to compile have error in one place or another that a file cannot be found or that the functions are not defined.

下面是最接近什么来。

Here is what comes closest.

在Makefile中,我把编译器指令:

In the Makefile I put the compiler directives:

 -rdynamic -I/usr/include 

如果我离开了第二个,-I / usr / include目录,那么编译器报告它无法找到所需的头execinfo.h。

If I leave out the second one, -I/usr/include, then the compiler reports it cannot find the required header execinfo.h.

接下来,在code,我想要做的回溯我抄例子中的功能:

Next, in the code where I want to do the backtrace I have copied the function from the example:

//trying to include the c backtrace capability
#include <execinfo.h>

void show_stackframe() {
void *trace[16];
char **messages = (char **)NULL;
int i, trace_size = 0;

trace_size = backtrace(trace, 16);
messages = backtrace_symbols(trace, trace_size);
printk(KERN_ERR "[bt] Execution path:\n");
for (i=0; i<trace_size; ++i)
    printk(KERN_ERR "[bt] %s\n", messages[i]);
}
//backtrace function

我已经把调用这个函数以后,在错误的第一个迹象发生块驱动程序的功能。简单地说:

I have put the call to this function later on, in a block driver function where the first sign of the error happens. Simply:

show_stackframe();

所以,当我编译它,以下错误:

So when I compile it, the following errors:

user@slinux:~/2.6-32$ make -s
Invoking make againt the kernel at /lib/modules/2.6.32-5-686/build
In file included from /usr/include/features.h:346,
        from /usr/include/execinfo.h:22,
        from /home/linux/2.6-32/block/block26.c:49:
/usr/include/sys/cdefs.h:287:1: warning: "__always_inline" redefined
In file included from /usr/src/linux-headers-2.6.32-5-common/include/linux/compiler-gcc.h:86,
        from /usr/src/linux-headers-2.6.32-5-common/include/linux/compiler.h:40,
        from /usr/src/linux-headers-2.6.32-5-common/include/linux/stddef.h:4,
        from /usr/src/linux-headers-2.6.32-5-common/include/linux/list.h:4,
        from /usr/src/linux-headers-2.6.32-5-common/include/linux/module.h:9,
        from /home/linux/2.6-32/inc/linux_ver.h:40,
        from /home/linux/2.6-32/block/block26.c:32:
/usr/src/linux-headers-2.6.32-5-common/include/linux/compiler-gcc4.h:15:1: warning: this is the location of the previous definition
    /home/linux/2.6-32/block/block26.c:50: warning: function declaration isn’t a prototype
WARNING: "backtrace" [/home/linux/2.6-32/ndas_block.ko] undefined!
WARNING: "backtrace_symbols" [/home/linux/2.6-32/ndas_block.ko] undefined!

请注意:block26.c是我希望能得到回溯文件

Note: block26.c is the file I am hoping to get the backtrace from.

有一个明显的原因,当它被编译成模块.ko回溯和backtrace_symbols保持未定义?

Is there an obvious reason why the backtrace and backtrace_symbols remain undefined when it is compiled into the .ko modules?

我猜是因为我使用的编译器包括execinfo.h这是驻留在计算机上,并没有被加载到模块。

I am guessing it because I use the compiler include execinfo.h which is residing on the computer and not being loaded to the module.

这是我的猜测没有受过教育的,至少可以说。

It is my uneducated guess to say the least.

任何人都可以提供帮助,以获得回溯功能模块中加载了?

Can anyone offer a help to get the backtrace functions loading up in the module?

感谢您看这个查询。

我的工作的debian。当我拿出功能,例如,模块编译罚款和几乎完美的作品。

I am working on debian. When I take out the function and such, the module compiles fine and almost works perfectly.

从ndasusers

From ndasusers

推荐答案

要打印堆栈内容,并回溯到内核日志,使用 dump_stack()功能你的内核模块。它宣布的Linux / kernel.h 在内核源​​目录中包含文件夹。

To print the stack contents and a backtrace to the kernel log, use the dump_stack() function in your kernel module. It's declared in linux/kernel.h in the include folder in the kernel source directory.

这篇关于如何包括一个内核模块code C回溯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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