Skip to content

Commit 0014f57

Browse files
committed
Add lldb visualizers
1 parent 862f286 commit 0014f57

File tree

2 files changed

+226
-21
lines changed

2 files changed

+226
-21
lines changed

src/etc/lldb_commands

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,91 @@
1-
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(alloc::([a-z_]+::)+)String$" --category Rust
1+
# Default
2+
type synthetic add -l lldb_lookup.synthetic_lookup -x ".*" --category Rust
3+
type summary add -F lldb_lookup.summary_lookup -x ".*" --category Rust
4+
# String
5+
type synthetic add -l lldb_lookup.StdStringSyntheticProvider -x "^(alloc::([a-z_]+::)+)String$" --category Rust
6+
type summary add -F lldb_lookup.StdStringSummaryProvider -e -x -h "^(alloc::([a-z_]+::)+)String$" --category Rust
7+
# Ref/Ptr
8+
type synthetic add -l lldb_lookup.PtrSyntheticProvider -x "^(const )?.* \*$" --category Rust
9+
type synthetic add -l lldb_lookup.PtrSyntheticProvider -x "^(const )?.* &$" --category Rust
10+
type summary add -F lldb_lookup.PtrSummaryProvider -e -h -x "^(const )?.* &$" --category Rust
11+
type summary add -F lldb_lookup.PtrSummaryProvider -e -h -x "^(const )?.* \*$" --category Rust
12+
## Nested Ref (must occur before &str)
13+
type synthetic add -l lldb_lookup.NestedRefSyntheticProvider -x "^ref(_mut)?\$<.+>$" --category Rust
14+
type summary add -F lldb_lookup.NestedRefSummaryProvider -x "^ref(_mut)?\$<.+>$" --category Rust
15+
# &str/&mut str
216
type synthetic add -l lldb_lookup.synthetic_lookup -x "^&(mut )?str$" --category Rust
17+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?str$" --category Rust
18+
## MSVC
19+
type synthetic add -l lldb_lookup.MSVCStrSyntheticProvider -x "^ref(_mut)?\$<str\$>$" --category Rust
20+
type summary add -F lldb_lookup.StdStrSummaryProvider -e -h -x "^ref(_mut)?\$<str\$>$" --category Rust
21+
# Array
322
type synthetic add -l lldb_lookup.synthetic_lookup -x "^&(mut )?\\[.+\\]$" --category Rust
23+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?\\[.+\\]$" --category Rust
24+
# Slice
25+
type synthetic add -l lldb_lookup.StdSliceSyntheticProvider -x "^ref(_mut)?\$<\[.+\]>" --category Rust
26+
type summary add -F lldb_lookup.StdSliceSummaryProvider -e -x -h "^ref(_mut)?\$<\[.+\]>" --category Rust
27+
## MSVC
28+
type synthetic add -l lldb_lookup.MSVCStdSliceSyntheticProvider -x "^ref(_mut)?\$<slice2\$<.+> >" --category Rust
29+
type summary add -F lldb_lookup.StdSliceSummaryProvider -e -x -h "^ref(_mut)?\$<slice2\$<.+> >" --category Rust
30+
# OsString
431
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(std::ffi::([a-z_]+::)+)OsString$" --category Rust
32+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::ffi::([a-z_]+::)+)OsString$" --category Rust
33+
# Vec
534
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(alloc::([a-z_]+::)+)Vec<.+>$" --category Rust
35+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Vec<.+>$" --category Rust
36+
# VecDeque
637
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(alloc::([a-z_]+::)+)VecDeque<.+>$" --category Rust
38+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)VecDeque<.+>$" --category Rust
39+
# BTreeSet
740
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(alloc::([a-z_]+::)+)BTreeSet<.+>$" --category Rust
41+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)BTreeSet<.+>$" --category Rust
42+
# BTreeMap
843
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(alloc::([a-z_]+::)+)BTreeMap<.+>$" --category Rust
44+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)BTreeMap<.+>$" --category Rust
45+
# HashMap
946
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(std::collections::([a-z_]+::)+)HashMap<.+>$" --category Rust
47+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::collections::([a-z_]+::)+)HashMap<.+>$" --category Rust
48+
# HashSet
1049
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(std::collections::([a-z_]+::)+)HashSet<.+>$" --category Rust
50+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::collections::([a-z_]+::)+)HashSet<.+>$" --category Rust
51+
# Rc
1152
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(alloc::([a-z_]+::)+)Rc<.+>$" --category Rust
53+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Rc<.+>$" --category Rust
54+
# Arc
1255
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(alloc::([a-z_]+::)+)Arc<.+>$" --category Rust
56+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Arc<.+>$" --category Rust
57+
# Cell
1358
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(core::([a-z_]+::)+)Cell<.+>$" --category Rust
59+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)Cell<.+>$" --category Rust
60+
# RefCell
1461
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(core::([a-z_]+::)+)Ref<.+>$" --category Rust
1562
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(core::([a-z_]+::)+)RefMut<.+>$" --category Rust
1663
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(core::([a-z_]+::)+)RefCell<.+>$" --category Rust
17-
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(core::([a-z_]+::)+)NonZero<.+>$" --category Rust
18-
type synthetic add -l lldb_lookup.synthetic_lookup -x "^core::num::([a-z_]+::)*NonZero.+$" --category Rust
19-
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(std::([a-z_]+::)+)PathBuf$" --category Rust
20-
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
22-
type summary add -F _ -e -x -h "^.*$" --category Rust
23-
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)String$" --category Rust
24-
type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?str$" --category Rust
25-
type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?\\[.+\\]$" --category Rust
26-
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::ffi::([a-z_]+::)+)OsString$" --category Rust
27-
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Vec<.+>$" --category Rust
28-
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)VecDeque<.+>$" --category Rust
29-
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)BTreeSet<.+>$" --category Rust
30-
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)BTreeMap<.+>$" --category Rust
31-
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::collections::([a-z_]+::)+)HashMap<.+>$" --category Rust
32-
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::collections::([a-z_]+::)+)HashSet<.+>$" --category Rust
33-
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Rc<.+>$" --category Rust
34-
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(alloc::([a-z_]+::)+)Arc<.+>$" --category Rust
35-
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)Cell<.+>$" --category Rust
3664
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)Ref<.+>$" --category Rust
3765
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefMut<.+>$" --category Rust
3866
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefCell<.+>$" --category Rust
67+
# NonZero
68+
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(core::([a-z_]+::)+)NonZero<.+>$" --category Rust
69+
type synthetic add -l lldb_lookup.synthetic_lookup -x "^core::num::([a-z_]+::)*NonZero.+$" --category Rust
3970
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)NonZero<.+>$" --category Rust
4071
type summary add -F lldb_lookup.summary_lookup -e -x -h "^core::num::([a-z_]+::)*NonZero.+$" --category Rust
72+
# PathBuf
73+
type synthetic add -l lldb_lookup.synthetic_lookup -x "^(std::([a-z_]+::)+)PathBuf$" --category Rust
4174
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(std::([a-z_]+::)+)PathBuf$" --category Rust
75+
# Path
76+
type synthetic add -l lldb_lookup.synthetic_lookup -x "^&(mut )?(std::([a-z_]+::)+)Path$" --category Rust
4277
type summary add -F lldb_lookup.summary_lookup -e -x -h "^&(mut )?(std::([a-z_]+::)+)Path$" --category Rust
43-
type category enable Rust
78+
# Enum
79+
## MSVC
80+
type synthetic add -l lldb_lookup.MSVCEnumSyntheticProvider -x "^enum2\$<.+>$" --category Rust
81+
type summary add -F lldb_lookup.MSVCEnumSummaryProvider -e -x -h "^enum2\$<.+>$" --category Rust
82+
## MSVC Variants
83+
type synthetic add -l lldb_lookup.synthetic_lookup -x "^enum2\$<.+>::.*$" --category Rust
84+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^enum2\$<.+>::.*$" --category Rust
85+
# Tuple
86+
type synthetic add -l lldb_lookup.synthetic_lookup -x "^\(.*\)$" --category Rust
87+
## MSVC
88+
type synthetic add -l lldb_lookup.MSVCTupleSyntheticProvider -x "^tuple\$<.+>$" --category Rust
89+
type summary add -F lldb_lookup.TupleSummaryProvider -e -x -h "^tuple\$<.+>$" --category Rust
90+
91+
type category enable Rust

src/etc/lldb_providers.py

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from lldb import (
44
SBData,
55
SBError,
6+
SBType,
67
SBValue,
78
eBasicTypeLong,
89
eBasicTypeUnsignedLong,
@@ -838,3 +839,159 @@ def StdNonZeroNumberSummaryProvider(valobj: SBValue, _dict: LLDBOpaque) -> str:
838839
return str(inner_inner.GetValueAsSigned())
839840
else:
840841
return inner_inner.GetValue()
842+
843+
844+
class NestedRefSyntheticProvider:
845+
def __init__(self, valobj: SBValue, _dict: LLDBOpaque):
846+
self.valobj = valobj
847+
848+
def num_children(self) -> int:
849+
return 0
850+
851+
def get_child_index(self, name: str) -> int:
852+
return -1
853+
854+
def get_child_at_index(self, index: int) -> SBValue:
855+
return None
856+
857+
def update(self):
858+
pass
859+
860+
def has_children(self) -> bool:
861+
return False
862+
863+
def get_type_name(self) -> str:
864+
name: str = self.valobj.GetTypeName()
865+
866+
# on MSVC
867+
if name.endswith(" >"):
868+
name = name[:-2]
869+
elif name.endswith(">"):
870+
name = name[:-1]
871+
872+
if name.startswith("ref$<"):
873+
ref_type = "&"
874+
elif name.startswith("ref_mut$<"):
875+
ref_type = "&mut "
876+
877+
ptee: SBValue = (
878+
self.valobj.GetNonSyntheticValue()
879+
.GetChildMemberWithName("ptr")
880+
.Dereference()
881+
)
882+
883+
return ref_type + ptee.GetDisplayTypeName()
884+
885+
886+
def NestedRefSummaryProvider(valobj: SBValue, _dict: LLDBOpaque) -> str:
887+
inner_val: SBValue = valobj
888+
inner_type: SBType = valobj.GetType()
889+
inner_type_name: str = inner_type.GetName()
890+
while inner_type_name.startswith("ref$<") or inner_type_name.startswith(
891+
"ref_mut$<"
892+
):
893+
inner_val = (
894+
inner_val.GetNonSyntheticValue().GetChildMemberWithName("ptr").Dereference()
895+
)
896+
897+
inner_type = inner_val.GetType()
898+
inner_type_name = inner_type.GetName()
899+
900+
summary = inner_val.summary
901+
if summary is None:
902+
summary = inner_val.value
903+
if summary is None:
904+
summary = "{...}"
905+
return summary
906+
907+
908+
class PtrSyntheticProvider:
909+
def __init__(self, valobj: SBValue, _dict: LLDBOpaque):
910+
self.valobj = valobj
911+
912+
def num_children(self) -> int:
913+
return 0
914+
915+
def get_child_index(self, name: str) -> int:
916+
return -1
917+
918+
def get_child_at_index(self, index: int) -> SBValue:
919+
return None
920+
921+
def update(self):
922+
pass
923+
924+
def has_children(self) -> bool:
925+
return False
926+
927+
def get_type_name(self) -> str:
928+
type: SBType = self.valobj.GetType()
929+
name_parts: list[str] = []
930+
931+
ptr_type: SBType = type
932+
ptee_type: SBType = type.GetPointeeType()
933+
ptee_val: SBValue = self.valobj
934+
935+
# if ptee_name.endswith()
936+
while ptr_type.is_pointer or ptr_type.is_reference:
937+
ptee_val: SBValue = ptee_val.Dereference()
938+
# remove the `const` modifier as it indicates the const-ness of any pointer/ref pointing
939+
# *to* it not its own constness
940+
# For example:
941+
# const u8 *const * -> *const *const u8
942+
# u8 *const * -> *const *mut u8
943+
# const u8 ** -> *mut *const u8
944+
# u8 ** -> *mut *mut u8
945+
ptr_name: str = ptr_type.GetName()
946+
if ptr_name.endswith("const"):
947+
ptr_name = ptr_name[:-5]
948+
ptee_name: str = ptee_type.GetName()
949+
950+
is_ref: bool = ptr_name[-1] == "&"
951+
952+
if ptee_type.is_pointer or ptee_type.is_reference:
953+
if ptee_name.endswith("const"):
954+
if is_ref:
955+
name_parts.append("&")
956+
else:
957+
name_parts.append("*const ")
958+
else:
959+
if is_ref:
960+
name_parts.append("&mut ")
961+
else:
962+
name_parts.append("*mut ")
963+
964+
else:
965+
if ptee_name.startswith("const "):
966+
if is_ref:
967+
name_parts.append("&")
968+
else:
969+
name_parts.append("*const ")
970+
else:
971+
if is_ref:
972+
name_parts.append("&mut ")
973+
else:
974+
name_parts.append("*mut ")
975+
976+
ptr_type = ptee_type
977+
ptee_type = ptee_type.GetPointeeType()
978+
979+
inner_name = ptee_val.GetDisplayTypeName()
980+
if inner_name.startswith("const "):
981+
inner_name = inner_name[6:]
982+
name_parts.append(inner_name)
983+
return "".join(name_parts)
984+
985+
986+
def PtrSummaryProvider(valobj: SBValue, dict) -> str:
987+
t: SBType = valobj.GetType()
988+
while t.is_pointer or t.is_reference:
989+
valobj = valobj.Dereference()
990+
t = valobj.GetType()
991+
992+
summary = valobj.summary
993+
if summary is None:
994+
summary = valobj.value
995+
if summary is None:
996+
summary = "{...}"
997+
return summary

0 commit comments

Comments
 (0)