Skip to content

Commit 85916c7

Browse files
authored
Rollup merge of #98301 - ortem:pretty-printers-nonzero, r=wesleywiser
Add GDB/LLDB pretty-printers for NonZero types Add GDB/LLDB pretty-printers for `NonZero` types. These pretty-printers were originally implemented for IntelliJ Rust by ```@Kobzol``` in intellij-rust/intellij-rust#5270. Part of #29392.
2 parents b9306c2 + 2a26987 commit 85916c7

File tree

8 files changed

+116
-1
lines changed

8 files changed

+116
-1
lines changed

src/etc/gdb_lookup.py

+3
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,7 @@ def lookup(valobj):
8989
if rust_type == RustType.STD_REF_CELL:
9090
return StdRefCellProvider(valobj)
9191

92+
if rust_type == RustType.STD_NONZERO_NUMBER:
93+
return StdNonZeroNumberProvider(valobj)
94+
9295
return None

src/etc/gdb_providers.py

+11
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ def children(self):
231231
yield "borrow", self.borrow
232232

233233

234+
class StdNonZeroNumberProvider:
235+
def __init__(self, valobj):
236+
fields = valobj.type.fields()
237+
assert len(fields) == 1
238+
field = list(fields)[0]
239+
self.value = str(valobj[field.name])
240+
241+
def to_string(self):
242+
return self.value
243+
244+
234245
# Yields children (in a provider's sense of the word) for a BTreeMap.
235246
def children_of_btree_map(map):
236247
# Yields each key/value pair in the node and in any child nodes.

src/etc/lldb_commands

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)C
1515
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)Ref<.+>$" --category Rust
1616
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefMut<.+>$" --category Rust
1717
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefCell<.+>$" --category Rust
18+
type summary add -F lldb_lookup.summary_lookup -e -x -h "^core::num::([a-z_]+::)*NonZero.+$" --category Rust
1819
type category enable Rust

src/etc/lldb_lookup.py

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ def summary_lookup(valobj, dict):
5555
if rust_type == RustType.STD_REF_CELL:
5656
return StdRefSummaryProvider(valobj, dict)
5757

58+
if rust_type == RustType.STD_NONZERO_NUMBER:
59+
return StdNonZeroNumberSummaryProvider(valobj, dict)
60+
5861
return ""
5962

6063

src/etc/lldb_providers.py

+8
Original file line numberDiff line numberDiff line change
@@ -739,3 +739,11 @@ def update(self):
739739
def has_children(self):
740740
# type: () -> bool
741741
return True
742+
743+
744+
def StdNonZeroNumberSummaryProvider(valobj, _dict):
745+
# type: (SBValue, dict) -> str
746+
objtype = valobj.GetType()
747+
field = objtype.GetFieldAtIndex(0)
748+
element = valobj.GetChildMemberWithName(field.name)
749+
return element.GetValue()

src/etc/rust_types.py

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class RustType(object):
3131
STD_REF = "StdRef"
3232
STD_REF_MUT = "StdRefMut"
3333
STD_REF_CELL = "StdRefCell"
34+
STD_NONZERO_NUMBER = "StdNonZeroNumber"
3435

3536

3637
STD_STRING_REGEX = re.compile(r"^(alloc::(\w+::)+)String$")
@@ -49,6 +50,7 @@ class RustType(object):
4950
STD_REF_REGEX = re.compile(r"^(core::(\w+::)+)Ref<.+>$")
5051
STD_REF_MUT_REGEX = re.compile(r"^(core::(\w+::)+)RefMut<.+>$")
5152
STD_REF_CELL_REGEX = re.compile(r"^(core::(\w+::)+)RefCell<.+>$")
53+
STD_NONZERO_NUMBER_REGEX = re.compile(r"^core::num::([a-z_]+::)*NonZero.+$")
5254

5355
TUPLE_ITEM_REGEX = re.compile(r"__\d+$")
5456

@@ -72,6 +74,7 @@ class RustType(object):
7274
RustType.STD_REF_MUT: STD_REF_MUT_REGEX,
7375
RustType.STD_REF_CELL: STD_REF_CELL_REGEX,
7476
RustType.STD_CELL: STD_CELL_REGEX,
77+
RustType.STD_NONZERO_NUMBER: STD_NONZERO_NUMBER_REGEX,
7578
}
7679

