开发者

Xcode debugger -- inspect a deeply nested object

I have a recursive-descent tree object. I want to be able to set a breakpoint and inspect it in the Xcode debugger. Inspecting the top level works just fine. But after I go down a level or so, the debugger says the values of the ivars are out of scope. Is there any way I can keep this from happening?

EDIT:

In response to a comment --

The ivar is an object of class Expression. The nesting mostly comes from the body ivar, which is typically an NSMutableArray of expression objects. So you might have a structure like this:

-Expression

---body (2 expressions)

-----0 Exp开发者_JAVA百科ression

-------body (1 expression)

----------0 Expression

------------body [empty]

-----1 Expression

-------body [empty]

There is also a head ivar, which is an object of class Token, which in turn has some string ivars, does not nest.

The way I use the debugger -- I set a breakpoint in a method inside the Expression object. I then click on the disclosure triangle for arguments, then for self, then for the body ivar, then for expressions within the body ivar, and so on. But eventually the debugger stops telling me the values of things.


I recommend adding this to your Expression class. Then you can po [expression explode] in the debugger to print the tree of an expression. A prerequisite is a proper -description method for your Expressionclass that prints out the rest of the ivars.

- (void) explodeAtLevel:(int)aLevel {
    NSMutableString* out = [[NSMutableString alloc] init];

    for (int i = 0;  i < aLevel; i++) [out appendString:@"-"];

    [out appendString:self.description];
    printf("%s\n", [out UTF8String]);
    [out release];

    for (id *subitem in body)
      if ([subitem isMemberOfClass:[Expression class]])
        [((Expression*)subitem) explodeAtLevel:(aLevel + 1)];
}


- (void) explode {
  [self explodeAtLevel:0];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