Skip to content

Commit 05d5c23

Browse files
committed
change RustType from string literals to enum
1 parent 1c5a0cf commit 05d5c23

File tree

4 files changed

+131
-124
lines changed

4 files changed

+131
-124
lines changed

src/etc/gdb_lookup.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import re
44

55
from gdb_providers import *
6-
from rust_types import *
6+
from rust_types import RustType, classify_struct, classify_union
77

88

99
_gdb_version_matched = re.search("([0-9]+)\\.([0-9]+)", gdb.VERSION)
@@ -28,7 +28,7 @@ def classify_rust_type(type):
2828
if type_class == gdb.TYPE_CODE_UNION:
2929
return classify_union(type.fields())
3030

31-
return RustType.OTHER
31+
return RustType.Other
3232

3333

3434
def check_enum_discriminant(valobj):
@@ -85,7 +85,7 @@ def __init__(self, name):
8585

8686
def add(self, rust_type, provider):
8787
# Just use the rust_type as the name.
88-
printer = PrintByRustType(rust_type, provider)
88+
printer = PrintByRustType(rust_type.name, provider)
8989
self.type_map[rust_type] = printer
9090
self.subprinters.append(printer)
9191

@@ -99,23 +99,23 @@ def __call__(self, valobj):
9999
printer = RustPrettyPrinter("rust")
100100
# use enum provider only for GDB <7.12
101101
if gdb_version[0] < 7 or (gdb_version[0] == 7 and gdb_version[1] < 12):
102-
printer.add(RustType.ENUM, enum_provider)
103-
printer.add(RustType.STD_STRING, StdStringProvider)
104-
printer.add(RustType.STD_OS_STRING, StdOsStringProvider)
105-
printer.add(RustType.STD_STR, StdStrProvider)
106-
printer.add(RustType.STD_SLICE, StdSliceProvider)
107-
printer.add(RustType.STD_VEC, StdVecProvider)
108-
printer.add(RustType.STD_VEC_DEQUE, StdVecDequeProvider)
109-
printer.add(RustType.STD_BTREE_SET, StdBTreeSetProvider)
110-
printer.add(RustType.STD_BTREE_MAP, StdBTreeMapProvider)
111-
printer.add(RustType.STD_HASH_MAP, hashmap_provider)
112-
printer.add(RustType.STD_HASH_SET, hashset_provider)
113-
printer.add(RustType.STD_RC, StdRcProvider)
114-
printer.add(RustType.STD_ARC, lambda valobj: StdRcProvider(valobj, is_atomic=True))
115-
116-
printer.add(RustType.STD_CELL, StdCellProvider)
117-
printer.add(RustType.STD_REF, StdRefProvider)
118-
printer.add(RustType.STD_REF_MUT, StdRefProvider)
119-
printer.add(RustType.STD_REF_CELL, StdRefCellProvider)
120-
121-
printer.add(RustType.STD_NONZERO_NUMBER, StdNonZeroNumberProvider)
102+
printer.add(RustType.Enum, enum_provider)
103+
printer.add(RustType.StdString, StdStringProvider)
104+
printer.add(RustType.StdOsString, StdOsStringProvider)
105+
printer.add(RustType.StdStr, StdStrProvider)
106+
printer.add(RustType.StdSlice, StdSliceProvider)
107+
printer.add(RustType.StdVec, StdVecProvider)
108+
printer.add(RustType.StdVecDeque, StdVecDequeProvider)
109+
printer.add(RustType.StdBTreeSet, StdBTreeSetProvider)
110+
printer.add(RustType.StdBTreeMap, StdBTreeMapProvider)
111+
printer.add(RustType.StdHashMap, hashmap_provider)
112+
printer.add(RustType.StdHashSet, hashset_provider)
113+
printer.add(RustType.StdRc, StdRcProvider)
114+
printer.add(RustType.StdArc, lambda valobj: StdRcProvider(valobj, is_atomic=True))
115+
116+
printer.add(RustType.StdCell, StdCellProvider)
117+
printer.add(RustType.StdRef, StdRefProvider)
118+
printer.add(RustType.StdRefMut, StdRefProvider)
119+
printer.add(RustType.StdRefCell, StdRefCellProvider)
120+
121+
printer.add(RustType.StdNonZeroNumber, StdNonZeroNumberProvider)

src/etc/lldb_lookup.py

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
from typing import Dict
3+
14
import lldb
25

