Strainu onLine
Blogul unui automatist
17th
MAY
Simple debugging in kernel programming
Posted by Strainu | Filed under C
When programming Linux kernel modules, you have limited debugging options. The main way is to use the printk function (the kernel equivalent of printf). If you want to give as much information as possible, you could use some of the macros that the language offers you, such as __FILE__ or __line__. Here is a small snippet you could use in your modules:
#define DEBUG 1
#if DEBUG
#define Dprintk(format, ...) \
printk (KERN_ALERT "[%s]:FUNC:%s:line:%d: " format, __FILE__, \
__func__, __LINE__, __VA_ARGS__)
#else
#define Dprintk(format, ...) do {}while(0)
#endif
#if DEBUG
#define Dprintk(format, ...) \
printk (KERN_ALERT "[%s]:FUNC:%s:line:%d: " format, __FILE__, \
__func__, __LINE__, __VA_ARGS__)
#else
#define Dprintk(format, ...) do {}while(0)
#endif
You can use the same code in userspace programs by replacing printk with printf. And just in case you’re wondering what’s with the empty do-while, you might want to take a look at this older article.
Recent Posts:
- 28 Oct Some people just won̵...
- 18 Aug Wiki Loves Monuments RomÃ...
- 15 May Want to work on Pidgin or...
- 14 Apr Free WiFi in the metro!
- 04 Apr Libertatea dincolo de sof...
- 11 Feb Electrocasnice online: Do...
- 15 Oct Wikipedia română –...
- 14 Oct Veliko Tarnovo Sound ...
- 11 Oct Romanian Postal Codes in ...
- 11 Jul Wikimania 2010 – zi...






