My Tech notes: debug macro in kernel - dbg() macro
Subscribe

Unix Documentation

Free Online Unix Training Materials

Lists many links to free Unix training materials.

Pointers and Arrays Materials

Pointers and Arrays materials Explained for C beginners

C FAQ and General Questions C Interview Questions

Powered By

Free XML Skins for Blogger

Powered by Blogger

Thursday, May 1, 2008

debug macro in kernel - dbg() macro

Help ksymoops out


mkdir /var/log/ksymoops

Every time a module is loaded /proc/ksymsand /proc/modules is copied there.

-k /var/log/ksymoops/.ksyms

-l /var/log/ksymoops/.modules




dbg() macro


#if !defined(CONFIG_FOO_MODULE)
#define MY_NAME "foo_driver"
#else
#define MY_NAME THIS_MODULE->name
#endif

#define dbg(fmt, arg...) do {
if (debug)
printk(KERN_DEBUG "%s: "__FUNCTION__": "
fmt "\n" , MY_NAME , ## arg);
} while (0)

static int debug;
MODULE_PARM(debug, "i");


Using dbg()


dbg ("Added slot %d to the list",
slot->physical_number);

shows up as:
hotplug_pci: pci_hp_register: Added slot 2 to the list


dbg ("");

shows up as:
hotplug_pci: pci_hp_register:


Other printk() macros


#define err(fmt, arg...)
printk(KERN_ERR "%s: " fmt "\n" , MY_NAME , ## arg)

#define info(fmt, arg...)
printk(KERN_INFO "%s: " fmt "\n" , MY_NAME , ## arg)

#define warn(fmt, arg...)
printk(KERN_WARNING "%s: " fmt "\n" , MY_NAME , ## arg)

No comments:

Post a Comment