绕过 exc_breakpoint 崩溃以继续执行程序

bypassing exc_breakpoint crash to continue program execution

在测试我的 iOS 应用程序(这是一个锻炼应用程序)时,该应用程序崩溃了 (EXC_BREAKPOINT),因为它试图保存锻炼数据。

崩溃是索引超出范围的问题,数组计数比锻炼秒数少 1。 (我应该从 1 而不是 0 开始秒计数器)

 for i in 0...seconds {
        let data = "\(i),\(dataArray.powerGenY[i-1]),\(dataArray.powerGenYAlt[i-1])\n"
        
        do {
          try data.appendToURL(fileURL: fileURL)
        }
        catch {
          print("Could not write data to file")
        }
      }

无论如何,这个错误让我转向了 LLDB。有什么办法可以使用 LLDB 来绕过这个错误并继续执行吗?

锻炼了一个小时后,我不准备让这次崩溃带走我的数据。由于崩溃让我陷入了 LLDB,我想看看是否有任何方法可以通过跳过/绕过/更改 i 的值来挽救数据,以便程序可以继续执行。

最初我试过

(lldb) po i = 3327
error: <EXPR>:3:1: error: cannot assign to value: 'i' is immutable
i = 3327
^

但它不允许我更改值 (I is immutable)

然后我尝试了 thread jump -l 1 但它出现了一些关于不是在当前函数之外执行代码的错误。

(lldb) th j -l 29
error: CSVExport.swift:29 is outside the current function.

最后,浏览此站点 https://www.inovex.de/blog/lldb-patch-your-code-with-breakpoints/ 并尝试一些操作。有帮助的是线程跳转

thread return

The mentioned disadvantage of thread jump can be avoided by using a different technique to change control flow behaviour. Instead of manipulating the affected lines of code directly the idea is to manipulate other parts of the program which in turn results in the desired behaviour. For the given example this means changing the return value of can_pass() from 0 to 1. Which, of course, can be done through LLDB. The command to use is thread just like before, but this time with the subcommand return to prematurely return from a stack frame, thereby short-circuiting its execution.

执行 thread return 1 成功了。这返回 true (1) 到索引超出范围问题,然后继续执行到下一行代码。