加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 引用内核模块中的console_loglevel错误

发布时间:2020-12-13 23:26:42 所属栏目:Linux 来源:网络整理
导读:我有一个 Linux模块,它有一个调试功能,我只想在调试模式下调用该函数. 现在我有这样的代码: if (console_loglevel = CONSOLE_LOGLEVEL_DEBUG) dump_my_message(dev,my_msg); 但是当在linux-next中构建这个代码时,它将抛出以下错误: CHK include/generated/
我有一个 Linux模块,它有一个调试功能,我只想在调试模式下调用该函数.
现在我有这样的代码:

if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
    dump_my_message(dev,my_msg);

但是当在linux-next中构建这个代码时,它将抛出以下错误:

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_printk符号,因此模块无法使用它.

但是,您真正应该使用的是Dynamic debug功能及其pr_debug()/ dev_dbg()函数.

基本上你需要的是确保你的内核中启用了CONFIG_DYNAMIC_DEBUG,在你想要编写一些调试代码的所有地方使用dev_dbg(),然后动态启用你的调试消息,例如:

>要启用模块中的所有消息,请在insmod / modprobe调用结束时添加dyndbg = p.
>要有选择地仅启用某些消息,请使用文档中描述的查询语言.例如,要仅启用模块中函数foo()和bar()的消息,请使用:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读