objective-c 在 Xcode 中查看变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1040585/
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
Watching variables in Xcode
提问by Stu
I'm trying to watch a variable with Xcode. I'm following the instructions in hereby pausing at a breakpoint, selecting Run > Variables View > .... but with the exception of "Enable Data Formatters" the rest of the options are all greyed out. Any ideas?
我正在尝试使用 Xcode 观察变量。我按照此处的说明进行操作,在断点处暂停,选择运行 > 变量视图 > .... 但除了“启用数据格式化程序”之外,其余选项都显示为灰色。有任何想法吗?
I'm using Xcode version 3.1.3.
我使用的是 Xcode 3.1.3 版。
回答by Quinn Taylor
I haven't gotten watchpoints created from the Run menu to work for me either, unfortunately. One thing to be aware of is that when a variable goes out of scope, the watchpoint may become invalid.
不幸的是,我也没有从“运行”菜单中创建观察点来对我来说有效。需要注意的一件事是,当变量超出范围时,观察点可能会变得无效。
If you don't mind getting a little more in-depth, you can use some low-level gdbcommands to set a watchpoint for the address of the memory itself. For example, in the guide you linked to, they show how to watch the variable pathwhich is a pointer with the value 0xbfffeb70. To manually set a watchpoint for that address, click in the debugger console (where the debugging output is printed) after the "(gdb)" prompt and type something like this:
如果你不介意更深入一点,你可以使用一些低级gdb命令来为内存本身的地址设置一个观察点。例如,在您链接的指南中,它们展示了如何观察变量path,它是一个值为 的指针0xbfffeb70。要手动为该地址设置观察点,请在“(gdb)”提示后单击调试器控制台(打印调试输出的位置)并键入如下内容:
watch *((int*)0xbfffeb70)
The cryptic syntax is necessary because gdb expects inputs as C expressions. For a little more detail, visit this linkand jump to the section titled "Using hardware watchpoints". (I'm testing on an Intel machine, not sure how PowerPC handles it.) When you set watchpoints this way, Xcode will alert you with a drop-down sheet when a watchpoint is reached and tell you how the value was changed, and gdb will print the same info in the console.
神秘的语法是必要的,因为 gdb 期望输入为 C 表达式。有关更多详细信息,请访问此链接并跳转到标题为“使用硬件观察点”的部分。(我正在 Intel 机器上进行测试,不确定 PowerPC 如何处理它。)当您以这种方式设置观察点时,Xcode 会在到达观察点时通过下拉表提醒您,并告诉您该值是如何更改的,并且gdb 将在控制台中打印相同的信息。
回答by John Smith
I just ran into this problem. Here is a solution: right click on the variable name and select "View variable in window" from the menu which appears. It should be near the bottom.
我刚刚遇到了这个问题。这是一个解决方案:右键单击变量名称,然后从出现的菜单中选择“在窗口中查看变量”。它应该靠近底部。
回答by Suragch
Add a breakpoint. Right click in the watch list of the debug area and choose "Add expression..."
添加断点。在调试区的监视列表中右键单击,然后选择“添加表达式...”
If you are getting a different menu, you have to click off of the currently highlighted variable so that nothing is highlighted when you right click.
如果您获得不同的菜单,则必须单击当前突出显示的变量,以便右键单击时不会突出显示任何内容。
回答by d.ennis
The Answers given here only work if you use the gdbcompiler. For those of you who are looking for an option to set a watchpoint with the lldbcompiler I have bad news:
此处给出的答案仅在您使用gdb编译器时才有效。对于那些正在寻找使用lldb编译器设置观察点的选项的人,我有一个坏消息:
It's not working jet (XCode 4.3.2 with lldb 3.1) even though the lldbdocs say you can.
即使lldb文档说你可以,它也不能工作 jet(XCode 4.3.2 和 lldb 3.1)。
Check out thisEmail. The lldbcommands compared to the gdbs can be found here
回答by galactikuh
I was trying to figure this out in XCode 5. I finally found a "Variables view" button at the bottom right of the output console. It's the little rectangle that will be gray on the left, white on the right if it's not enabled. I'm not sure if this is in XCode 3, but I expect most people have upgraded anyway.
我试图在 XCode 5 中解决这个问题。我终于在输出控制台的右下角找到了一个“变量视图”按钮。如果未启用,则左侧为灰色的小矩形,右侧为白色。我不确定这是否在 XCode 3 中,但我希望大多数人无论如何都升级了。


