views:

4294

answers:

5

I'm trying to watch a variable with Xcode. I'm following the instructions in here by pausing at a breakpoint, selecting Run > Variables View > .... but with the exception of "Enable Data Formatters" the rest of the options are all greyed out. Any ideas?

I'm using Xcode Version 3.1.3 if that matters.

+5  A: 

I haven't gotten watchpoints created from the Run menu to work for me either, unfortunately. One thing to be aware of is that when a variable goes out of scope, the watchpoint may become invalid.

If you don't mind getting a little more in-depth, you can use some low-level gbd commands to set a watchpoint for the address of the memory itself. For example, in the guide you linked to, they show how to watch the variable path which is a pointer with the value 0xbfffeb70. To manually set a watchpoint for that address, click in the debugger console (where the debugging output is printed) after the "(gdb)" prompt and type something like this:

watch *((int*)0xbfffeb70)

The cryptic syntax is necessary because gdb expects inputs as C expressions. For a little more detail, visit this link and jump to the section titled "Using hardware watchpoints". (I'm testing on an Intel machine, not sure how PowerPC handles it.) When you set watchpoints this way, Xcode will alert you with a drop-down sheet when a watchpoint is reached and tell you how the value was changed, and gdb will print the same info in the console.

Quinn Taylor
+2  A: 

I just ran into this problem. Here is a solution: right click on the variable name and select "View variable in window" from the menu which appears. It should be near the bottom.

John Smith
A: 

I have the exact same issue. Optimization/debug build, once a breakpoint hits, there's is no obvious way to watch a variable). Hovering the mouse over a variables works most of the time, but sometimes it just doesnt work.

Going to the view variables, all i see is the entire menu options (except top item) greyed out. Man, XCode, and its documentation, sucks.

Anybody else have any other ideas? Maybe i really dont have the optimization turned off? How is that done?

AlvinfromDiaspar
A: 

Click "Run > Show > Expressions...". This will show the Expressions window where you are able to enter a variable to watch in a textbox in the bottom.

Peter Theill
+1  A: 

Sorry but these solutions that involve showing this in a separate window just don't cut it. The whole point of a debugger is that you are supposed to look at the variables in the variables display window and SEE THEIR VALUES. You are not supposed to have to additionally click on every variable you are interested in only to get a small popup-window per variable. How messed up is that?

jjclose