36
from lldb_providers import *
@@ -9,57 +12,60 @@ def is_hashbrown_hashmap(hash_map: lldb.SBValue) -> bool:
912
return len(hash_map.type.fields) == 1
1013

1114

12-
def classify_rust_type(type: lldb.SBType) -> str:
15+
def classify_rust_type(type: lldb.SBType) -> RustType:
16+
if type.IsPointerType():
17+
type = type.GetPointeeType()
18+
1319
type_class = type.GetTypeClass()
1420
if type_class == lldb.eTypeClassStruct:
1521
return classify_struct(type.name, type.fields)
1622
if type_class == lldb.eTypeClassUnion:
1723
return classify_union(type.fields)
1824

19-
return RustType.OTHER
25+
return RustType.Other
2026

2127

2228
def summary_lookup(valobj: lldb.SBValue, _dict: LLDBOpaque) -> str:
2329
"""Returns the summary provider for the given value"""
2430
rust_type = classify_rust_type(valobj.GetType())
2531

26-
if rust_type == RustType.STD_STRING:
32+
if rust_type == RustType.StdString:
2733
return StdStringSummaryProvider(valobj, _dict)
28-
if rust_type == RustType.STD_OS_STRING:
34+
if rust_type == RustType.StdOsString:
2935
return StdOsStringSummaryProvider(valobj, _dict)
30-
if rust_type == RustType.STD_STR:
36+
if rust_type == RustType.StdStr:
3137
return StdStrSummaryProvider(valobj, _dict)
3238

33-
if rust_type == RustType.STD_VEC:
39+
if rust_type == RustType.StdVec:
3440
return SizeSummaryProvider(valobj, _dict)
35-
if rust_type == RustType.STD_VEC_DEQUE:
41+
if rust_type == RustType.StdVecDeque:
3642
return SizeSummaryProvider(valobj, _dict)
37-
if rust_type == RustType.STD_SLICE:
43+
if rust_type == RustType.StdSlice:
3844
return SizeSummaryProvider(valobj, _dict)
3945

40-
if rust_type == RustType.STD_HASH_MAP:
46+
if rust_type == RustType.StdHashMap:
4147
return SizeSummaryProvider(valobj, _dict)
42-
if rust_type == RustType.STD_HASH_SET:
48+
if rust_type == RustType.StdHashSet:
4349
return SizeSummaryProvider(valobj, _dict)
4450

45-
if rust_type == RustType.STD_RC:
51+
if rust_type == RustType.StdRc:
4652
return StdRcSummaryProvider(valobj, _dict)
47-
if rust_type == RustType.STD_ARC:
53+
if rust_type == RustType.StdArc:
4854
return StdRcSummaryProvider(valobj, _dict)
4955

50-
if rust_type == RustType.STD_REF:
56+
if rust_type == RustType.StdRef:
5157
return StdRefSummaryProvider(valobj, _dict)
52-
if rust_type == RustType.STD_REF_MUT:
58+
if rust_type == RustType.StdRefMut:
5359
return StdRefSummaryProvider(valobj, _dict)
54-
if rust_type == RustType.STD_REF_CELL:
60+
if rust_type == RustType.StdRefCell:
5561
return StdRefSummaryProvider(valobj, _dict)
5662

57-
if rust_type == RustType.STD_NONZERO_NUMBER:
63+
if rust_type == RustType.StdNonZeroNumber:
5864
return StdNonZeroNumberSummaryProvider(valobj, _dict)
5965

60-
if rust_type == RustType.STD_PATHBUF:
66+
if rust_type == RustType.StdPathBuf:
6167
return StdPathBufSummaryProvider(valobj, _dict)
62-
if rust_type == RustType.STD_PATH:
68+
if rust_type == RustType.StdPath:
6369
return StdPathSummaryProvider(valobj, _dict)
6470

6571
return ""
@@ -69,22 +75,22 @@ def synthetic_lookup(valobj: lldb.SBValue, _dict: LLDBOpaque) -> object:
6975
"""Returns the synthetic provider for the given value"""
7076
rust_type = classify_rust_type(valobj.GetType())
7177

