swift - Swift 的 LLDB : Custom type summary for generic type

标签 swift lldb

使用 LLDB,我可以为类型添加自定义摘要:

(lldb) type summary add -s "This is a Foo" Baz.Foo

但是,我无法对具有两个或多个泛型的泛型类型执行此操作。

给定一个类型为 Foo 的模块 Baz具有两个或多个泛型:

struct Foo<Bar: Numeric, Bar2: Numeric> {}

我尝试过以下方法;一切都没有成功:

  • type summary add -s "This is a Foo" Baz.Foo
  • type summary add -s "This is a Foo" Baz.Foo<A, B>
  • type summary add -s "This is a Foo" Baz.Foo<Float, Float>
  • type summary add -s "This is a Foo" Baz.Foo<Bar, Bar2>
  • type summary add -s "This is a Foo" Baz.Foo<Float>

在所有情况下,都会打印标准描述而不是自定义描述。

那么如何为具有两个或多个泛型的泛型类型添加自定义摘要,理想情况下无需为 Bar 指定具体类型和Bar2

最佳答案

使用 --regex/-x 标志来模式匹配 Swift 中的泛型类型或 C++ 中的模板类型。

type summary add -s "This is a Foo" -x "^Baz\.Foo<.+,.+>$"

您可以通过运行type Summary list -l swift来查看许多示例。 Dictionary 的显示方式如下:

^Swift\.Dictionary<.+,.+>$:  (show children) (hide value) (skip references) Swift.Dictionary summary provider

关于swift - Swift 的 LLDB : Custom type summary for generic type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62367278/

相关文章:

ios - 查明用户是否已接受接收推送通知?

swift - estimatedRowHeight API 有时会破坏自定义单元格

c - 在使用 lldb 调试 macOS 应用程序时,是否可以使用观察点观察寄存器的内容以进行更改?

python - 在定义的时间后退出 LLDB session

ios - 如何使用 UIButton 停止特定功能?

ios - 如何使用标识符连接外设/BLE 设备?

ios - Swift Eureka 表单 : how do you limit the number of rows in a multivalued section?

c - 如何查看哪个库拥有 lldb 回溯的符号

Xcode调试器(lldb)从内存地址获取对象描述

c - 在调试器中运行函数/方法