为什么Xcode的变量视图的“编辑值”不改变变量值? [英] Why is Xcode's Variables View's "Edit Value" not changing the variable value?

查看:165
本文介绍了为什么Xcode的变量视图的“编辑值”不改变变量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xcode的变量视图中,在调试区域的右侧,当应用程序在断点处运行并暂停时,您可以右键单击变量并选择编辑值。

In Xcode's Variables View, on the right of the Debug area, when an app is running and paused at a breakpoint you can right-click a variable and select "Edit Value".

对于一个swift字符串,它是灰色的,我可以想象为什么会是这种情况。但是即使是一个简单的int,它会打开一个编辑框来输入一个新的值,但是在该值保持为旧值之后。即使在代码中更改的var也是如此。

For a swift String it's greyed out, and I can imagine why that might be the case. But even for a simple int, it brings up an edit box to enter an new value, but after hitting the value stays at the old value. This is true even for a var which is changed during the code.

更新:如下面Jim所示,应该可以使用lldb表达式设置值命令,但是,虽然Xcode会告诉你它已经改变了,但实际上并没有改变它的价值。

Update: as shown in Jim's answer below, you should be able to set the value using the lldb expression command, but, although Xcode will tell you it has changed, it fails to actually change the value.

这是破碎的,还是有什么具体的你需要做的它上班吗谢谢。

Is this broken, or is there something specific you need to do for it to work? Thanks.

更新:这是一个编译错误 - 请参阅 Jim的评论。这是一个解决方法...

Update: It's a compile bug - see Jim's comment. Here's a workaround...

    println("Before lldb change, foo is \(foo)")
    //make compiler think foo may change, so I can change it myself at the console
    if count("abcd") == 0 { foo = 0 }
    println("After lldb change, code now thinks foo is \(foo)")


推荐答案

Swift实体,确实是字符串,但即使是简单类型,如Int的,实际上不是简单的类型。您在变量视图中看到的值由lldb中的数据格式化程序构建,它们设置为在不运行任何代码的情况下呈现一个有用的值视图(出于性能原因)。获取Swift类型的内容,但是我们没有教他们如何编辑值,只提供它们。

Most Swift entities, for sure strings but even "simple" types like Int's, are actually not simple types. The values you see in the Variables View are constructed by data formatters in lldb that are set up to present a useful view of the Values without running any code (for performance reasons.) They know how grub around & fetch the contents of Swift types, but we didn't teach them how to edit values, only present them.

如果要更改值,则需要运行您的程序中的一些代码可以执行,您可以使用lldb控制台中的表达式命令。因此,例如,如果您有一个名为 foo 的I​​nt变量,您可以执行以下操作:

If you want to change a value, you need to run some code in your program to do that, which you can do using the expression command in the lldb console. So for instance if you have an Int variable called foo, you can do:

(lldb)expr foo = 12

(lldb) expr foo = 12

这将编译&执行该代码片段,当然Swift编译器也知道如何更改这些Swift值,所以最终的代码将正确设置值。

That will compile & execute that code fragment, and of course the Swift compiler does know how to alter these Swift values, so the resultant code will correctly set the value.

请注意,它会出现swift编译器有时会将值复制到寄存器,并从寄存器w / o中使用它来指示调试信息中的事实。如果发生这种情况,lldb将在调试信息指向的位置报告它设置的值,但代码实际上将使用临时值。我已经提交了一个错误,快速编译器演示了一个例子。

Note, it does appear that the swift compiler will sometimes copy a value to a register and use it from the register w/o indicating that fact in the debug info. If that happens, lldb will report the value it set in the location the debug information pointed to, but the code will actually use the temporary value. I've filed a bug with the swift compiler demonstrating one instance of this.

这篇关于为什么Xcode的变量视图的“编辑值”不改变变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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