<?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>Orange Juice Liberation Front &#187; debugging</title>
	<atom:link href="http://orangejuiceliberationfront.com/tag/debugging/feed/" rel="self" type="application/rss+xml" />
	<link>http://orangejuiceliberationfront.com</link>
	<description>Uli&#039;s citrussy fresh thoughts on technical stuff</description>
	<lastBuildDate>Mon, 13 May 2013 20:59:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Debugging memory on OS X</title>
		<link>http://orangejuiceliberationfront.com/debugging-memory-on-os-x/</link>
		<comments>http://orangejuiceliberationfront.com/debugging-memory-on-os-x/#comments</comments>
		<pubDate>Fri, 23 Feb 2007 12:11:01 +0000</pubDate>
		<dc:creator>uliwitness</dc:creator>
				<category><![CDATA[Macintosh]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[carbon]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[memory smasher]]></category>
		<category><![CDATA[objective c]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.orangejuiceliberationfront.com/?p=90</guid>
		<description><![CDATA[Just a short note so I don&#8217;t have to Google around Apple&#8217;s web site for hours: There&#8217;s a few useful environment variables that can be set to help in debugging disposed memory accesses etc. Most of them are documented on Enabling the mallocDebug features and Finding memory leaks: Set DYLD_INSERT_LIBRARIES to /usr/lib/libMallocDebug.A.dylib. This makes you &#8230;  <a href="http://orangejuiceliberationfront.com/debugging-memory-on-os-x/">Continue reading</a>]]></description>
				<content:encoded><![CDATA[<p>Just a short note so I don&#8217;t have to Google around Apple&#8217;s web site for hours: There&#8217;s a few useful environment variables that can be set to help in debugging disposed memory accesses etc. Most of them are documented on <a href="http://developer.apple.com/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html#//apple_ref/doc/uid/20001884-CJBJFIDD">Enabling the mallocDebug features</a> and <a href="http://developer.apple.com/documentation/Performance/Conceptual/ManagingMemory/Articles/FindingLeaks.html">Finding memory leaks</a>:</p>
<ul>
<li>Set <tt>DYLD_INSERT_LIBRARIES</tt> to <tt>/usr/lib/libMallocDebug.A.dylib</tt>. This makes you link against libMallocDebug, which prints errors on bad accesses. Set a breakpoint on <tt>MDprintf</tt> to see a backtrace when this triggers.</li>
<li>set <tt>MallocScribble</tt> and <tt>MallocPreScribble</tt> to <tt>YES</tt> to initialize new memory to 0xAA and freed memory to 0&#215;55, which will also help finding out when you&#8217;re accessing bad memory.</li>
<li>set <tt>MallocGuardEdges</tt> to <tt>YES</tt> to make it harder to smash memory and instead get a bad access exception.</li>
</ul>
<p>Any other memory debug tricks you guys have?</p>
]]></content:encoded>
			<wfw:commentRss>http://orangejuiceliberationfront.com/debugging-memory-on-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging Assembler on Mac OS X</title>
		<link>http://orangejuiceliberationfront.com/debugging-assembler-on-mac-os-x/</link>
		<comments>http://orangejuiceliberationfront.com/debugging-assembler-on-mac-os-x/#comments</comments>
		<pubDate>Sat, 11 Nov 2006 15:01:06 +0000</pubDate>
		<dc:creator>uliwitness</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[Macintosh]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[assembly language]]></category>
		<category><![CDATA[darwin]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[gdb]]></category>
		<category><![CDATA[intel assembler]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.orangejuiceliberationfront.com/?p=227</guid>
		<description><![CDATA[The thing a programmer probably does most is, unsurprisingly, debugging. Not that programmers necessarily love debugging, but if you don&#8217;t have a high pain tolerance for debugging, you probably don&#8217;t want to pursue a career in programming. On the other hand, if you like the challenge of the bug hunt, you should try getting into &#8230;  <a href="http://orangejuiceliberationfront.com/debugging-assembler-on-mac-os-x/">Continue reading</a>]]></description>
				<content:encoded><![CDATA[<p>The thing a programmer probably does most is, unsurprisingly, debugging. Not that programmers necessarily love debugging, but if you don&#8217;t have a high pain tolerance for debugging, you probably don&#8217;t want to pursue a career in programming. On the other hand, if you like the challenge of the bug hunt, you should try getting into this biz. Or into exterminating. Whatever makes you happy, man.</p>
<p>Anyway, my recent posting on <a href="http://blog.orangejuiceliberationfront.com/?p=225">Intel Assembly Language Programming on Mac OS X</a> kinda left you hanging in the air on this one. I didn&#8217;t say anything about debugging. Why? Because, honestly, I hadn&#8217;t got that far yet. Of course, the first bug didn&#8217;t leave me waiting for long, so here&#8217;s some handy tools if you want to debug your assembler program.</p>
<p>First, you need to compile your assembler source files with GCC using the <tt>-g</tt> option. That will give you debug symbols, which means the debugger will show you each line. Once you&#8217;ve done that, you just launch GDB, on the command line, as usual:</p>
<pre>% gdb path/to/your/executable</pre>
<p>You&#8217;ll get the GDB prompt you may have already seen in Xcode&#8217;s debugger console. Type in</p>
<pre>(gdb) start</pre>
<p>and it will jump to the start of your <tt>main</tt> function. GDB will always print the next line, and you can use the <tt>step</tt> command to execute it and see the next one. Of course, you may want to see what is in a particular register or at a particular memory address. Easy:</p>
<pre>(gdb) print/x $eax</pre>
<p>will print register <tt>eax</tt> as hexadecimal (that&#8217;s what the &#8216;/x&#8217; means &#8211; there&#8217;s also &#8216;/d&#8217; for decimal, &#8216;/c&#8217; for character, &#8216;/s&#8217; for string and &#8216;/t&#8217; for binary). If you want to view a memory location, you use the &#8216;x&#8217; command instead.</p>
<pre>(gdb) x/1xb $eax</pre>
<p>will take the address in $eax, and print 1 byte at that address in hexadecimal. The parts after the slash decode into <tt>/&lt;count&gt;&lt;displayFormat&gt;&lt;type&gt;</tt>. <tt>displayFormat</tt> is the same as the thing after the slash when you print, <tt>count</tt> is a number indicating how many to print, and <tt>type</tt> is &#8216;b&#8217; for byte, &#8216;h&#8217; for halfword (2 bytes) or &#8216;w&#8217; for word (4 bytes).</p>
<p>Oh yeah and to get out of gdb again, the command is <tt>quit</tt>. Happy debugging!</p>
<p><strong>Update:</strong> I recently realized I&#8217;d omitted two important little tricks from this description: If you don&#8217;t have debug symbols, you can still step through code. The relevant commands are</p>
<pre>(gdb) si</pre>
<p>which steps through code by one instruction (this even works with system functions etc.) and</p>
<pre>(gdb) p/i</pre>
<p>which disassembles and prints the current instruction.</p>
]]></content:encoded>
			<wfw:commentRss>http://orangejuiceliberationfront.com/debugging-assembler-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

 Served from: orangejuiceliberationfront.com @ 2013-05-21 05:02:45 by W3 Total Cache -->