How to set a breakpoint on "objectAtIndex:" method of a specific property in a specific class in XCode 4?

breakpoints, objective-c, xcode, xcode4

Solution

After some digging, I found a way to work this out. That's kinda ugly.

It involves creating a conditional breakpoint dynamically, in a command triggered by a first breakpoint.

First, break whenever your fooArray is ready. I settled on the `fooArray` accessor, but it could be done earlier :

` breakpoint set --name "-[Foo fooArray]" `

Then, what you want is break when `objectAtIndex:` is called on this specific array object. First let's put its pointer in a variable :

` expr id $watch = self->_fooArray `

and then create a new breakpoint, using this variable in the condition :

` breakpoint set --name "-[__NSArrayI objectAtIndex:]" --condition "$rdi == $watch" `

- `$rdi` contains `self`, at least on `x86_64`. Use `$r0` on ARM. (See Clark Cox's great post on the topic.)

- `-[NSArray objectAtIndex:]` is never called. As Peter mentioned, NSArray is a class cluster, and your array is actually an `__NSArrayI`.

Or, in Xcode :

(Don't forget to check the "continue" box.)

It's not really beautiful, but it seems to work !

Problem

I would like to set a symbolic breakpoint on "objectAtIndex:" method of a specific property in a specific class. See the following code : ``` @interface Foo ... @property (strong,nonatomic) NSMutableArray *fooArray; ... @end ``` I 've tried the following things: - `-[[Foo fooArray] objectAtIndex:]` - `-[Foo::fooArray objectAtIndex:]` - `-[Foo::fooArray objectAtIndex]` - `Foo::fooArray::objectAtIndex:` - `Foo::fooArray::objectAtIndex` - `Foo::fooArray::objectAtIndex()` None of theses solutions work. Any ideas to do the trick ?

Original source

Related problems