In XCode 6 how can you set a watchpoint without stopping execution?

对着背影说爱祢 提交于 2019-11-30 13:57:31

Well it seems that the only way to achieve this is to use the LLDB command line. So for those of you who, like me, had never used it here is a step-by-step (actually fairly easy) way to use it and watch variables without stopping execution:

  1. Set a breakpoint in Xcode (click to the left of your source line) where the variable you want to watch is used (in scope), and run your code until it reaches the breakpoint.
  2. In the console view (little window displayed at the bottom right where you can display console things) you should see a (lldb) prompt. This is where you enter the following commands:
    w s v stuff (or watchpoint set variable stuff) where stuff is the name of the variable you want to watch
    w c a (or watchpoint command add) to enter a script mode where you enter one command per line as follows after the '>'
    p stuff (or print stuff) to display the new stuff variable value
    c (or continue) to continue execution
    DONE to finish this little script (note the UPPERCASE characters!)

THAT'S IT ! You can remove your breakpoint and continue execution. From then on messages will be displayed in the console every time the variable "stuff" is updated, without stopping the execution of your code (it might slow it down a little of course, but that is usually not important).

Watchpoint is just like a breakpoint which gets hit when the value of a variable which is being watched gets updated. To set it please follow below steps:

1.Set a breakpoint such that the variables view in the debugger shows the variable you want to watch. 2.Right click on the variable and select Watch "variable name". 3.This will stop the execution whenever the value of the variable changes.

The watchpoint will now start showing in the debug navigator. In order to remove it just drag is towards the editor and you are good to go.

PS : this is just a smarter version of implemention didset for a variable and setting and breakpoint inside it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!