7780
def is_tuple_fields(fields):

src/test/debuginfo/numeric-types.rs

+86-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// only-cdb
21
// compile-flags:-g
32

3+
// min-gdb-version: 8.1
4+
45
// Tests the visualizations for `NonZero{I,U}{8,16,32,64,128,size}`, `Wrapping<T>` and
56
// `Atomic{Bool,I8,I16,I32,I64,Isize,U8,U16,U32,U64,Usize}` located in `libcore.natvis`.
67

@@ -153,6 +154,90 @@
153154
// cdb-check:a_usize : 0x400 [Type: core::sync::atomic::AtomicUsize]
154155
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicUsize]
155156

157+
158+
// === GDB TESTS ===================================================================================
159+
160+
// gdb-command:run
161+
162+
// gdb-command:print/d nz_i8
163+
// gdb-check:[...]$1 = 11
164+
165+
// gdb-command:print nz_i16
166+
// gdb-check:[...]$2 = 22
167+
168+
// gdb-command:print nz_i32
169+
// gdb-check:[...]$3 = 33
170+
171+
// gdb-command:print nz_i64
172+
// gdb-check:[...]$4 = 44
173+
174+
// gdb-command:print nz_i128
175+
// gdb-check:[...]$5 = 55
176+
177+
// gdb-command:print nz_isize
178+
// gdb-check:[...]$6 = 66
179+
180+
// gdb-command:print/d nz_u8
181+
// gdb-check:[...]$7 = 77
182+
183+
// gdb-command:print nz_u16
184+
// gdb-check:[...]$8 = 88
185+
186+
// gdb-command:print nz_u32
187+
// gdb-check:[...]$9 = 99
188+
189+
// gdb-command:print nz_u64
190+
// gdb-check:[...]$10 = 100
191+
192+
// gdb-command:print nz_u128
193+
// gdb-check:[...]$11 = 111
194+
195+
// gdb-command:print nz_usize
196+
// gdb-check:[...]$12 = 122
197+
198+
199+
200+
// === LLDB TESTS ==================================================================================
201+
202+
// lldb-command:run
203+
204+
// lldb-command:print/d nz_i8
205+
// lldb-check:[...]$0 = 11 { __0 = 11 }
206+
207+
// lldb-command:print nz_i16
208+
// lldb-check:[...]$1 = 22 { __0 = 22 }
209+
210+
// lldb-command:print nz_i32
211+
// lldb-check:[...]$2 = 33 { __0 = 33 }
212+
213+
// lldb-command:print nz_i64
214+
// lldb-check:[...]$3 = 44 { __0 = 44 }
215+
216+
// lldb-command:print nz_i128
217+
// lldb-check:[...]$4 = 55 { __0 = 55 }
218+
219+
// lldb-command:print nz_isize
220+
// lldb-check:[...]$5 = 66 { __0 = 66 }
221+
222+
// lldb-command:print/d nz_u8
223+
// lldb-check:[...]$6 = 77 { __0 = 77 }
224+
225+
// lldb-command:print nz_u16
226+
// lldb-check:[...]$7 = 88 { __0 = 88 }
227+
228+
// lldb-command:print nz_u32
229+
// lldb-check:[...]$8 = 99 { __0 = 99 }
230+
231+
// lldb-command:print nz_u64
232+
// lldb-check:[...]$9 = 100 { __0 = 100 }
233+
234+
// lldb-command:print nz_u128
235+
// lldb-check:[...]$10 = 111 { __0 = 111 }
236+
237+
// lldb-command:print nz_usize
238+
// lldb-check:[...]$11 = 122 { __0 = 122 }
239+
240+
156241
use std::num::*;
157242
use std::sync::atomic::*;
158243

src/tools/compiletest/src/runtest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,7 @@ impl<'test> TestCx<'test> {
11031103
"^(core::([a-z_]+::)+)Ref<.+>$",
11041104
"^(core::([a-z_]+::)+)RefMut<.+>$",
11051105
"^(core::([a-z_]+::)+)RefCell<.+>$",
1106+
"^core::num::([a-z_]+::)*NonZero.+$",
11061107
];
11071108

11081109
script_str

0 commit comments

Comments
 (0)