Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4.3 Breakpoint Logging object descriptions

I'd like to move from NSLogging all over the place to using breakpoints for logging where the performance hit doesn't preclude it.

I know I can just po an object with a Debugger Command action, and I know I can just log any string by choosign the Log Message action.

And I think I should be able to combine both by choosing Log Message and entering something like SomeText giving context for object description: @(const char *)[[anObject description] UTF8String]@. Unfortunately, this doesn't seem to work, and always gives me what I assume to be the pointer to the description string.

What am I doing wrong?

like image 695
fzwo Avatar asked May 16 '26 21:05

fzwo


1 Answers

It's kinda tricky but I think that this will work. Set the breakpoint Action as a debugger command. Then use this text as the action:

po (NSString *) [@"Some text describing: " stringByAppendingString:(NSString *)[anObject description]]

You must always be very careful to cast return types when working in the debugger. Both with GDB and LLDB.

I like your idea of using breakpoints to avoid the performance hit, but this also means that your logs will only be printed when connected to a debugger. While NSLogs will buffer their output to the system log, viewable from the Organizer (Devices) in Xcode.

like image 191
Sam Avatar answered May 18 '26 19:05

Sam