{"id":2856,"date":"2014-02-26T21:57:06","date_gmt":"2014-02-26T21:57:06","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/26\/use-gdb-to-examine-objective-c-class-from-crash-handledelegatesource-bad-access-collection-of-common-programming-errors\/"},"modified":"2014-02-26T21:57:06","modified_gmt":"2014-02-26T21:57:06","slug":"use-gdb-to-examine-objective-c-class-from-crash-handledelegatesource-bad-access-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/02\/26\/use-gdb-to-examine-objective-c-class-from-crash-handledelegatesource-bad-access-collection-of-common-programming-errors\/","title":{"rendered":"Use GDB to examine Objective C class from crash (HandleDelegateSource bad access)-Collection of common programming errors"},"content":{"rendered":"<p>I am trying to debug an intermittent error on the iPhone, a crash with a trace that looks like:<\/p>\n<pre><code>objc_message_send\n__invoking__\n[NSInvocation invoke]\nHandleDelegateSource\nMainRunLoop\n....\n<\/code><\/pre>\n<p>When GDB stops, I&#8217;d like to be able to determine details about what selector the system is attempting to be invoked &#8211; I&#8217;ve set a break point now around [NSInvocation Invoke], but from that point cannot figure out how to examine details of the NSInvocation object I am stopped in.<\/p>\n<ol>\n<li>\n<p>This article, recently published at Phrack should answer all your questions. Enlightening reading.<\/p>\n<\/li>\n<li>\n<p>A simple final answer &#8211; in GDB you can simply view the register with the name of the selector being called (theSelector parameter in lothar&#8217;s answer). It&#8217;s a C string, so you observe it using one of the following commands (depending on if you are running in the simulator or the device):<\/p>\n<pre><code>Simulator: display \/s $ecx\nDevice: display \/s $r1\n<\/code><\/pre>\n<\/li>\n<li>\n<p>If you look at the reference information for objc_msgSend you will see that the selector is the second argument. Now it should be easier to decipher the debugger output.<\/p>\n<blockquote>\n<p>objc_msgSend Sends a message with a simple return value to an instance of a class.<\/p>\n<p>id objc_msgSend(id theReceiver, SEL theSelector, &#8230;)<\/p>\n<p>Parameters theReceiver A pointer that points to the instance of the class that is to receive the message. theSelector The selector of the method that handles the message. &#8230;<\/p>\n<p>A variable argument list containing the arguments to the method.<\/p>\n<\/blockquote>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>I am trying to debug an intermittent error on the iPhone, a crash with a trace that looks like: objc_message_send __invoking__ [NSInvocation invoke] HandleDelegateSource MainRunLoop &#8230;. When GDB stops, I&#8217;d like to be able to determine details about what selector the system is attempting to be invoked &#8211; I&#8217;ve set a break point now around [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2856","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2856"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2856\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}