With LLDB I can add custom summaries for a type, which then gets printed when the p
or frame variable
command is invoked with a value of that type.
(lldb) type summary add -s "This is a Foo" Baz.Foo
However, I am unable to do this for a generic type with two or more generic type parameters.
Given a module Baz with the type Foo
that has two generic type parameters:
struct Foo<Bar: Numeric, Bar2: Numeric> {}
I have tried the following; all without success:
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>
In all cases, the standard description was being printed instead of the custom one for Foo<Float, Float>()
.
So how can I add a custom summary for a generic type with two or more generics, ideally without having to specify concrete types for Bar
and Bar2
?
The only option that I have found that somewhat works is to introduce a typealias FloatFoo = Foo<Float, Float>
and to cast values for printing (p value as FloatFoo
). However, this does not help much, as it does not work with frame variable
and it requires concrete types for Bar
and Bar2
. Also, it would be very annoying to do every time.
Edit (Partial solution):
I can somewhat get it to work by defining a marker protocol
public protocol FooProtocol {}
extension Foo: FooProtocol {}
and then defining the summary for the protocol. However this only works after I cast to FooProtocol
when printing a Foo
value for the first time.
If the cast is not performed on the first time ever printing a Foo
, LLDB will continue to use the default summary, even when casting on subsequent prints.