Created
December 7, 2017 18:22
-
-
Save kastiglione/d4be0e82405b9c85d37bd35ae2d58102 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add this to ~/.lldbinit; Then run: `main-check SomeClass someSelector:doesThing:` | |
command regex main-check 's/(.+) +(.+)/expr -lobjc -- (void)__main_thread_add_check_for_selector((void*)objc_getClass("%1"), @selector(%2))/' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void addMainThreadCheck(Class cls, SEL selector) { | |
#if DEBUG | |
void *symbol = dlsym(RTLD_DEFAULT, "__main_thread_add_check_for_selector"); | |
if (!symbol) { | |
return; | |
} | |
void (*addCheck)(Class, SEL) = (__typeof__(addCheck))symbol; | |
addCheck(cls, selector); | |
#endif | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func addMainThreadCheck(_ cls: AnyClass, _ selector: Selector) { | |
#if DEBUG | |
let RTLD_DEFAULT = UnsafeMutableRawPointer(bitPattern: -2) | |
guard let symbol = dlsym(RTLD_DEFAULT, "__main_thread_add_check_for_selector") else { | |
return | |
} | |
typealias Signature = @convention(c) (AnyClass, Selector) -> Void | |
let addCheck = unsafeBitCast(symbol, to: Signature.self) | |
addCheck(cls, selector) | |
#endif | |
} |
Thanks for commenting. Is the checker enabled in the scheme's Run > Diagnostics?
Yep. Without that you hit the return
codepath
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FWIW seems like this method doesn't work anymore. Registering the selector works but it never fires the checker