如何使用 Swift 在 LLDB 中打印等效于 #line #file #function 的内容?

How to print equivalent of #line #file #function in LLDB using Swift?

在源代码中,如果我这样做:

print("\(#file) \(#line) \(#function)")

我得到如下输出:

MyFile.swift 31 doFoo()

但是,从 LLDB 中的断点开始,如果我做类似的事情:

(lldb) po "\(#file) \(#function) \(#line)"

我得到:

"<EXPR> $__lldb_expr(_:) 6"

有没有办法从后者得到前者的输出?我知道你可以这样做:

(lldb) frame info
frame #0: 0x0000000102d92c46 MyApp `closure #2 in Client.fetchCart([=15=]=(error_instance = 0x0000600000810be0 -> 0x0000000108e88cc0 (void *)0x0000000108e88ce8: __SwiftNativeNSError)) at Client+Cart.swift:21:23

...但是输出非常混乱。有没有办法将其清理为文件、行和函数?

您可以set a custom format显示帧信息。想做就做:

settings set frame-format "${line.file.basename} ${line.number} ${function.name-without-args}\n"

然后尝试frame info。你会得到类似的东西:

AppDelegate.swift 11 AppDelegate.application(_:didFinishLaunchingWithOptions:)

您可以按照 .

使此设置永久生效