在XCode 6中,如何在不停止执行的情况下设置观察点? [英] In XCode 6 how can you set a watchpoint without stopping execution?

查看:142
本文介绍了在XCode 6中,如何在不停止执行的情况下设置观察点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以按照以下步骤轻松地在XCode中设置观察点(顺便说一句,如果有更简单的方法,我想知道...):
-运行程序
-在使用变量的代码中设置一个断点
-到达断点时,右键单击该变量,然后选择监视"nameOfTheVariable""
-继续执行.

唯一的问题是,每次变量值更改时,执行都会停止.我希望XCode继续执行而不停止,即仅在控制台输出中显示值更改.
此功能似乎在命令行模式下可用,尽管我最初想避免使用它,但我发布了使用该模式的解决方案(请参见下文),因为这似乎是执行我想要的唯一方法,即在显示变量的同时继续执行变化.

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.

推荐答案

看来,实现此目标的唯一方法是使用LLDB命令行.因此,对于像我这样从未在这里使用过的人来说,这是一种逐步使用(实际上相当简单)的方法,可以在不停止执行的情况下使用它并监视变量:

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. 在Xcode(在源代码行的左侧)中设置一个断点(在作用域中),该断点用于监视要使用的变量(在范围内),然后运行代码,直到断点为止.
  2. 在控制台视图(显示在右下角的小窗口中,您可以在其中显示控制台内容),您应该看到一个(lldb)提示.在这里输入以下命令:
    w s v stuff (或 watchpoint set variable stuff ),其中stuff是要监视的变量的名称
    w c a (或 watchpoint command add )进入脚本模式,在该模式下,您在>"
    之后每行输入一个命令,如下所示: p stuff (或 print stuff )以显示新的填充变量值
    c (或 continue )以继续执行
    DONE 完成这个小脚本(注意大写字母!)
  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!)

就是这样!您可以删除断点并继续执行.从此以后,每次更新变量"stuff"时,都会在控制台中显示消息,而不会停止执行代码(这当然会使其速度降低一点,但这通常并不重要).

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).

这篇关于在XCode 6中,如何在不停止执行的情况下设置观察点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