How to improve the display of variables that are objects in the xcode 4.5 debugger (noob)

I am using Xcode 4.5 on a Mac with an iOS simulator to write iPhone apps. When I hit a breakpoint in the debugger, I use "Auto" to view the variables. The problem is that the objects are initially stacked, and I have to expand each one to see its meaning. This is normal, but it is tiring and difficult to read. Is there a CUSTOMIZING way to present data in a debugger?

I looked at the LLDB tutorial and I looked at the "custom summary lines" in the Quinn Taylor post , but I don't get it. He must have used an older version of xcode.

Basically, I have an object like

class Vec3 {public: float x, y, z; };

and in the debug window I see

pos (Vec3) 

and what I would rather see

  pos = (Vec3) (x=45.2, y=10.7, z=2.0) 

without the need to expand the variable. Does anyone know how I can do this?

+6
source share
2 answers

If Vec3 is your class (or something you can subclass), override its description . This allows you to format what appears when you say po pos in the console.

To find out about this, refer to this page:

http://lldb.llvm.org/varformats.html

you can say

 type summary add --summary-string 

and then a string description of how you want to display this type of variable.

If you really want to get into nitty-gritty, you can write your own formatter; nice discussion in two WWDC 2012 debugging and LLDB videos. But you have to write a Python script to do this, so I gave more "noob".

+2
source

I managed to get this working with xcode 4.5.2. To summarize, these are the steps.

  • open or create ~ / .lldbinit with a text editor and add this line

     type summary add Vec3 --summary-string "x=${var.x}, y=${var.y}, z=${var.z}" 
  • restart xcode. Now, when you click the breakpoint, Vec3 will display as

     pos (Vec3) x=1, y=3.125, z=9.5 

You can do many other things in .lldbinit as described at http://lldb.llvm.org/varformats.html

for instance

 type summary add Vec3 --inline-children --omit-names 

will automatically generate a summary line and

 type summary add --inline-children -x "Vec[:alnum:]*" 

will automatically generate summary lines for ALL types starting with "Vec".

+7
source

All Articles