覆盖只读变量 lldb swift

Override readonly variable lldb swift

lldb 中是否有覆盖只读变量的方法。

例如,如果你有一个结构

struct Object {
    let name: String
}

使用 lldb

在 Xcode 的断点处执行以下操作
(lldb) expression object.name = "Tom"

将导致

error: <EXPR>:2:19: error: cannot assign to property: 'name' is a get-only property

我完全理解为什么会这样,只是想知道在调试过程中是否有简单的方法来解决这个问题?

请注意这是 Swift & NOT Objective-C

您可以使用memory write {address} lldb 命令覆盖内存并更改字符串值。我设法一次完成一个地址,但似乎 memory write 能够一次完成。

(lldb) help memory write
     Write to the memory of the process being debugged.

Syntax: memory write <cmd-options> <address> <value> [<value> [...]]

Command Options Usage:
  memory write [-f <format>] [-s <byte-size>] <address> <value> [<value> [...]]
  memory write -i <filename> [-s <byte-size>] [-o <offset>] <address> <value> [<value> [...]]

       -f <format> ( --format <format> )
            Specify a format to be used for display.

       -i <filename> ( --infile <filename> )
            Write memory using the contents of a file.

       -o <offset> ( --offset <offset> )
            Start writing bytes from an offset within the input file.

       -s <byte-size> ( --size <byte-size> )
            The size in bytes to use when displaying with the selected format.

     This command takes options and free-form arguments.  If your arguments
     resemble option specifiers (i.e., they start with a - or --), you must use
     ' -- ' between the end of the command options and the beginning of the
     arguments.

举个例子(希望对lldb和Swift内部有更多了解的人可以提供更好的方法):

这表明一次一个字节地覆盖内存。 po "Tom".dataUsingEncoding(NSUTF8StringEncoding)!获取十六进制表示,用于单步遍历和覆盖object.name的内存。我确信有一种更简单的方法(在一个命令中),但我无法找出正确的参数值来实现它。