Skip to content

Enabling Printk’s in Paging

March 3, 2011

OMG!!! Debugging kernel code is really difficult but debugging paging in kernel code is more difficult. Try this,before pagetables are setup put printk in buddy allocator code and check what will happen. Don’t waste time in exploring this, kernel will get crash as pagetables are not setup and libraries are not initialized. But still you want to debug the code after page tables are setup. Follow the steps given below :

1. Add below declaration in any of the file (say mm.h)
int post_printk=0;
EXPORT_SYMBOL(post_printk);

2. Define following macro in your code

#define MY_PRINTK(print_this)  if(post_printk) printk(“\n%s\n”print_this)

In kernel programming always put “\n” at the end of printks which ensure that printk’s will be printed even though kernel is crashed.

3. Now set post_printk=1 when you want to enable printks.

4. So rather than putting printks use the macro definition defined above.

MY_PRINTK(“This is my message in printk”);

Advertisements

From → Kernel

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: