在 Xcode 中观察表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5779302/
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
Watch Expression in Xcode
提问by user4951
Say I am debugging. Say I need to know what the value of [somevariable count]
说我在调试。说我需要知道 [somevariable count] 的值
How would I do so?
我该怎么做?
回答by ThomasW
If what you want to do is know the value of the expression while program execution is halted, then do something like
如果您想要做的是在程序执行停止时知道表达式的值,那么执行类似的操作
> p (int)[somevariable count]
in the gdb console.
在 gdb 控制台中。
Note:People searching for the term "watch" might be expecting an answer about being able to observe when a value changes. For that question these are some answers that are more appropriate:
注意:搜索术语“观察”的人可能希望得到有关能够观察值何时发生变化的答案。对于这个问题,以下是一些更合适的答案:
回答by Elad Lavi
Put a breakpoint on the relevant code line. When Xcode stops on that line, in the debug area (the bottom of the screen is splitted to two parts, look at the right one, if you don't see the bottom part, shift+cmd+Y, plus sometimes the right side or the left side are hidden and there are small buttons on the right bottom side to show them), you see all of the local and global variables. Right click (or two fingers) that debug area, and you will see a context menu with one of the options "add expression". Type in your expression.
在相关的代码行上放置一个断点。当Xcode停在那条线上时,在调试区(屏幕底部被分成两部分,看右边的,如果你没有看到底部,shift+cmd+Y,有时还有右边或者左侧是隐藏的,右下侧有小按钮来显示它们),你会看到所有的局部和全局变量。右键单击(或两个手指)该调试区域,您将看到一个上下文菜单,其中包含“添加表达式”选项之一。输入您的表达式。
Note: above previous user's comment about the word "watch" is pretty clear to whomever comes from any other IDE but not in Xcode.
注意:对于来自任何其他 IDE 但不在 Xcode 中的任何人来说,以上先前用户对“watch”一词的评论非常清楚。