I am not interested in logging into frameworks or under the covers but only at my source level code upon entry and exit of each method. I would like it to provide Class Name and Method Name and log it to file or at least have it fly by on the screen.
My query is if it is pos开发者_如何学Pythonsible with existing Xcode/Debugger/Instruments facilities, can I implement it in an easy way other than an NSLog statement at every method entry and exit, or is there a commercial tool that provides this capability ?
I'm talking source methods here... not execution processes or threads. Thanks.
Dave Dribin covers precisely this in his article Tracing Objective-C messages.
The part you are after is probably this:
If you set the
NSObjCMessageLoggingEnabled
environment variable toYES
, the Objective-C runtime will log all dispatched Objective-C messages to a file named /tmp/msgSends-<pid>.
Xtrace (https://github.com/johnno1962/Xtrace) has many features and works well for tracing Objective-C. One needs source access to their project, like you appear to have, and can emit messages on entry/exit, like you appear to want.
- Debug-time configuration - can hard-code or configure tracing while debugging
- Uncomplicated integration - one .mm and one .h
- NSRegularExpression matching - classes, methods, types
An alternative which you can use with iOS simulator
on the Mac (arm/x86_64)
- Create a
Symbolic Breakpoint
- Symbol:
objc_msgSend
- Action:
Debugger Command
Command:
p (void)printf("[%s, %s]\n", (char*)object_getClassName($arg1), $arg2)
*
p
is an alias forexpr --
Check:
Automatically continue after evaluating actions
精彩评论