本文介绍了LLDB“线程返回"命令在Swift函数中发出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读在调试器中跳舞-带有LLDB的华尔兹/a>文章.而且我正在尝试使用Swift 2.2和Swift 3.0的thread return命令.

我的代码非常简单:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let resust = test()
        print(resust)
    }

    func test() -> Bool {
        return true
    }
}

,我在test()函数的开头添加了一个thread return false动作的断点.但是,在command + R之后,我的程序按预期在断点处停止,但是出现以下错误:

and I added a breakpoint at the beginning of the test() function with a thread return false action. However, after command+R, my program stops at the breakpoint as expect, but with the following error:

错误:线程1的第0帧返回错误:我们目前仅支持设置简单的整数和浮点返回类型."

"error: Error returning from frame 0 of thread 1: We only support setting simple integer and float return types at present.."

以下是屏幕截图:

然后,我在Objective-C代码中尝试了相同的方法;一切顺利.

Then I tried the same in Objective-C code; everything goes well.

推荐答案

这些是已知的错误. Swift中的值类型(Int,Bool等)都是复杂的对象,我们还没有教过lldb如何覆盖它们的返回值.错误处理也将使这个棘手.

These are known bugs. The value types in Swift (Int, Bool, etc.) are all complex objects, and we haven't taught lldb how to overwrite the return values for them. Error handling will also make this tricky.

通常,强制返回是不安全的-ARC甚至Swift都更不安全,因为您可能不平衡引用计数-不仅是局部变量,而且还可能是传入的对象.

In general, forced returns are unsafe - more so with ARC and even more so with Swift, since you are likely to unbalance reference counts - not just on locals but potentially on objects passed in.

这篇关于LLDB“线程返回"命令在Swift函数中发出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

查看更多