Skip to content

Instantly share code, notes, and snippets.

@atomkirk
Last active December 25, 2015 16:49
Show Gist options
  • Save atomkirk/7008367 to your computer and use it in GitHub Desktop.
Save atomkirk/7008367 to your computer and use it in GitHub Desktop.
Find where a view was added. (Cocoa)

Sometimes, a view will appear on your screen and you don't know how it got there. Did your app add it? Did the SDK add it? Here's how to get the debugger to stop right where it was added so you can look at the call stack.

First, set up a symbolic breakpoint on [UIView addSubview:]

Then run the app until it hits the first symbolic breakpoint. You'll be at some assembly that looks like this:

Set a breakpoint right where I've pointed out above. Disable the symbolic breakpoint so now all that will break is this new breakpoint you've just set. Run your app again.

Each time you hit this breakpoint, the registers $eax and $ecx will be available to you. $eax will contain the address to the view being added as a subview. $ecx will contain the address to the view adding the subview.

Keep hitting continue (control + command + Y) and checking the registers until you find the view you're looking for:

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