Skip to content

Commit ca62580

Browse files
committed
change RustType from string literals to enum
1 parent 9725c4b commit ca62580

File tree

4 files changed

+128
-124
lines changed

4 files changed

+128
-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: 40 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,7 +12,7 @@ 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:
1316
if type.IsPointerType():
1417
type = type.GetPointeeType()
1518

@@ -19,50 +22,50 @@ def classify_rust_type(type: lldb.SBType) -> str:
1922
if type_class == lldb.eTypeClassUnion:
2023
return classify_union(type.fields)
2124

22-
return RustType.OTHER
25+
return RustType.Other
2326

2427

2528
def summary_lookup(valobj: lldb.SBValue, _dict: LLDBOpaque) -> str:
2629
"""Returns the summary provider for the given value"""
2730
rust_type = classify_rust_type(valobj.GetType())
2831

29-
if rust_type == RustType.STD_STRING:
32+
if rust_type == RustType.StdString:
3033
return StdStringSummaryProvider(valobj, _dict)
31-
if rust_type == RustType.STD_OS_STRING:
34+
if rust_type == RustType.StdOsString:
3235
return StdOsStringSummaryProvider(valobj, _dict)
33-
if rust_type == RustType.STD_STR:
36+
if rust_type == RustType.StdStr:
3437
return StdStrSummaryProvider(valobj, _dict)
3538

36-
if rust_type == RustType.STD_VEC:
39+
if rust_type == RustType.StdVec:
3740
return SizeSummaryProvider(valobj, _dict)
38-
if rust_type == RustType.STD_VEC_DEQUE:
41+
if rust_type == RustType.StdVecDeque:
3942
return SizeSummaryProvider(valobj, _dict)
40-
if rust_type == RustType.STD_SLICE:
43+
if rust_type == RustType.StdSlice:
4144
return SizeSummaryProvider(valobj, _dict)
4245

43-
if rust_type == RustType.STD_HASH_MAP:
46+
if rust_type == RustType.StdHashMap:
4447
return SizeSummaryProvider(valobj, _dict)
45-
if rust_type == RustType.STD_HASH_SET:
48+
if rust_type == RustType.StdHashSet:
4649
return SizeSummaryProvider(valobj, _dict)
4750

48-
if rust_type == RustType.STD_RC:
51+
if rust_type == RustType.StdRc:
4952
return StdRcSummaryProvider(valobj, _dict)
50-
if rust_type == RustType.STD_ARC:
53+
if rust_type == RustType.StdArc:
5154
return StdRcSummaryProvider(valobj, _dict)
5255

53-
if rust_type == RustType.STD_REF:
56+
if rust_type == RustType.StdRef:
5457
return StdRefSummaryProvider(valobj, _dict)
55-
if rust_type == RustType.STD_REF_MUT:
58+
if rust_type == RustType.StdRefMut:
5659
return StdRefSummaryProvider(valobj, _dict)
57-
if rust_type == RustType.STD_REF_CELL:
60+
if rust_type == RustType.StdRefCell:
5861
return StdRefSummaryProvider(valobj, _dict)
5962

60-
if rust_type == RustType.STD_NONZERO_NUMBER:
63+
if rust_type == RustType.StdNonZeroNumber:
6164
return StdNonZeroNumberSummaryProvider(valobj, _dict)
6265

63-
if rust_type == RustType.STD_PATHBUF:
66+
if rust_type == RustType.StdPathBuf:
6467
return StdPathBufSummaryProvider(valobj, _dict)
65-
if rust_type == RustType.STD_PATH:
68+
if rust_type == RustType.StdPath:
6669
return StdPathSummaryProvider(valobj, _dict)
6770

6871
return ""
@@ -72,54 +75,54 @@ def synthetic_lookup(valobj: lldb.SBValue, _dict: LLDBOpaque) -> object:
7275
"""Returns the synthetic provider for the given value"""
7376
rust_type = classify_rust_type(valobj.GetType())
7477

