Skip to content

Instantly share code, notes, and snippets.

@MattyAyOh
Created January 13, 2016 13:40
Show Gist options
  • Save MattyAyOh/0207084340841f5e4369 to your computer and use it in GitHub Desktop.
Save MattyAyOh/0207084340841f5e4369 to your computer and use it in GitHub Desktop.
How to set symbolic breakpoints to identify when an object is registered/unregistered to NSNotificationCenter
-[NSNotificationCenter addObserver:selector:name:object:]
and
-[NSNotificationCenter addObserverForName:object:queue:usingBlock:]
With the condition:
(BOOL)[@"fractionCompleted" isEqualToString:(id)$r8]
and
(BOOL)[@"fractionCompleted" isEqualToString:(id)$rdx]
Then set an action as a Debugger Command:
po $rdx
and
po $rcx
If you're curious about why the registers change, that is because OS X follows the System V ABI for register calling conventions. Arguments for a method go into:
rdi, rsi, rdx, rcx, r8, r9
In that argument order. Because Objective-C messages get compiled into objc_msgsend(receiver, selectorname, argument1, argument2, argument3, argument4)
@MattyAyOh
Copy link
Author

MattyAyOh commented Mar 13, 2017

Informal Protocol KVO symbols:

-[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:]
-[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:]

@MattyAyOh
Copy link
Author

Checking type of class of a pointer in register:

(BOOL)[(id)$rdi isKindOfClass:(Class)[EditorImageView class]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment