Skip to content

Commit 84c9b70

Browse files
committed
add MSVC tuple providers
1 parent 0cc4f4f commit 84c9b70

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

src/etc/lldb_commands

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ type synthetic add -l lldb_lookup.synthetic_lookup -x "^(core::([a-z_]+::)+)NonZ
1818
type synthetic add -l lldb_lookup.synthetic_lookup -x "^core::num::([a-z_]+::)*NonZero.+$" --category Rust
1919
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(std::([a-z_]+::)+)PathBuf$" --category Rust
2020
type synthetic add -l lldb_lookup.synthetic_lookup -x "^&(mut )?(std::([a-z_]+::)+)Path$" --category Rust
21-
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(.*)$" --category Rust
21+
type synthetic add -l lldb_lookup.MSVCStdSliceSyntheticProvider -x "^ref\$<slice2\$<.+> >" --category Rust
22+
type synthetic add -l lldb_lookup.MSVCTupleSyntheticProvider -x "^tuple\$<.+>$" --category Rust
23+
type summary add -F lldb_lookup.TupleSummaryProvider -e -x -h "^tuple\$<.+>$" --category Rust
24+
type synthetic add -l lldb_lookup.synthetic_lookup -x "^\(.*\)$" --category Rust
2225
type summary add -F _ -e -x -h "^.*$" --category Rust
2326
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)String$" --category Rust
2427
type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?str$" --category Rust
@@ -40,4 +43,5 @@ type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)N
4043
type summary add -F lldb_lookup.summary_lookup -e -x -h "^core::num::([a-z_]+::)*NonZero.+$" --category Rust
4144
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::([a-z_]+::)+)PathBuf$" --category Rust
4245
type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?(std::([a-z_]+::)+)Path$" --category Rust
46+
type summary add -F lldb_lookup.TupleSummaryProvider -e -x -h "^tuple\$<.+>$" --category Rust
4347
type category enable Rust

src/etc/lldb_providers.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,24 @@ def StdPathSummaryProvider(valobj: SBValue, _dict: LLDBOpaque) -> str:
205205
return '"%s"' % data
206206

207207

208+
def sequence_formatter(output: str, valobj: SBValue, _dict: LLDBOpaque):
209+
length: int = valobj.GetNumChildren()
210+
211+
long: bool = False
212+
for i in range(0, length):
213+
if len(output) > 32:
214+
long = True
215+
break
216+
child: SBValue = valobj.GetChildAtIndex(i)
217+
output += f"{child.value}, "
218+
if long:
219+
output = f"(len: {length}) " + output + "..."
220+
else:
221+
output = output[:-2]
222+
223+
return output
224+
225+
208226
class StructSyntheticProvider:
209227
"""Pretty-printer for structs and struct enum variants"""
210228

@@ -348,6 +366,41 @@ def has_children(self) -> bool:
348366
return True
349367

350368

369+
class MSVCTupleSyntheticProvider:
370+
__slots__ = ["valobj"]
371+
372+
def __init__(self, valobj: SBValue, _dict: LLDBOpaque):
373+
self.valobj = valobj
374+
375+
def num_children(self) -> int:
376+
return self.valobj.GetNumChildren()
377+
378+
def get_child_index(self, name: str) -> int:
379+
return self.valobj.GetIndexOfChildWithName(name)
380+
381+
def get_child_at_index(self, index: int) -> SBValue:
382+
child: SBValue = self.valobj.GetChildAtIndex(index)
383+
return child.CreateChildAtOffset(str(index), 0, child.GetType())
384+
385+
def update(self):
386+
pass
387+
388+
def has_children(self) -> bool:
389+
return self.valobj.MightHaveChildren()
390+
391+
def get_type_name(self) -> str:
392+
name = self.valobj.GetTypeName()
393+
# remove "tuple$<" and ">", str.removeprefix and str.removesuffix require python 3.9+
394+
name = name[7:-1]
395+
return "(" + name + ")"
396+
397+
398+
def TupleSummaryProvider(valobj: SBValue, _dict: LLDBOpaque):
399+
output: str = sequence_formatter("(", valobj, dict)
400+
output += ")"
401+
return output
402+
403+
351404
class StdVecSyntheticProvider:
352405
"""Pretty-printer for alloc::vec::Vec<T>
353406

0 commit comments

Comments
 (0)