评估LLDB中的Swift表达
我想定义一个快速扩展名,包括方法 /计算的VAR,仅用于LLDB调试目的。这是常规的Swift代码:
extension Collection where Self.Element == Int {
var elementsOver30: [Self.Element]? {
return self.filter { $0 > 30 }
}
}
在纯LLDB中的示例中,如何定义ElementSover30
?我认为表达式
命令是正确使用的工具,但有时我会出现解析错误。
另外,LLDB中的其他Swift符号是否有等效的语法,例如struct
s?
I want to define a Swift extension, including a method / computed var, only for LLDB debugging purposes. Here is the regular Swift code:
extension Collection where Self.Element == Int {
var elementsOver30: [Self.Element]? {
return self.filter { $0 > 30 }
}
}
How can I define elementsOver30
in this example in pure LLDB? I think expression
command is the right tool to use, but I sometimes get parsing errors.
Also, is there an equivalent syntax for other Swift symbols in LLDB, like struct
s?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用LLDB中的SWIFT代码
Working with Swift code in LLDB ????
Most Swift code can be executed as part of LLDB if it's part of the stdlib with the right syntax. The key is to prefix type names with the symbol identifier
$
. I've used$
even for variable names here (new LLDB improvements make this unnecessary) because I prefer to distinguish LLDB definitions.Extensions ????
With improvements to LLDB, you can actually copy-paste the Swift code directly after expression.
I've added an example for your extension with
$
symbols for clarity:Pressing Enter after
expression
prompts a multi-line evaluation where we can input the remaining Swift code.Structs/Class definitions ????
Reading a Swift instance from memory
Sometimes, we need to read Swift code using Objective-C in LLDB. For example, if we have a Swift file with a View Controller:
We can print the dynamic type of the result of a memory address as follows:
View Swift docs ????
Use
type lookup
to read a minified version of the type definitions: