Console_loglevel ERROR link in kernel module

I have a Linux module that has a debug function, and I just want to call this function in debug mode. Now I have code like this:

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

But when you create this code in linux-next, it will throw below errors:

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

Can you help figure out how to do this? thank!!!

+4
source share
1 answer

A compilation error is caused by the fact that the symbol is console_printknot exported, so it cannot be used by modules.

However, you must use the dynamic debugging function and its pr_debug()/ function dev_dbg().

, CONFIG_DYNAMIC_DEBUG, dev_dbg() , , , :

  • , dyndbg=+p insmod/modprobe.

  • , , . , foo() bar() , :

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

All Articles