Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Main Thread Checker dylib injection

Tags:

xcode9

dylib

According to the Apple Developer Documentation Diagnosing Memory, Thread, and Crash Issues Early, in the "Detect Improper UI Updates on Background Threads" section, the libMainThreadChecker.dylib can be injected at runtime to an application in order to use the Main Thread Checker tool. How would one go about injecting this dylib before (if possible) or during runtime without using the diagnostic setting in Xcode? I've tried injecting using the osxinj and yololib projects on GitHub with no luck.

like image 341
mservidio Avatar asked Mar 07 '23 21:03

mservidio


2 Answers

There's a number of ways you can do this: the easiest is probably setting the DYLD_INSERT_LIBRARIES environment variable to /Applications/Xcode.app/Contents/Developer/usr/lib/libMainThreadChecker.dylib. (You can do this from the "Arguments" tab of the Schemes editor.)

Another way would be to dynamically load it in code. Just put something like dlopen("/Applications/Xcode.app/Contents/Developer/usr/lib/libMainThreadChecker.dylib", RTLD_LAZY) early in your app's startup path.

You could also directly link against the library, but that would hardcode the library into your app, which I would not really recommend for something used largely for debugging.

like image 199
saagarjha Avatar answered Mar 28 '23 22:03

saagarjha


Click on your project name beside the Stop button -> Edit scheme. Under Diagnostics there's an option to enable/disable it

enter image description here

like image 44
meowmeowmeow Avatar answered Mar 28 '23 22:03

meowmeowmeow