{"id":86,"date":"2011-02-11T10:32:00","date_gmt":"2011-02-11T10:32:00","guid":{"rendered":"https:\/\/www.root42.de\/blog\/?p=86"},"modified":"2011-02-11T10:32:00","modified_gmt":"2011-02-11T10:32:00","slug":"valgrind-checking-of-ios-programs","status":"publish","type":"post","link":"https:\/\/www.root42.de\/blog\/?p=86","title":{"rendered":"Valgrind checking of iOS programs"},"content":{"rendered":"<p>Well, this is awesome news. First, <a href=\"http:\/\/valgrind.org\/\">valgrind<\/a> has been available for OS X for some time now. And second, you can use it to <a href=\"http:\/\/landonf.bikemonkey.org\/code\/iphone\/iPhone_Simulator_Valgrind.20081224.html\">check your iOS programs<\/a> on the simulator with it.<\/p>\n<p>The idea here is to let your program spawn valgrind itself. Because you cannot tell the simulator to run the program through valgrind. Well, maybe you could build a funky bundle, but I think this works just fine. So here is the &nbsp;code, taken from the above link:<\/p>\n<pre>#define VALGRIND \"\/usr\/local\/valgrind\/bin\/valgrind\"<br \/> <br \/>int main(int argc, char *argv[]) {<br \/>#ifdef VALGRIND_REXEC<br \/>    \/* Using the valgrind build config, rexec ourself<br \/>     * in valgrind *\/<br \/>    if (argc &lt; 2 || (argc &gt;= 2 &amp;&amp; strcmp(argv[1], \"-valgrind\") != 0)) {<br \/>        execl(VALGRIND, VALGRIND, \"--leak-check=full\", \"--dsymutil=yes\", argv[0], \"-valgrind\",<br \/>              NULL);<br \/>    }<br \/>#endif<br \/>  <br \/>    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];<br \/>    int retVal = UIApplicationMain(argc, argv, nil, @\"PeepsAppDelegate\");<br \/>    [pool release];<br \/>    return retVal;<br \/>}<br \/><\/pre>\n<p>You will obviously want to define the <span style=\"font-family: 'Courier New', Courier, monospace;\">VALGRIND_REXEC<\/span> macro, if you need valgrind output. You can also pass different command line arguments to valgrind. E.g. you can switch to different valgrind tools this way, or pipe everything to a log-file.<br \/><b>Update:<\/b>&nbsp;I finally got around to trying out this method. One problem here is that valgrind will fail to run, since it tries to open \/dev\/random, which I guess is not allowed for sandboxed applications. But one can fix this by <a href=\"http:\/\/stackoverflow.com\/questions\/4599462\/valgrind-and-ios-sdk-4-2\">patching and recompiling valgrind<\/a>, which is not too hard. Especially when using MacPorts. Furthermore, I needed to add <span style=\"font-family: 'Courier New', Courier, monospace;\">&#8211;dsymutil=yes<\/span> to the valgrind options, or else the program would just crash.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well, this is awesome news. First, valgrind has been available for OS X for some time now. And second, you can use it to check your iOS programs on the simulator with it. The idea here is to let your program spawn valgrind itself. Because you cannot tell the simulator to run the program through &hellip; <a href=\"https:\/\/www.root42.de\/blog\/?p=86\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Valgrind checking of iOS programs&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,62,24,63],"tags":[],"_links":{"self":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/86"}],"collection":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=86"}],"version-history":[{"count":0,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/86\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}