views:

60

answers:

2

In its default (ie, my) configuration, Xcode is somewhat unhelpful in its debugger window for variables, especially those of the common Objective-C collections variety.

The debugger seems to usually want to display the underlying Obj-C structure when I expand some object, so I'm looking at isas and the class hierarchy.

But what I almost always want here is something semantically meaningful for the object itself. E.g. for an NSDictionary, I'd ideally want to see a list of keys/values. If those keys and values are, for example NSStrings, I just want to see the string values, not complex nested objects. Same goes for NSSets, NSArrays, and the bytes inside an NSData. And NSStrings, while usually getting their string representation in the Summary column, are impossible to look at when they're long (e.g. a pathname that's too long to fit in the column doesn't seem to scroll)-- when I double-click it, I get the display template string instead, so I can't select/copy it either.

I have recently spent time in Eclipse debugging Java, and for all its faults, Eclipse knows about all the Java collections, and has a simple one-line dump out of the contents of a string or collection or whatever when you find it in the debugger.

Is there a way to get this in Xcode? Am I missing something obvious, or should I be diving into the display templating system? I know there's some support there, as NSArrays seem to get a special kind of listy format, NSDictionaries get a "2 key/value pairs" summary, etc.

EDIT: It's possible to drop into GDB to get more data on objects. I'm disheartened that GDB's po acting on an NSDictionary gives the sort of awesomely useful output that I expect from a GUI debugger. Can this be replicated without context switching to the console?

I enjoy the Xcode environment so much, but the near-complete opaqueness of objects that I use all the time really stymies debugging time. Thanks.

+3  A: 

Yep, XCode variables lookup during the debug is weak, but it is based on gdb and you can control it thought the console. During debug open the console and write whatever command you need, to see the NSDictionary* dic; contents it's as simple as

po dic

po prints data as presented in the [obj description] result. You can also call any methods like

po [dict valueForKey:@"myKey"], or p(NSRect) [[self view] frame]

You can get more in gdb help

Gobra
+1 Thanks Gobra. I'm going to edit the question to emphasize that I'm hoping for non-commandline solutions, but I understand that this might be the best solution out there, unfortunately.
quixoto
+3  A: 

I would look at both special GDB output (as Gobra noted), but also the display templates.

The display stuff looks complex but is actually pretty simple - here's an example for makign NSIndexPath display "Sec:x Row:y":

Sec:{(int)[$VAR section]}  Row:{(int)[$VAR row]} 

So you can print descriptive text and multiple values for any object type. The display variables work for all classes of that type, and persist between XCode runs and also across projects.

One last tricky thing to note is that for anything that returns a string, you need to add a ":s" after the "{}" pair like so:

{[myClass description]}:s

If you need to clear a display template, just click the line to edit and erase it all - you go back to the default. So, it's really easy to quickly create temporary formatters for any object that let you see exactly what is of interest.

Kendall Helmstetter Gelner