'How to improve the display of variables which are objects in the xcode 4.5 debugger
I'm using Xcode 4.5 on Mac with the iOS simulator to write iPhone apps. When I hit a breakpoint in the debugger, I use the "Auto" to look at variables. The problem is that the objects are initially all folded, and I have to expand each one to see its value. That's ok, but it is tedious and hard to read. Is there some way to CUSTOMIZE the way that data is presented in the debugger?
I've looked at LLDB tutorial and I looked at "custom summary strings" in the post by Quinn Taylor, but I don't understand it. He must have used an older version of xcode.
Basically, I have an object such as
class Vec3 { public: float x,y,z; };
and in the debug window I see
pos (Vec3)
and what I'd rather see is
pos = (Vec3) (x=45.2, y=10.7, z=2.0)
without having to expand the variable. Does anyone know how I can do that?
Solution 1:[1]
If Vec3 is your class (or something you can subclass), override its description
. That lets you format what appears when you say po pos
in the console.
To get fancier, consult this page:
http://lldb.llvm.org/varformats.html
You can say
type summary add --summary-string
followed by a string description of how you want this type of variable to be displayed.
If you really want to get into the nitty-gritty, you can write your own formatter; good discussion in the two WWDC 2012 videos on debugging and LLDB. But you have to write a Python script to do that, so I've given more of a "noob" solution.
Solution 2:[2]
I was able to get this working with xcode 4.5.2. To summarize, these are the steps.
open or create ~/.lldbinit using 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 hit a breakpoint the Vec3 will be displayed as,
pos (Vec3) x=1, y=3.125, z=9.5
You can do a lot of other things in the .lldbinit as described in http://lldb.llvm.org/varformats.html
For instance
type summary add Vec3 --inline-children --omit-names
will auto-generate a summary string and
type summary add --inline-children -x "Vec[:alnum:]*"
will auto-generate summary strings for ALL types that start with "Vec".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | John Henckel |