使用 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/