Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watching variables in Xcode

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.

like image 895
Stu Avatar asked Jun 24 '09 19:06

Stu


People also ask

How do I see variables in Xcode?

See variable values in code and the variable viewer When your app pauses at a breakpoint, hover over a variable in your source code to view its current value. If the variable is an image or other type that isn't expressible as text, click the Quick Look button at the upper-right to see a preview of the variable.

How do you view the value of a variable?

Hover over a variable to see its value. The most commonly used way to look at variables is the DataTip. When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable.

How do I trace in Xcode?

Use the bt command in (lldb). Once paused or after a crash, just type bt into the debug console. It will print the full stack trace. Awesome tip for tracking down a constraint issue after setting the symbolic breakpoint.

What are watch variables?

Any item of data within a program that a programmer wants to observe when debugging. Watch variables may be viewed while the program runs on its own, is stepped through instruction by instruction or when the program crashes. Setting watch variables is part of the debugging operation in a compiler.


3 Answers

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

like image 163
Quinn Taylor Avatar answered Oct 23 '22 21:10

Quinn Taylor


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.

like image 38
John Smith Avatar answered Oct 23 '22 21:10

John Smith


Add a breakpoint. Right click in the watch list of the debug area and choose "Add expression..."

enter image description here

If you are getting a different menu, you have to click off of the currently highlighted variable so that nothing is highlighted when you right click.

like image 4
Suragch Avatar answered Oct 23 '22 21:10

Suragch