Skip to main content.
Navigation:
DENX
>
Training2
>
LddDebuggingWithPrintk
Translations:
Edit
|
Attach
|
Raw
|
Ref-By
|
Printable
|
More
Training2
Sections of this site:
DENX Home
|
DULG
|
ELDK-5
|
Know
|
Training
|
U-Boot
|
U-Bootdoc
Topics
Training2 Home
Changes
Index
Search
Go
List of pages in Training2
Search
%SECTION0{name=LddDebuggingWithPrintk}% Debugging with printk * simple and effective * works with default kernel * little impact on timing (compared to hardware debuggers) * avoid cluttering syslog: log kernel messages to file during testing * stop klogd: =killall klogd= * and restart with log to file option =klogd -f /tmp/mymessages= * change kernel loglevel (which messages are printed to console) * =/proc/sys/kernel/printk= * off =dmesg -n 1=, full =dmesg -n 8= *simple* <verbatim> #define DEBUG #ifdef DEBUG # define _DBG(fmt, args...) printk(KERN_DEBUG "%s: " fmt "\n", __FUNCTION__, ##args) #else # define _DBG(fmt, args...) do { } while(0); #endif /* example usage */ void read_this(int count) { _DBG("reading count=%d bytes", count); } </verbatim> *Debug levels:* <verbatim> #define DEBUG #define DEBUG_LEVEL_LOW #define DEBUG_LEVEL_MEDIUM #define DEBUG_LEVEL_HIGH static int debug = DEBUG_LEVEL_MEDIUM; /* change with ioctl or proc */ #ifdef DEBUG # define _DBG(x, fmt, args...) do{ if (debug>=x) printk(KERN_CRIT "%s: " fmt "\n", __FUNCTION__, ##args); } while(0); #else # define _DBG(x, fmt, args...) do { } while(0); #endif /* example usage */ void function1() { _DBG(DEBUG_LEVEL_LOW, "addr1=0x%x, addr2=0x%x", addr1, addr2); } void fatal_error() { _DBG(DEBUG_LEVEL_HIGH, "this is the end"); } </verbatim> *Debug selective subsystems:* <verbatim> #define DEBUG #define DEBUG_READ (1<<0) #define DEBUG_WRITE (1<<1) #define DEBUG_LOCKS (1<<2) static unsigned int debug_mask = 0; #ifdef DEBUG # define _DBG(x, fmt, args...) do{ if (debug_mask & x) printk(KERN_DEBUG "%s: " fmt "\n", __FUNCTION__, ##args); } while(0); #else # define _DBG(x, fmt, args...) do { } while(0); #endif /* example usage */ void read() { _DBG(DEBUG_READ, "inside read function"); } void write(int count) { _DBG(DEBUG_WRITE, "writing count=%d bytes", count); } </verbatim>
5.4. Debugging Techniques
1. Denx Training Topics
5.4.2. Debugging Oopses
Prev
Home
Next