在 XCode 6 中,如何在不停止执行的情况下设置观察点?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28581844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In XCode 6 how can you set a watchpoint without stopping execution?
提问by DrMad
You can easily set a watchpoint in XCode by following these steps (btw if there is a simpler way, I'd like to know it...):
- Run your program
- Set a breakpoint in the code where your variable is used
- when reaching breakpoint, use a right click on the variable and select 'Watch "nameOfTheVariable"'
- Continue execution.
The only problem is that execution will stop every time the variable value changes. I would like XCode to continue the execution without stopping, i.e. merely display the value changes in the console output.
This feature seems available in command line mode, and although I initially wanted to avoid it, I posted a solution using that mode (see below), as it seems to be the only way to do what I want, i.e. continue execution while displaying variable changes.
您可以按照以下步骤轻松地在 XCode 中设置观察点(顺便说一句,如果有更简单的方法,我想知道......):
- 运行您的程序
- 在使用变量的代码中设置断点
-到达断点时,右键单击变量并选择“观察“nameOfTheVariable””
- 继续执行。
唯一的问题是每次变量值改变时执行都会停止。我希望 XCode 继续执行而不停止,即仅在控制台输出中显示值更改。
此功能在命令行模式下似乎可用,虽然我最初想避免它,但我使用该模式发布了一个解决方案(见下文),因为它似乎是做我想做的唯一方法,即在显示变量时继续执行变化。
回答by DrMad
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:
好吧,似乎实现这一目标的唯一方法是使用 LLDB 命令行。因此,对于像我这样从未使用过它的人来说,这里有一个分步(实际上相当简单)的方法来使用它并在不停止执行的情况下观察变量:
- 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.
- 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
(orwatchpoint set variable stuff
) where stuff is the name of the variable you want to watchw c a
(orwatchpoint command add
) to enter a script mode where you enter one command per line as follows after the '>'p stuff
(orprint stuff
) to display the new stuff variable valuec
(orcontinue
) to continue executionDONE
to finish this little script (note the UPPERCASE characters!)
- 在 Xcode 中设置一个断点(单击源代码行的左侧),在该处(在范围内)使用您要监视的变量,然后运行您的代码,直到它到达断点。
- 在控制台视图(右下角显示的小窗口,您可以在其中显示控制台内容)中,您应该看到(lldb)提示。您可以在此处输入以下命令:(
w s v stuff
或watchpoint set variable stuff
)其中 stuff 是您要监视的变量的名称w c a
(或watchpoint command add
)以进入脚本模式,在该模式下,您可以在“>”p stuff
(或print stuff
)之后每行输入一个命令,如下所示显示新的变量值c
(或continue
)以继续执行DONE
以完成这个小脚本(注意大写字符!)
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).
就是这样 !您可以删除断点并继续执行。从那时起,每次更新变量“stuff”时都会在控制台中显示消息,而不会停止代码的执行(当然它可能会减慢速度,但这通常并不重要)。
回答by Pranav Gupta
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.
1.设置断点,使调试器中的变量视图显示您要查看的变量。2.右击变量并选择Watch“变量名”。3.这将在变量值发生变化时停止执行。
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.
PS:这只是一个更智能的实现didset 版本,用于变量和其中的设置和断点。