<?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>UNIXy Goodness &#187; Debugging</title>
	<atom:link href="http://quenelle.org/unix/category/debugging/feed/" rel="self" type="application/rss+xml" />
	<link>http://quenelle.org/unix</link>
	<description>UNIX developer tools and other cool stuff</description>
	<lastBuildDate>Mon, 23 Jan 2012 19:21:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Visualizing dynamic library dependencies</title>
		<link>http://quenelle.org/unix/2009/shared-library-graphs/</link>
		<comments>http://quenelle.org/unix/2009/shared-library-graphs/#comments</comments>
		<pubDate>Fri, 22 May 2009 15:59:01 +0000</pubDate>
		<dc:creator>Chris Quenelle</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[OpenSolaris]]></category>

		<guid isPermaLink="false">http://quenelle.org/unix/?p=243</guid>
		<description><![CDATA[<p>Darryl Gove has been working on graphical display of shared library dependencies. It seems useful for performance analysis and debugging of dynamically linked applications.</p> <p>He did one for StarOffice and for Firfox and Thunderbird.</p> StarOffice : http://blogs.sun.com/d/entry/drawing_libraries_neater_eye_candy Firefox, Thunderbird : http://blogs.sun.com/d/entry/graph_of_libraries_used_by ]]></description>
			<content:encoded><![CDATA[<p>Darryl Gove has been working on graphical display of shared library dependencies. It seems useful for performance analysis and debugging of dynamically linked applications.</p>
<p>He did one for StarOffice and for Firfox and Thunderbird.</p>
<ul>
<li>StarOffice : <a href="http://blogs.sun.com/d/entry/drawing_libraries_neater_eye_candy">http://blogs.sun.com/d/entry/drawing_libraries_neater_eye_candy</a></li>
<li>Firefox, Thunderbird : <a href="http://blogs.sun.com/d/entry/graph_of_libraries_used_by">http://blogs.sun.com/d/entry/graph_of_libraries_used_by</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://quenelle.org/unix/2009/shared-library-graphs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugger Design</title>
		<link>http://quenelle.org/unix/2009/debugger-design/</link>
		<comments>http://quenelle.org/unix/2009/debugger-design/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 00:52:46 +0000</pubDate>
		<dc:creator>Chris Quenelle</dc:creator>
				<category><![CDATA[dbx]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Developer Tools]]></category>

		<guid isPermaLink="false">http://quenelle.org/unix/?p=225</guid>
		<description><![CDATA[<p>I&#8217;ve spent a number of years in the dbx group at Sun, and over time you collect a lot of coulda-woulda-shoulda stories.  You know what I mean, &#8220;This code should really have been designed to do XYZ.&#8221;  Or &#8220;This module shouldn&#8217;t have to talk to that module.&#8221;  I figured I&#8217;d try to record some of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent a number of years in the dbx group at Sun, and over time you collect a lot of coulda-woulda-shoulda stories.  You know what I mean, &#8220;This code should really have been designed to do XYZ.&#8221;  Or &#8220;This module shouldn&#8217;t have to talk to that module.&#8221;  I figured I&#8217;d try to record some of the interesting bits for posterity, so I wrote an essay that I vaingloriously call a whitepaper.  So without further ado:</p>
<ul>
<li>
<h3><a href="http://quenelle.org/unix/white-papers/debugger-design/">Debugger Design</a></h3>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://quenelle.org/unix/2009/debugger-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging tips for threaded programs on Solaris</title>
		<link>http://quenelle.org/unix/2007/thread-asserts/</link>
		<comments>http://quenelle.org/unix/2007/thread-asserts/#comments</comments>
		<pubDate>Fri, 01 Jun 2007 02:03:24 +0000</pubDate>
		<dc:creator>Chris Quenelle</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[OpenSolaris]]></category>

		<guid isPermaLink="false">http://quenelle.org/unix/?p=162</guid>
		<description><![CDATA[<p>Phil Harmon wrote a blog entry over a year ago ( Solaris Threads Tunables ) where he mentioned a list of tunable parameters that you can use to fiddle around with the implementation of Solaris libthread. You can fine tune the spin-lock timeouts, and other timing details. But one of the flags that he mentioned [...]]]></description>
			<content:encoded><![CDATA[<p>Phil Harmon wrote a blog entry over a year ago (<a href="http://blogs.sun.com/pgdh/entry/solaris_threads_tunables_part_1"> Solaris Threads Tunables </a>) where he mentioned a list of tunable parameters that you can use to fiddle around with the implementation of Solaris libthread. You can fine tune the spin-lock timeouts, and other timing details. But one of the flags that he mentioned is NOT related to tuning libthread. It&#8217;s more related to debugging your program! Someone on our internal dbx-interest alias asked why their program (which had a bug) was acting different when run under dbx, and the answer turns out to be related to a &#8220;sync tracking&#8221; flag that dbx turns on by default. It causes somewhat stricter checking of mutex bugs to be turned on.</p>
<p>Anyway, it turns out that if you set the environment variable <tt>_THREAD_ERROR_DETECTION</tt> to 1 or 2 you can get an extra level of error checking enabled inside libthread. 1 produces warning messages, and 2 produces warning messages and a core file for inspection.</p>
<p>The messages look like this:</p>
<pre>*** _THREAD_ERROR_DETECTION: lock usage error detected ***
mutex_lock(0x8047d50): calling thread already owns the lock
calling thread is 0xfeea2000 thread-id 1</pre>
<p>Most of the implementation is in <a href="http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libc/port/threads/assfail.c"> libc/port/threads/assfail.c<img id="snap_com_shot_link_icon" class="snap_preview_icon" style="border: 0pt none; margin: 0pt ! important; padding: 1px 0pt 0pt; max-height: 2000px; max-width: 2000px; min-width: 0px; min-height: 0px; font-style: normal; font-weight: normal; font-family: &quot;trebuchet ms&quot;,arial,helvetica,sans-serif; float: none; position: static; left: auto; top: auto; line-height: normal; background-image: url(http://i.ixnp.com/images/v3.68/theme/silver/palette.gif); background-color: transparent; visibility: visible; width: 14px; height: 12px; background-position: -1128px 0pt; background-repeat: no-repeat; text-decoration: none; vertical-align: top; display: inline;" src="http://i.ixnp.com/images/v3.68/t.gif" alt="" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://quenelle.org/unix/2007/thread-asserts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Graphical display of thread synchronization</title>
		<link>http://quenelle.org/unix/2006/graphical-thread-synchronization/</link>
		<comments>http://quenelle.org/unix/2006/graphical-thread-synchronization/#comments</comments>
		<pubDate>Mon, 11 Sep 2006 02:02:21 +0000</pubDate>
		<dc:creator>Chris Quenelle</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Developer Tools]]></category>

		<guid isPermaLink="false">http://quenelle.org/unix/?p=23</guid>
		<description><![CDATA[<p>One of the things that&#8217;s really hard about debugging threaded programs is tracking down which threads own which locks, and figuring out which locks they are supposed to own. In other words, synchronization bugs.  The most difficult symptom to debug is data corruption, because it&#8217;s very hard to track down exactly where things start to [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that&#8217;s really hard about debugging threaded programs is tracking down which threads own which locks, and figuring out which locks they are <strong>supposed</strong> to own. In other words, synchronization bugs.  The most difficult symptom to debug is data corruption, because it&#8217;s very hard to track down exactly where things start to go wrong. In those cases where your program actually ends up in a deadlock, you get start with a smoking gun, and work from there. Much easier.</p>
<p>One way to find synchronization bugs in your program is to use Sun&#8217;s new <a title="DRDT Description" href="http://developers.sun.com/prodtech/cc/downloads/drdt/drdt_index.html">Data Race Detection Tool</a> you can find a preview version of that tool in <a title="Download Express 2" href="http://developers.sun.com/prodtech/cc/downloads/express.jsp">Sun Studio Express 2</a>.</p>
<p>Another way to hunt for bugs is to use dbx&#8217;s built-in synchronization debugging commands.  You can list all the locks in your program, and find out which threads own them, and which threads are waiting on them.</p>
<p>Here is some output from my dining philosophers program:</p>
<pre>(dbx) syncs
All locks currently known to libthread:
forks (0x00021670): thread  mutex(locked)
forks+0x18 (0x00021688): thread  mutex(locked)
forks+0x30 (0x000216a0): thread  mutex(locked)
forks+0x48 (0x000216b8): thread  mutex(locked)
forks+0x60 (0x000216d0): thread  mutex(locked)
foodlock (0x00021708): thread  mutex(unlocked)

(dbx) sync -info 0x00021670
forks (0x21670): thread  mutex(locked)
Lock owned by t@2
Threads blocked by this lock are:
        t@6 a l@6 philosopher() sleep on 0x21670 in __lwp_park()</pre>
<p>Okay, that&#8217;s fine. But obviously I need to pull out a pad of paper and start drawing boxes if I want to see where my bugs are. Of course, there are tools for drawing boxes and arrows, and all you have to do to use them is to convert your data into XML.</p>
<p>So I wrote a little ksh script and a little perl script, and presto, instant pictures. Well, I had to download a graph editing/layout tool &#8230; and I had to learn how to use it. But that wasn&#8217;t so bad.</p>
<p>When I first ran my dining philosophers program, now don&#8217;t laugh, I didn&#8217;t actually unlock my eating utensils. I wrote the unlocks, but then I rearranged some stuff, and they got dropped on the floor. So the first time I ran it, I got a deadlock.</p>
<p>My original plan was:</p>
<ul>
<li>write functioning dining philosophers program</li>
<li>inject artificial bug</li>
<li>write graph utility</li>
<li>write blog</li>
</ul>
<p>I ended up executing a slightly different plan:</p>
<ul>
<li>write buggy dining philosophers program</li>
<li>get deadlock</li>
<li>write graph utility</li>
<li>fix dining philosophers program</li>
<li>write blog</li>
</ul>
<p>Anyway, here is the picture that resulted from my deadlocked program. The graph edge with the same source/destination node is a dead give away. <img src='http://quenelle.org/unix/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  The t@2 names are the dbx names for the threads.  &#8220;forks&#8221; is the name if the array variable that holds the locks representing the eating utensils for the dining philosophers. So &#8220;forks&#8221; is one lock, and &#8220;forks+0xNN&#8221; is another lock. (see source code link below).</p>
<div id="attachment_24" class="wp-caption alignnone" style="width: 358px"><img class="size-full wp-image-24" title="grbug" src="http://quenelle.org/unix/wp-content/uploads/2009/02/grbug.jpg" alt="sync graph with bug" width="348" height="383" /><p class="wp-caption-text">sync graph with bug</p></div>
<p>Here is a picture when the program is working right. In other words, after I added my missing unlock statements.</p>
<div id="attachment_25" class="wp-caption alignnone" style="width: 143px"><img class="size-full wp-image-25" title="grworks" src="http://quenelle.org/unix/wp-content/uploads/2009/02/grworks.jpg" alt="sync graph for working program" width="133" height="590" /><p class="wp-caption-text">sync graph for working program</p></div>
<p>The ksh function is copied into the comments at the top of the perl script. So to run this demo yourself, here are the installation instructions.</p>
<ul>
<li>download <a title="source for demo program" href="http://mediacast.sun.com/share/quenelle/dine.c">dine.c</a></li>
<li>download <a title="perl program to convert dbx output to graphml" href="http://mediacast.sun.com/share/quenelle/syncs_to_graphml">syncs_to_graphml</a></li>
<li>install syncs_to_graphml somewhere on your search path (or edit the ksh script to find it)</li>
<li>copy the ksh script out of the comments in the perl script and into your ~/.dbxrc file</li>
<li>download the yEd program, and get it up and running (written in java, so it&#8217;s easy to set up)</li>
<li><a class="moz-txt-link-freetext" href="http://www.yworks.com/en/products_yed_about.htm">http://www.yworks.com/en/products_yed_about.htm</a></li>
</ul>
<p>To run the demo:</p>
<ul>
<li>compile dine.c with -g and -lpthread</li>
<li>load it into dbx</li>
<li>run it, and stop the program in the middle (ctrl-C)</li>
<li>use the new syncgraph command inside dbx</li>
<li>load the output file /tmp/syncgraph.graphml into the yEd editor</li>
<li>use Tools -&gt; Fit Node To Label (hit OK)</li>
<li>use Layout -&gt; Classic (hit OK)</li>
</ul>
<p>At that point, you should get a picture of the threads and their locks.</p>
<p>At that point you can play around with the various layout options for arranging the nodes in the graph.  Don&#8217;t be annoyed at all the little properties and numbers you can set.  I just ignore those most of the time. You can also export the image as jpg, pdf, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://quenelle.org/unix/2006/graphical-thread-synchronization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>debug info in XML, and DSD 2.0</title>
		<link>http://quenelle.org/unix/2005/debug-info-in-xml-and-dsd-20/</link>
		<comments>http://quenelle.org/unix/2005/debug-info-in-xml-and-dsd-20/#comments</comments>
		<pubDate>Sun, 18 Sep 2005 06:30:25 +0000</pubDate>
		<dc:creator>Chris Quenelle</dc:creator>
				<category><![CDATA[Compilers]]></category>
		<category><![CDATA[dbx]]></category>
		<category><![CDATA[Debugging]]></category>

		<guid isPermaLink="false">http://quenelle.org/unix/?p=110</guid>
		<description><![CDATA[<p>I&#8217;ve been working in my spare time on the idea of converting dwarf debugging information into XML so that I can format it as XHTML using a stylesheet, and so I can check it using a Schema of some sort. When I started fiddling today I assumed that using a DTD was the way to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working in my spare time on the idea of converting dwarf debugging information into XML so that I can format it as XHTML using a stylesheet,  and so I can check it using a Schema of some sort.  When I started fiddling today I assumed that using a DTD was the way to go, that what one does with XML, no?  Well after banging my head against the DTD format for a while, and looking for help on (our friend) the internet, I stumbled across a more general description of different ways to write XML schemas alternatives.  Notice the lower case schema there.  One of the several ways is called simply &#8220;XML Schema&#8221;, which is an alternative to DTD and DSD etc.  Don&#8217;t get confused yet, you  just started reading.</p>
<p>I had to kick myself in the head again tonight.  Every time I get really stumped on trying to find good information on the internet, I end up realizing that everything I wanted was already there in Wikipedia.  In the really confusing situations where I&#8217;m jumping in the deep end of the pool, all I really need to start me out is a two page summary of the state of the art. something to put all the technology jargon into context for me.  But I still haven&#8217;t learned to look on Wikipedia first. *kick* *ouch*</p>
<p>God, lists look ugly in the hacked theme I&#8217;m using.  I should fix them up one day.  Anyway, here is good info on the different ways to  formally describe your XML so that you can check it, and make sure it doesn&#8217;t have bugs.</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Document_Type_Definition">DTD Wikipedia entry</a></li>
<li><a href="http://en.wikipedia.org/wiki/XML_schema">XML Schema Wikipedia Entry</a></li>
<li><a href="http://www.brics.dk/%7Eamoeller/XML/schemas/">Good comparison of old and new languages.</a></li>
</ul>
<p>From oldest and klunkiest to newest and hottest, the different languages are: 1) DTD 2) &#8220;XML Schema&#8221; 3) DSD 2.0</p>
<p>Note: Clayton Wheeler also pointed me at Relax NG, which is much more elegant.</p>
]]></content:encoded>
			<wfw:commentRss>http://quenelle.org/unix/2005/debug-info-in-xml-and-dsd-20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

