简体   繁体   English

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

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

In source code, if I do:在源代码中,如果我这样做:

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

I get output like:我得到 output 喜欢:

MyFile.swift 31 doFoo()

However, from a breakpoint in LLDB, if I do similar:但是,从 LLDB 中的断点开始,如果我执行类似操作:

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

I get:我得到:

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

Is there a way to get output like the former from the latter?有没有办法像前者一样从后者获得 output? I'm aware you can do:我知道你可以这样做:

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

... but that output is pretty messy. ...但是 output 非常混乱。 Is there a way to clean it up to just file, line and function?有没有办法将其清理为文件、行和 function?

You can set a custom format for displaying the frame info.您可以设置自定义格式来显示框架信息。 For what you want, you can do:对于您想要的,您可以执行以下操作:

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

And then try frame info .然后尝试frame info You'd get something like:你会得到类似的东西:

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

You can make this setting permanent by following this answer .您可以按照此答案永久设置此设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM