Search code examples
iosdebuggingios-simulatorxcode4.5formatter

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

  • 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.