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

前端 未结 3 2012
日久生厌
日久生厌 2021-02-20 13:51

I would like to set a symbolic breakpoint on \"objectAtIndex:\" method of a specific property in a specific class.

See the following code :

@interface Fo         


        
3条回答
  •  萌比男神i
    2021-02-20 14:22

    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 :

    Xcode dynamic breakpoint

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

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

提交回复
热议问题