Why don't Xcode View "Edit Value" variables change the value of the variable?

In the Xcode Variables view to the right of the debug area, when the application is running and paused at a breakpoint, you can right-click the variable and select Change Value.

For the swift line, it is out of order and I can imagine why that might be the case. But even for a simple int, it calls the edit box to enter a new value, but after reaching the value, the same value remains. This is true even for var, which changes during code.

Update: As shown in Jim below, you can set the value using the lldb expression command, but although Xcode will tell you that it has changed, it cannot actually change the value.

Is it broken, or is there something specific you need to do to make it work? Thank.

Screenshot

Update: This is a compilation error - 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)")

      

+3


source to share


2 answers


Most Swift objects are, of course, strings, but even "simple" types like Int are not really simple types. The values ​​you see in the variable view are generated by the data formatters in lldb, which are tuned to present a useful view of the values ​​without using any code (for performance reasons). They know how to collect and retrieve the contents of Swift types, but we didn't teach them how to edit values, only represent them.

If you want to change the value, you need to run some code in your program, which you can do using expression

the lldb command in the console. For example, if you have an Int variable named foo

, you can do:

(lldb) expr foo = 12



This will compile and execute this piece of code, and of course the Swift compiler knows how to change these Swift values, so the resulting code will set the value correctly.

Note, it looks like the fast compiler sometimes copies a value into a register and uses it out of register without specifying that fact in the debug info. If this happens, lldb will report the value set at the location pointed to by the debug information, but the code will actually use the temporary value. I've filed a bug with a fast compiler demonstrating one instance of this.

+10


source


In the case of constant integers, you cannot directly set anything.

However, let's say that you have a variable passed as a parameter to your function:

value = (AnyObject!) Int64(38) instance_type = (Builtin.RawPointer) 0xb000000000000263

Please note that this address starting at 1 is not a real pointer. Now suppose you want to replace 38 with 64. You enter:



po Unmanaged.passUnretained(64).toOpaque()

and you have the magic constant 64 pseudo-address:

0xb000000000000403 - _rawValue : (Opaque Value)

then you replace 0xb000000000000263 with 0xb000000000000403 and you changed your constant.

God I love Swift

+1


source







All Articles