When running an iOS app in the simulator, there's an environment variable NSObjCMessageLoggingEnabled
that causes all objc_msgSend
calls to be logged out to a file. (Detailed explanation).
I'm trying to trace out all the messages that are being sent in my app, but I can't run it in the simulator. It has to be on a physical device because I'm interacting with hardware through the lightning connector. For the same reason, I can't attach a debugger to the process.
It would be helpful to write a log to disk like the one created with NSObjCMessageLoggingEnabled
, but write it locally in my app's Documents directory, or similar.
Is this possible?
All NSObjCMessageLoggingEnabled
does is cause CoreFoundation
to automatically call instrumentObjcMessageSends
at startup and shutdown.
The problem is that Apple has intentionally hidden that function in the native iOS SDK, so you can't just call it.
But it still exists in the dylib at runtime, so you can always do this:
#include <dlfcn.h>
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 have no idea where, if anywhere, the logs are being written to. I assume you're going to want to call logObjcMessageSends
to register your own ObjCLogProc
, as explained in the post you linked to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With