Swift 的 LLDB:通用类型的自定义类型摘要
LLDB for Swift: Custom type summary for generic type
使用 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
使用 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