28

How do you watch a variable in xcode 4? I'm not sure how to do this.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
lampShade
  • 4,361
  • 8
  • 34
  • 50
  • 2
    possible duplicate of [Where is the expression window in Xcode 4?](http://stackoverflow.com/questions/5632477/where-is-the-expression-window-in-xcode-4) Just enter the variable name as expression. – osgx May 12 '11 at 17:57
  • thanks my question is a dupe. – lampShade May 12 '11 at 18:21
  • same question here http://stackoverflow.com/questions/6500718/does-xcode4-have-a-watch-window – Nabil Sham Nov 05 '12 at 00:33

3 Answers3

13

Right click in the local variables window to see the "Watch Expression" menu command. Type the variable name and the variable will be added.

jbierling
  • 681
  • 6
  • 12
3

"Watch VariableName" is available in debug area. Just right click on a var and select "Watch var".

enter image description here

DareDevil
  • 902
  • 8
  • 21
0

There is 2 ways to watch a variable and break at certain condition.

  1. Edit breakpoints

Control-click a breakpoint indicator to display a command menu and choose Edit Breakpoint to open the breakpoint editor and set conditions, add actions, and so forth, as mentioned in Breakpoints. enter image description here

  1. Use LLDB command line. For example, below command will watch the value of 'I', and break when I==3.

    (lldb) watch set var i Watchpoint created: Watchpoint 1: addr = 0x100001018 size = 4 state = enabled type = w declare @ '/Volumes/data/lldb/svn/ToT/test/functionalities/watchpoint/watchpoint_commands/condition/main.cpp:12' (lldb) watch modify -c 'i==3' (lldb) watch list

This is where you can type LLDB command in Xcode.

enter image description here

Weidian Huang
  • 2,787
  • 2
  • 20
  • 29