XCode 4 - 在调试期间观察自定义变量的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7037345/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:43:25  来源:igfitidea点击:

XCode 4 - watching values of custom variable during debug

iphoneobjective-ciosxcodemacos

提问by Daniel Nguyen

I am new to xcode and I just have a quick question. In Visual Studio and Eclipse, I can add custom variables to a windows and watch its values during a debug session. I am looking for the same feature in Xcode 4, but I cannot find it. If it is possible in Xcode, could you please provide instruction so that I can do what I wish to do. If this is not possible, please let me know.

我是 xcode 的新手,我只是有一个简单的问题。在 Visual Studio 和 Eclipse 中,我可以将自定义变量添加到 Windows 并在调试会话期间观察其值。我正在 Xcode 4 中寻找相同的功能,但我找不到它。如果可以在 Xcode 中使用,请提供说明以便我可以做我想做的事情。如果这是不可能的,请告诉我。

I am only able to find the window for variables that are "local", or "auto", or "all".

我只能找到“本地”、“自动”或“全部”变量的窗口。

Thanks in advance.

提前致谢。

回答by Nathanial Woolls

Right click in that same window (that has the toggles for Local, Auto, All) and click Add Expression. Type in the full expression and click Done. The new watch expression should show when debugging in the window in the lower left with an E next to it.

在同一个窗口(具有本地、自动、全部切换)中单击鼠标右键,然后单击添加表达式。输入完整的表达式并单击完成。在左下角的窗口中调试时应该显示新的监视表达式,旁边有一个 E。

回答by davbryn

Also, if you don't want to mess about with the IDE too much you can use gdb for this.

此外,如果您不想过多地使用 IDE,您可以为此使用 gdb。

Click in the output window of the debugger and type po variable_nameand it will print out the value of that variable at that time.

在调试器的输出窗口中单击并键入po variable_name,它将打印出当时该变量的值。

e.g

例如

(gdb) po mArray

(gdb) po mArray

(gdb) __NSArrayobject1, object2... etc`

(gdb) __NSArrayobject1, object2 ...等`

You can also use print variable_nameto get the value of a variable.

您还可以使用print variable_name来获取变量的值。

回答by alloc_iNit

To print the variable in console,

要在控制台中打印变量,

    NSString *str1 = @"First String";
    NSLog(@"%@", str1);
    int counter = 7;
    NSLog(@"%i", counter);

And you want to see with out printing,

你想看到不打印,

  1. Put breakpoint at desired position and as its break the running application, take pointer to the variable and it will show you an one lined popup with gray colored arrow.
  2. As you point to that gray colored arrow, two tiny arrows with up-down indication will show.
  3. As you tap on those arrows, a pop will come and choose first option, "Print Description"and it will show you the value of desired variable.
  1. 将断点放在所需的位置,当它中断正在运行的应用程序时,将指针指向变量,它会显示一个带有灰色箭头的单行弹出窗口。
  2. 当您指向那个灰色箭头时,将显示两个带有上下指示的小箭头。
  3. 当您点击这些箭头时,会弹出一个弹出窗口并选择第一个选项“打印说明”,它会显示所需变量的值。