swift - 更改 LLDB 中的 Int 变量值

标签 swift stack lldb xcode11

环境: Xcode 11.3.1/Swift 5

这是函数:

func lldbTest() {
    var switchInt = 1

    ...// do something and set a break point here

    if switchInt == 1 {
        print("switchInt == 1")
    } else if switchInt == 2 {
        print("switchInt == 2")
    }
}

我在进入 if 语句之前进行调试,我在 lldb 中将 switchInt 更改为 2
e switchInt = 2
p switchInt
(Int) $R4 = 2

但它仍然打印“switchInt == 1”
result

最佳答案

我猜这种行为是因为编译器已经评估了 if 语句“if switchInt == 1”,因为在该行之前没有更改 switchInt 值的代码。我尝试了以下操作,并能够获得所需的行为。

var switchInt = 1

for i in 0..<10 {
    switchInt = 0
}

if switchInt == 1 {  -> Put a break point here and use (lldb) e switchInt=2
    print("switchInt == 1")
} else if switchInt == 2 {
    print("switchInt == 2")
}

现在执行命令 p switchInt,它的值为 2。通过断点,它将打印 switchInt == 2。

关于swift - 更改 LLDB 中的 Int 变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60666635/

相关文章:

swift - 为什么我的 Swift 循环失败并出现错误 "Can' t form range with end < start”?

ios - 快速迭代字符长度

ios - AppsFlyer iOS 编译错误 : "AppsFlyerTracker.shared().delegate = self" fails

c - 程序不等待用户在 while(1) 循环内接受用户输入

xcode - 如何在 Xcode 中使用 LLDB 打印时间戳?

swift - 保存核心数据时应用挂起

C++为什么创建新节点以删除堆栈上的节点错误

assembly - ARM中的SP(栈)和LR是什么?

iphone - po 对象导致错误 : cannot find interface declaration for '$__lldb_objc_class'

c++ - 如何在 lldb 命令行中调用 C++ 对象的公共(public)函数?