2

I am using Xcode 4.3.3 and I want to set symbolic endpoints. I created a symbolic breakpoint for all objc_msgSend symbols and I wanted to combine it with a "Debugger output".

I followed the tips of this post in SO. However in my debugger the message

error: 'printf' is not a valid command.

appears. Any clue? I want for every function call a message [Class method] to be printed in the debugger area. Like this

[UIApplication sharedApplication]
[UIApplication _isClassic]
[NSCFString getCString:maxLength:encoding:]
[UIApplication class]
[SLSMoleculeAppDelegate isSubclassOfClass:]
[SLSMoleculeAppDelegate initialize]
Community
  • 1
  • 1
cateof
  • 6,608
  • 25
  • 79
  • 153

1 Answers1

4

It works with lldb if you prefix "expr --" to the debugger command in the breakpoint settings:

expr -- (void)printf("[%s, %s]\n",(char *) object_getClassName(*(long*)($esp+4)), (char *) *(long *)($esp+8) )

The solution is not perfect however, because the debugger prints "no result" after each output:

[OS_xpc_dictionary, _xref_dispose]
<no result>
[NSObject, initialize]
<no result>
[OS_object, initialize]
<no result>

I have found nothing to suppress the "no result" output, it may be that it is not possible, see this Open Radar.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • It looks like Sean Callanan fixed the "no result" output in the lldb sources a couple months ago when evaluating an expression that returns void - although this change hasn't been included in an Xcode release yet. v. http://lists.cs.uiuc.edu/pipermail/lldb-commits/Week-of-Mon-20120806/006287.html – Jason Molenda Oct 02 '12 at 19:55
  • @JasonMolenda: Thank you for the information. I have just tested it with LLDB-167.4, which is part of the current Xcode 4.5.1, and "no result" is still printed. – Martin R Oct 06 '12 at 10:22
  • Yeah his checkin was more recent than that release; lldb-168 and later should have this change in it. – Jason Molenda Oct 06 '12 at 21:24
  • BTW the reason a change from early August isn't in a release of early October is to do with release branching ... the lldb-167.2 was released in Xcode 4.5 in September; Xcode 4.5.1 was a dot release to fix a few bugs that slipped through. They must have decided to include a fix or two in lldb in the 4.5.1 release so they copied those isolated patches into the lldb-167 branch and made an lldb-167.4 in late September. They didn't import all of the changes in the last two months, only the isolated fixes needed, so that other bugs weren't introduced. Next big release should include the fix. – Jason Molenda Oct 06 '12 at 21:50
  • And just to follow up on all this -- The `` output won't happen with Xcode 4.6.x, I just verified with lldb-179.5. – Jason Molenda May 02 '13 at 19:25
  • I currently get "error: use of undeclared identifier '$esp'" when trying to use this, any idea why? – BarrettJ May 29 '13 at 13:14
  • 1
    @BarrettJ: Is that on 64-bit or arm? Then this might help: http://stackoverflow.com/a/16346300/1187415. – Martin R May 29 '13 at 13:24