<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Strainu onLine &#187; debugging</title>
	<atom:link href="http://www.strainu.ro/tag/debugging/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.strainu.ro</link>
	<description>Blogul unui automatist</description>
	<lastBuildDate>Fri, 28 Oct 2011 15:46:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Simple debugging in kernel programming</title>
		<link>http://www.strainu.ro/programming/c/simple-debugging-in-kernel-programming/</link>
		<comments>http://www.strainu.ro/programming/c/simple-debugging-in-kernel-programming/#comments</comments>
		<pubDate>Thu, 17 May 2007 07:17:07 +0000</pubDate>
		<dc:creator>Strainu</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[kernel]]></category>

		<guid isPermaLink="false">http://blog.strainu.ro/personal/simple-debugging-in-kernel-programming/</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>When programming Linux kernel modules, you have limited debugging options. The main way is to use the <strong>printk</strong> 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 <em>__FILE__</em> or <em>__line__</em>. Here is a small snippet you could use in your modules:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define DEBUG 1</span><br />
<span style="color: #339933;">#if DEBUG</span><br />
<span style="color: #339933;">#define Dprintk(format, ...) \<br />
printk (KERN_ALERT &quot;[%s]:FUNC:%s:line:%d: &quot; format, __FILE__, \<br />
__func__, __LINE__, __VA_ARGS__)</span><br />
<span style="color: #339933;">#else</span><br />
<span style="color: #339933;">#define Dprintk(format, ...) do {}while(0)</span><br />
<span style="color: #339933;">#endif</span></div></div>
<p>You can use the same code in userspace programs by replacing <strong>printk</strong> with <strong>printf</strong>. And just in case you&#8217;re wondering what&#8217;s with the empty <strong>do-while</strong>, you might want to take a look at <a href="http://codertricks.strainu.ro/c/2007/05/04/macros-using-dowhile0/" target="_blank">this older article</a>.</p>
<div class='sociable'><div><span class='sociable-tagline'><strong>Share and Enjoy:</strong></span></div><ul><li><a rel="nofollow" target="_blank"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F&amp;t=Simple%20debugging%20in%20kernel%20programming" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/facebook.png" class="sociable-img sociable-hovers" title="Facebook" alt="Facebook" /></a></li><li><a rel="nofollow" target="_blank"  href="http://twitter.com/home?status=Simple%20debugging%20in%20kernel%20programming%20-%20http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/twitter.png" class="sociable-img sociable-hovers" title="Twitter" alt="Twitter" /></a></li><li><a rel="nofollow" target="_blank"  href="http://identi.ca/notice/new?status_textarea=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/identica.png" class="sociable-img sociable-hovers" title="Identi.ca" alt="Identi.ca" /></a></li><li><a rel="nofollow" target="_blank"  href="mailto:?subject=Simple%20debugging%20in%20kernel%20programming&amp;body=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/email_link.png" class="sociable-img sociable-hovers" title="email" alt="email" /></a></li><li><a rel="nofollow" target="_blank" title="Add to favorites" href="#" onclick="AddToFavorites(); return false;"><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/addtofavorites.png" class="sociable-img sociable-hovers" title="Add to favorites" alt="Add to favorites" /></a></li><li><a rel="nofollow" target="_blank"  href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F&amp;title=Simple%20debugging%20in%20kernel%20programming&amp;bodytext=When%20programming%20Linux%20kernel%20modules%2C%20you%20have%20limited%20debugging%20options.%20The%20main%20way%20is%20to%20use%20the%20printk%20function%20%28the%20kernel%20equivalent%20of%20printf%29.%20If%20you%20want%20to%20give%20as%20much%20information%20as%20possible%2C%20you%20could%20use%20some%20of%20the%20macros%20that%20the%20la" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/digg.png" class="sociable-img sociable-hovers" title="Digg" alt="Digg" /></a></li><li><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.strainu.ro%2Fprogramming%2Fc%2Fsimple-debugging-in-kernel-programming%2F&amp;title=Simple%20debugging%20in%20kernel%20programming" ><img src="http://www.strainu.ro/site/wp-content/plugins/sociable-30/images/default/16/stumbleupon.png" class="sociable-img sociable-hovers" title="StumbleUpon" alt="StumbleUpon" /></a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.strainu.ro/programming/c/simple-debugging-in-kernel-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