72-
if rust_type == RustType.STRUCT:
78+
if rust_type == RustType.Struct:
7379
return StructSyntheticProvider(valobj, _dict)
74-
if rust_type == RustType.STRUCT_VARIANT:
80+
if rust_type == RustType.StructVariant:
7581
return StructSyntheticProvider(valobj, _dict, is_variant=True)
76-
if rust_type == RustType.TUPLE:
82+
if rust_type == RustType.Tuple:
7783
return TupleSyntheticProvider(valobj, _dict)
78-
if rust_type == RustType.TUPLE_VARIANT:
84+
if rust_type == RustType.TupleVariant:
7985
return TupleSyntheticProvider(valobj, _dict, is_variant=True)
80-
if rust_type == RustType.EMPTY:
86+
if rust_type == RustType.Empty:
8187
return EmptySyntheticProvider(valobj, _dict)
82-
if rust_type == RustType.REGULAR_ENUM:
88+
if rust_type == RustType.RegularEnum:
8389
discriminant = valobj.GetChildAtIndex(0).GetChildAtIndex(0).GetValueAsUnsigned()
8490
return synthetic_lookup(valobj.GetChildAtIndex(discriminant), _dict)
85-
if rust_type == RustType.SINGLETON_ENUM:
91+
if rust_type == RustType.SingletonEnum:
8692
return synthetic_lookup(valobj.GetChildAtIndex(0), _dict)
87-
if rust_type == RustType.ENUM:
93+
if rust_type == RustType.Enum:
8894
# this little trick lets us treat `synthetic_lookup` as a "recognizer function" for the enum
8995
# summary providers, reducing the number of lookups we have to do. This is a huge time save
9096
# because there's no way (via type name) to recognize sum-type enums on `*-gnu` targets. The
@@ -106,37 +112,37 @@ def synthetic_lookup(valobj: lldb.SBValue, _dict: LLDBOpaque) -> object:
106112
)
107113

108114
return ClangEncodedEnumProvider(valobj, _dict)
109-
if rust_type == RustType.STD_VEC:
115+
if rust_type == RustType.StdVec:
110116
return StdVecSyntheticProvider(valobj, _dict)
111-
if rust_type == RustType.STD_VEC_DEQUE:
117+
if rust_type == RustType.StdVecDeque:
112118
return StdVecDequeSyntheticProvider(valobj, _dict)
113-
if rust_type == RustType.STD_SLICE or rust_type == RustType.STD_STR:
119+
if rust_type == RustType.StdSlice or rust_type == RustType.StdStr:
114120
return StdSliceSyntheticProvider(valobj, _dict)
115121

116-
if rust_type == RustType.STD_HASH_MAP:
122+
if rust_type == RustType.StdHashMap:
117123
if is_hashbrown_hashmap(valobj):
118124
return StdHashMapSyntheticProvider(valobj, _dict)
119125
else:
120126
return StdOldHashMapSyntheticProvider(valobj, _dict)
121-
if rust_type == RustType.STD_HASH_SET:
127+
if rust_type == RustType.StdHashSet:
122128
hash_map = valobj.GetChildAtIndex(0)
123129
if is_hashbrown_hashmap(hash_map):
124130
return StdHashMapSyntheticProvider(valobj, _dict, show_values=False)
125131
else:
126132
return StdOldHashMapSyntheticProvider(hash_map, _dict, show_values=False)
127133

128-
if rust_type == RustType.STD_RC:
134+
if rust_type == RustType.StdRc:
129135
return StdRcSyntheticProvider(valobj, _dict)
130-
if rust_type == RustType.STD_ARC:
136+
if rust_type == RustType.StdArc:
131137
return StdRcSyntheticProvider(valobj, _dict, is_atomic=True)
132138

133-
if rust_type == RustType.STD_CELL:
139+
if rust_type == RustType.StdCell:
134140
return StdCellSyntheticProvider(valobj, _dict)
135-
if rust_type == RustType.STD_REF:
141+
if rust_type == RustType.StdRef:
136142
return StdRefSyntheticProvider(valobj, _dict)
137-
if rust_type == RustType.STD_REF_MUT:
143+
if rust_type == RustType.StdRefMut:
138144
return StdRefSyntheticProvider(valobj, _dict)
139-
if rust_type == RustType.STD_REF_CELL:
145+
if rust_type == RustType.StdRefCell:
140146
return StdRefSyntheticProvider(valobj, _dict, is_cell=True)
141147

142148
return DefaultSyntheticProvider(valobj, _dict)

src/etc/lldb_providers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def vec_to_string(vec: SBValue) -> str:
249249
)
250250

251251

252-
def StdStringSummaryProvider(valobj, dict):
252+
def StdStringSummaryProvider(valobj: SBValue, dict: LLDBOpaque):
253253
inner_vec = (
254254
valobj.GetNonSyntheticValue()
255255
.GetChildMemberWithName("vec")

0 commit comments

Comments
 (0)