Skip to content

Commit e8c5e09

Browse files
committed
doc comment for get_template_args
1 parent 2be8812 commit e8c5e09

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/etc/lldb_providers.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,18 @@ def has_children(self) -> bool:
131131
return False
132132

133133

134-
def get_template_args(type_name: str) -> List[str]:
134+
def get_template_args(type_name: str) -> list[str]:
135+
"""
136+
Takes a type name `T<A, tuple$<B, C>, D>` and returns a list of its generic args
137+
`["A", "tuple$<B, C>", "D"]`.
138+
139+
String-based replacement for LLDB's `SBType.template_args`, as LLDB is currently unable to
140+
populate this field for targets with PDB debug info. Also useful for manually altering the type
141+
name of generics (e.g. `Vec<ref$<str$>` -> `Vec<&str>`).
142+
143+
Each element of the returned list can be looked up for its `SBType` value via
144+
`SBTarget.FindFirstType()`
145+
"""
135146
params = []
136147
level = 0
137148
start = 0
@@ -801,17 +812,7 @@ def update(self):
801812
self.element_type = self.valobj.GetType().GetTemplateArgumentType(0)
802813

803814
if not self.element_type.IsValid():
804-
# annoyingly, vec's constituent type isn't guaranteed to be contained anywhere useful.
805-
# Some functions have it, but those functions only exist in binary when they're used.
806-
# that means it's time for string-based garbage.
807-
808-
# acquire the first generic parameter via its type name
809-
_, _, end = self.valobj.GetTypeName().partition("<")
810-
element_name, _, _ = end.partition(",")
811-
812-
# this works even for built-in rust types like `u32` because internally it's just a
813-
# `typedef` i really REALLY wish there was a better way to do this, but at the moment
814-
# LLDB flat out ignores template parameters due to piggybacking off of TypeSystemClang.
815+
element_name = get_template_args(self.valobj.GetTypeName())[0]
815816
self.element_type = self.valobj.target.FindFirstType(element_name)
816817

817818
self.element_type_size = self.element_type.GetByteSize()

0 commit comments

Comments
 (0)