6

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?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
John Henckel
  • 10,274
  • 3
  • 79
  • 79

2 Answers2

8

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

  1. 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}"
    
  2. 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".

John Henckel
  • 10,274
  • 3
  • 79
  • 79
  • Another useful tidbit. You can double-click on the variable in the watch window, and a pop-up appears called "Set Summary Format for type" in which you can temporarily customize the summary string of the type. However the syntax appears to be slightly different from the "type summary add..." – John Henckel Jan 03 '13 at 16:47
2

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Yes I can modify Vec3. The "description" message works ok for Objective-C, but not C++. And it only works in the console window. I was hoping to be able to customize the watch window. In MS Studio you can do it very nicely with the "autoexp.dat" file. – John Henckel Dec 18 '12 at 22:09
  • Hey! I just found a really [great web page](http://disanji.net/iOS_Doc/#documentation/DeveloperTools/Conceptual/XcodeDebugging/220-Viewing_Variables_and_Memory/variables_and_memory.html) that tells how you can make custom formatters for structs (like CGRect) by modifying `CustomDataViews.plist`... Unfortunately Apple has removed it... at least, I can't find it anywhere. – John Henckel Dec 18 '12 at 22:31
  • "I was hoping to be able to customize the watch window", yep, well, that's what the Python script is for. You write it, you add it through your ~/.lldbinit file, you're all set. – matt Dec 18 '12 at 22:33
  • I think you're confused between GDB and LLDB, dude. – matt Dec 18 '12 at 22:34