Log Objective-c sends messages to the device

When the iOS application starts, the environment variable NSObjCMessageLoggingEnabled exists in the simulator, which calls all objc_msgSend calls to exit to the file. ( Detailed explanation ).

I am trying to trace all the messages that are sent in my application, but I cannot run it in the simulator. It must be on the physical device because I interact with the hardware through the lightning connector. For the same reason, I cannot connect the debugger to the process.

It would be useful to write a journal to disk, like the one that was created using NSObjCMessageLoggingEnabled , but write it locally to the My Documents folder or the like.

Is it possible?

+5
source share
1 answer

All NSObjCMessageLoggingEnabled really calls CoreFoundation to automatically call instrumentObjcMessageSends at startup and shutdown.

The problem is that Apple intentionally hid this feature in the native SDK for iOS, so you can't just name it.

But it still exists in dylib at runtime, so you can always do this:

 typedef void functype(BOOL); void *libobjc = dlopen("/usr/lib/libobjc.dylib", RTLD_LAZY); functype *instrumentObjcMessageSends = dlsym(libobjc, "instrumentObjcMessageSends"); if (!instrumentObjcMessageSends) { NSLog(@"Couldn't get instrumentObjcMessageSends"); exit(1); } instrumentObjcMessageSends(YES); NSLog(@"Did it"); 

I don’t know where, if anywhere, magazines are recorded. I assume you will want to call logObjcMessageSends to register your own ObjCLogProc , as described in the post you linked.

+3
source

Source: https://habr.com/ru/post/1201188/


All Articles