75-
if rust_type == RustType.STRUCT:
78+
if rust_type == RustType.Struct:
7679
return StructSyntheticProvider(valobj, _dict)
77-
if rust_type == RustType.STRUCT_VARIANT:
80+
if rust_type == RustType.StructVariant:
7881
return StructSyntheticProvider(valobj, _dict, is_variant=True)
79-
if rust_type == RustType.TUPLE:
82+
if rust_type == RustType.Tuple:
8083
return TupleSyntheticProvider(valobj, _dict)
81-
if rust_type == RustType.TUPLE_VARIANT:
84+
if rust_type == RustType.TupleVariant:
8285
return TupleSyntheticProvider(valobj, _dict, is_variant=True)
83-
if rust_type == RustType.EMPTY:
86+
if rust_type == RustType.Empty:
8487
return EmptySyntheticProvider(valobj, _dict)
85-
if rust_type == RustType.REGULAR_ENUM:
88+
if rust_type == RustType.RegularEnum:
8689
discriminant = valobj.GetChildAtIndex(0).GetChildAtIndex(0).GetValueAsUnsigned()
8790
return synthetic_lookup(valobj.GetChildAtIndex(discriminant), _dict)
88-
if rust_type == RustType.SINGLETON_ENUM:
91+
if rust_type == RustType.SingletonEnum:
8992
return synthetic_lookup(valobj.GetChildAtIndex(0), _dict)
90-
if rust_type == RustType.ENUM:
93+
if rust_type == RustType.Enum:
9194
return ClangEncodedEnumProvider(valobj, _dict)
92-
if rust_type == RustType.STD_VEC:
95+
if rust_type == RustType.StdVec:
9396
return StdVecSyntheticProvider(valobj, _dict)
94-
if rust_type == RustType.STD_VEC_DEQUE:
97+
if rust_type == RustType.StdVecDeque:
9598
return StdVecDequeSyntheticProvider(valobj, _dict)
96-
if rust_type == RustType.STD_SLICE or rust_type == RustType.STD_STR:
99+
if rust_type == RustType.StdSlice or rust_type == RustType.StdStr:
97100
return StdSliceSyntheticProvider(valobj, _dict)
98101

99-
if rust_type == RustType.STD_HASH_MAP:
102+
if rust_type == RustType.StdHashMap:
100103
if is_hashbrown_hashmap(valobj):
101104
return StdHashMapSyntheticProvider(valobj, _dict)
102105
else:
103106
return StdOldHashMapSyntheticProvider(valobj, _dict)
104-
if rust_type == RustType.STD_HASH_SET:
107+
if rust_type == RustType.StdHashSet:
105108
hash_map = valobj.GetChildAtIndex(0)
106109
if is_hashbrown_hashmap(hash_map):
107110
return StdHashMapSyntheticProvider(valobj, _dict, show_values=False)
108111
else:
109112
return StdOldHashMapSyntheticProvider(hash_map, _dict, show_values=False)
110113

111-
if rust_type == RustType.STD_RC:
114+
if rust_type == RustType.StdRc:
112115
return StdRcSyntheticProvider(valobj, _dict)
113-
if rust_type == RustType.STD_ARC:
116+
if rust_type == RustType.StdArc:
114117
return StdRcSyntheticProvider(valobj, _dict, is_atomic=True)
115118

116-
if rust_type == RustType.STD_CELL:
119+
if rust_type == RustType.StdCell:
117120
return StdCellSyntheticProvider(valobj, _dict)
118-
if rust_type == RustType.STD_REF:
121+
if rust_type == RustType.StdRef:
119122
return StdRefSyntheticProvider(valobj, _dict)
120-
if rust_type == RustType.STD_REF_MUT:
123+
if rust_type == RustType.StdRefMut:
121124
return StdRefSyntheticProvider(valobj, _dict)
122-
if rust_type == RustType.STD_REF_CELL:
125+
if rust_type == RustType.StdRefCell:
123126
return StdRefSyntheticProvider(valobj, _dict, is_cell=True)
124127

125128
return DefaultSyntheticProvider(valobj, _dict)

src/etc/lldb_providers.py

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

179179

180-
def StdStringSummaryProvider(valobj, dict):
180+
def StdStringSummaryProvider(valobj: SBValue, dict: LLDBOpaque):
181181
inner_vec = (
182182
valobj.GetNonSyntheticValue()
183183
.GetChildMemberWithName("vec")

0 commit comments

Comments
 (0)