Using symbolic breakpoints for child classes in Xcode?

I have a SomeClass class that inherits from UIView , and I want to track where its setFrame: method was called.

In the case of UIView I could add a symbolic breakpoint with the value -[UIView setFrame:] , but I cannot do the same for my own class - it just does not call / does not stop at the breakpoint. And of course, I cannot use -[UIView setFrame:] , because it will be called redundant. How to solve this problem?

I could override setFrame: in my class, but in this case I don’t need a symbolic breakpoint, and it’s better to use a regular breakpoint instead. But in this case, I also need to add some changes to my own class, and this is not very suitable for me.

+1
debugging ios objective-c xcode uiview
source share
1 answer

If I understand correctly, you want to set a breakpoint at - [UIView setFrame:], but only stop it when the "I" is an object of the SomeClass class. You can do this with a breakpoint condition. Something like:

 (int) strcmp("SomeClass", (const char *)class_getName((id)[(id) $arg1 class])) == 0 

The only trick is that $arg1 is an alias for the register that contains the first argument, and in ObjC methods the first argument is always self . Note that the register alias $ arg1 is defined only for architectures that use registers to pass arguments; in particular, 32-bit x86 does not pass arguments this way. The following answer provides a good description of how to get the first argument for most common architectures:

Symbolic breakpoint when calling dispatch_async with a specific queue

This may slow down the process a bit, as it will stop every time you call [UIView setFrame] , but there is no better way to avoid this, except that you suggest overriding setFrame: then stop it.

I also a little disgustingly outsmarted the casting here. We do not have debugging information for many of these functions, so you must tell the debugger what their return types are.

By the way, the lldb command line also has a type of "break on selector", which will break in all implementations of this selector. There is no UI ability to call this, but in the console you can do:

 (lldb) break set -S setFrame: 

So, you can set a breakpoint for all setFrame: methods, and then add the same condition (you can do this by passing the -c flag to the break set command. If this breakpoint corresponds to too many functions, you can disable individual hits by looking at their indices with the break list and then disabling them one by one using the bkpt.loc form, which you will see in the break list output.

+2
source share

All Articles