I recently ran into a problem for which there were no working solutions on Google. I'd like to log an applications's Objective-C messages to the console or to a file. I didn't write the application so I don't have the source code to recompile with logging included. I have a jailbroken iPhone so no restrictions on how to realize this. I even considered doing this through a MobileSubstrate extension (may I hook objc_msgSend for that application to do some logging?), but had not very much ideas. Can you please help me out with this?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
There is a logging mechanism for ObjC messages, but I'm not sure whether you'll get method names without symbol files. Assuming that your jailbroken phone will allow you to run any app under control of the debugger (gdb), you should be able to start the app, set a breakpoint early during the initialization, then do this:
(gdb) call (void)instrumentObjcMessageSends(YES)
The log file will be written to a text file in the tmp folder. More details here:
http://www.dribin.org/dave/blog/archives/2006/04/22/tracing_objc/