<?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>Ahruman’s Webthing &#187; Code</title>
	<atom:link href="http://jens.ayton.se/blag/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://jens.ayton.se/blag</link>
	<description>Cocoa coding stuff, when I can be bothered.</description>
	<lastBuildDate>Thu, 25 Aug 2011 21:56:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Hacking your Log Messages</title>
		<link>http://jens.ayton.se/blag/hacking-your-log-messages/</link>
		<comments>http://jens.ayton.se/blag/hacking-your-log-messages/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 01:33:21 +0000</pubDate>
		<dc:creator>Jens Ayton</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[skank]]></category>

		<guid isPermaLink="false">http://jens.ayton.se/blag/hacking-your-log-messages/</guid>
		<description><![CDATA[More nasty code inspired by IRC conversations, but this time aimed at the iPhone SDK – although it will work on Mac&#160;OS&#160;X as well, and on WebObjects&#160;4 for Windows&#160;NT, and probably on at least some flavours of NextStep. Simply drop this &#8230; <a href="http://jens.ayton.se/blag/hacking-your-log-messages/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://jens.ayton.se/blag/hackin-ur-crash-reportz/">More</a> nasty code inspired by IRC conversations, but this time aimed at the iPhone SDK – although it will work on Mac&nbsp;OS&nbsp;X as well, and on WebObjects&nbsp;4 for Windows&nbsp;NT, and probably on at least some flavours of NextStep. Simply drop <a href="/code/files/JANSLogHack.m">this file</a> into your project, and all <code class="objc-code">NSLog()</code> output will be redirected to <code class="objc-code">stdout</code>, using a private but <a href="http://docs.info.apple.com/article.html?artnum=70081">documented</a> Foundation function.</p>
<p>Why would you want to do that? Ahh, well, that part is covered by the iPhone SDK NDA. Lawyers, eh? It must be a pretty good reason, though, given testimonials like <a href="http://twitter.com/chockenberry/statuses/796361931">this</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jens.ayton.se/blag/hacking-your-log-messages/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Hacking your Crash Reports</title>
		<link>http://jens.ayton.se/blag/hackin-ur-crash-reportz/</link>
		<comments>http://jens.ayton.se/blag/hackin-ur-crash-reportz/#comments</comments>
		<pubDate>Tue, 18 Mar 2008 02:47:49 +0000</pubDate>
		<dc:creator>Jens Ayton</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[skank]]></category>

		<guid isPermaLink="false">http://jens.ayton.se/blag/hackin-ur-crash-reportz/</guid>
		<description><![CDATA[In a conversation on #macdev, it was pointed out that the Crash Reporter has an &#8220;Application Specific Information:&#8221; line when certain Apple apps crash. This obviously warranted investigation, and through the powers of Google it was determined that said investigation &#8230; <a href="http://jens.ayton.se/blag/hackin-ur-crash-reportz/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In a conversation on <a href="http://devintosh.com/index2.php">#macdev</a>, it was pointed out that the Crash Reporter has an &#8220;Application Specific Information:&#8221; line when certain Apple apps crash. This obviously warranted investigation, and through the powers of Google it was determined that said investigation <a href="http://www.allocinit.net/blog/2008/01/04/application-specific-information-in-leopard-crash-reports/" title="Application Specific Information in Leopard Crash Reports — allocinit.net">had in fact happened a few months ago</a>. How fortunate that we didn’t <a href="http://jens.ayton.se/blag/the-mysteries-of-ical-revealed/" title="The Mysteries of iCal, Revealed! — Ahruman’s Webthing">spend time investigating it and writing test cases, only to find someone had already done a better job</a>.</p>
<p>Anyway, this is an entirely unsupported thing to do, and the means of doing it may disappear at any time, so don’t. But if you do, do it cleanly, like this:
<pre class="objc-code">#ifndef NDEBUG
/*  Function to set “Application Specific Information” field in crash reporter
    log in Leopard. Extremely unsupported, so not used in release builds.
*/
static void InitCrashReporterInfo(void);
static void SetCrashReporterInfo(const char *info);
static BOOL sCrashReporterInfoAvailable = NO;
#else
#define InitCrashReporterInfo() do {} while (0)
#define SetCrashReporterInfo(i) do {} while (0)
#define sCrashReporterInfoAvailable 0
#endif

/* Insert code here. Or make it non-static, depending on what you’re doing. */

#ifndef NDEBUG
static char **sCrashReporterInfo = NULL;
static char *sOldCrashReporterInfo = NULL;
static NSLock *sCrashReporterInfoLock = nil;

static void InitCrashReporterInfo(void)
{
    // Load secret symbol __crashreporter_info__; don’t do anything if not found.
    sCrashReporterInfo = dlsym(RTLD_DEFAULT, "__crashreporter_info__");
    if (sCrashReporterInfo != NULL)
    {
        // We'll need a lock, too.
        sCrashReporterInfoLock = [[NSLock alloc] init];
        if (sCrashReporterInfoLock != nil)
        {
            sCrashReporterInfoAvailable = YES;
        }
        else
        {
            sCrashReporterInfo = NULL;
        }
    }
}

static void SetCrashReporterInfo(const char *info)
{
    char                    *copy = NULL, *old = NULL;

    /*  Don’t do anything if setup failed or the string is NULL or empty.
        (The NULL and empty checks may not be desirable in other uses.)
    */
    if (!sCrashReporterInfoAvailable || info == NULL || *info == '\0')  return;

    // Copy the string, which we assume to be dynamic...
    copy = strdup(info);
    if (copy == NULL)  return;

    /*  ...and swap it in.
        Note that we keep a separate pointer to the old value, in case
        something else overwrites __crashreporter_info__.
    */
    [sCrashReporterInfoLock lock];
    *sCrashReporterInfo = copy;
    old = sOldCrashReporterInfo;
    sOldCrashReporterInfo = copy;
    [sCrashReporterInfoLock unlock];

    // Delete our old string.
    if (old != NULL)  free(old);
}
#endif</pre>
<p>For this to be actually useful, you’d want to be using <a href="http://smartcrashreports.com/" title="Smart Crash Reports">Smart Crash Reports</a> (apparently <a href="http://www.unsanity.org/archives/betas/enthusiastic_trepidation.php" title="Enthousiastic Trepidation — Unsanity.org">coming soonish</a> to a Leopardy computer near you) or something similar.</p>
]]></content:encoded>
			<wfw:commentRss>http://jens.ayton.se/blag/hackin-ur-crash-reportz/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

