Watching variables in Xcode
Asked Answered
U

5

19

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.

Useless answered 24/6, 2009 at 19:52 Comment(4)
once you hit a breakpoint you should be able to hover your mouse over a breakpoint and it will show the variables info.Weed
Are you sure you are running a debug build with optimization turned off?Maretz
I tried a debug build instead of release but the problem persists.Useless
@zPesk — Note that "watchpoints" are different from "breakpoints". The former are for monitoring a particular data address, the latter are for stopping at a given code line.Denicedenie
D
19

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.

Denicedenie answered 25/6, 2009 at 5:21 Comment(2)
If you want to watch a member of a C++ method, I found this variant immensely useful: watch -location mTextFormatted. Revealed a nasty bug related to static vs dynamic cast ;)Radioactive
The lldb alternative would be watchpoint set expression -- 0xbfffeb70 or w s e -- 0xbfffeb70 for short.Cant
K
8

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.

Klos answered 2/3, 2010 at 3:28 Comment(0)
P
4

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.

Pauwles answered 29/7, 2015 at 23:20 Comment(1)
it doesn't stop when the expression changesRisk
G
2

The Answers given here only work if you use the gdb compiler. For those of you who are looking for an option to set a watchpoint with the lldb compiler I have bad news:

It's not working jet (XCode 4.3.2 with lldb 3.1) even though the lldb docs say you can.

Check out this Email. The lldb commands compared to the gdbs can be found here

Glamorous answered 8/8, 2012 at 17:15 Comment(1)
wa s e -- <addr> worked for me, e.g.: wa s e -- 0xbfffeb70Baumgardner
R
1

I was trying to figure this out in XCode 5. I finally found a "Variables view" button at the bottom right of the output console. It's the little rectangle that will be gray on the left, white on the right if it's not enabled. I'm not sure if this is in XCode 3, but I expect most people have upgraded anyway.

Recital answered 21/1, 2015 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.