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.

4
  • 1
    once you hit a breakpoint you should be able to hover your mouse over a breakpoint and it will show the variables info. Commented Jun 24, 2009 at 20:03
  • Are you sure you are running a debug build with optimization turned off? Commented Jun 24, 2009 at 20:18
  • I tried a debug build instead of release but the problem persists. Commented Jun 24, 2009 at 20:29
  • 2
    @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. Commented Jun 25, 2009 at 5:18

5 Answers 5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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 ;)
The lldb alternative would be watchpoint set expression -- 0xbfffeb70 or w s e -- 0xbfffeb70 for short.
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.

Comments

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.

1 Comment

it doesn't stop when the expression changes
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

1 Comment

wa s e -- <addr> worked for me, e.g.: wa s e -- 0xbfffeb70
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.