Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 内核模块中的引用控制台\u日志级别错误_Linux_Linux Kernel_Linux Device Driver - Fatal编程技术网

Linux 内核模块中的引用控制台\u日志级别错误

Linux 内核模块中的引用控制台\u日志级别错误,linux,linux-kernel,linux-device-driver,Linux,Linux Kernel,Linux Device Driver,我有一个Linux模块,它有一个调试函数,我只想在调试模式下调用该函数。 现在我有这样的代码: if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG) dump_my_message(dev, my_msg); 但下一步在linux中构建此代码时,将抛出以下错误: CHK include/generated/uapi/linux/version.h Kernel: arch/x86/boot/bzImage is ready (#

我有一个Linux模块,它有一个调试函数,我只想在调试模式下调用该函数。 现在我有这样的代码:

if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
    dump_my_message(dev, my_msg);
但下一步在linux中构建此代码时,将抛出以下错误:

CHK     include/generated/uapi/linux/version.h
Kernel: arch/x86/boot/bzImage is ready  (#2)
  Building modules, stage 2.
  MODPOST 2738 modules
ERROR: "console_printk" [drivers/mymodule.ko] undefined!
scripts/Makefile.modpost:91: recipe for target '__modpost' failed
make[1]: *** [__modpost] Error 1
Makefile:1117: recipe for target 'modules' failed
make: *** [modules] Error 2

你能帮我弄清楚怎么做吗?谢谢

编译错误是由于未导出
console\u printk
符号,因此模块无法使用它

然而,您真正应该使用的是功能及其
pr\u debug()
/
dev\u dbg()
函数

基本上,您需要的是确保在内核中启用了
CONFIG\u DYNAMIC\u DEBUG
,在需要编写调试代码的所有地方使用
dev\u dbg()
,然后动态启用调试消息,例如:

  • 要启用模块中的所有消息,请在
    insmod
    /
    modprobe
    调用末尾添加
    dyndbg=+p

  • 要有选择地仅启用部分消息,请使用文档中描述的查询语言。例如,要仅启用模块中函数
    foo()
    bar()
    中的消息,请使用:

    insmod mymodule.ko dyndbg="func foo +p; func bar +p"
    

  • 谢谢我看到控制台日志级别也被driver/nubus/nubus.c使用。如果未导出,此模块如何使用console_loglevel/console_printk?如何从printk导出console_printk的模块?谢谢nubus不是内核模块,它被编译到主内核映像中。这就是为什么它访问这些符号没有问题——这个限制只涉及作为内核模块编写的代码。您可以修改内核并导出任何符号,只需查找export_symbol()宏。但是,请记住,如果您在内核中使用您自己导出的任何符号,此模块将只能与您的内核一起工作。非常感谢您的帮助!