Skip to content

Commit

Permalink
Rollup merge of rust-lang#98301 - ortem:pretty-printers-nonzero, r=Ma…
Browse files Browse the repository at this point in the history
…rk-Simulacrum

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 rust-lang#29392.
  • Loading branch information
matthiaskrgr authored Jun 26, 2022
2 parents 436bb62 + 0bc536e commit e629404
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/etc/gdb_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,7 @@ def lookup(valobj):
if rust_type == RustType.STD_REF_CELL:
return StdRefCellProvider(valobj)

if rust_type == RustType.STD_NONZERO_NUMBER:
return StdNonZeroNumberProvider(valobj)

return None
11 changes: 11 additions & 0 deletions src/etc/gdb_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ def children(self):
yield "borrow", self.borrow


class StdNonZeroNumberProvider:
def __init__(self, valobj):
fields = valobj.type.fields()
assert len(fields) == 1
field = list(fields)[0]
self.value = str(valobj[field.name])

def to_string(self):
return self.value


# Yields children (in a provider's sense of the word) for a BTreeMap.
def children_of_btree_map(map):
# Yields each key/value pair in the node and in any child nodes.
Expand Down
1 change: 1 addition & 0 deletions src/etc/lldb_commands
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)C
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)Ref<.+>$" --category Rust
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefMut<.+>$" --category Rust
type summary add -F lldb_lookup.summary_lookup -e -x -h "^(core::([a-z_]+::)+)RefCell<.+>$" --category Rust
type summary add -F lldb_lookup.summary_lookup -e -x -h "^core::num::([a-z_]+::)*NonZero.+$" --category Rust
type category enable Rust
3 changes: 3 additions & 0 deletions src/etc/lldb_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def summary_lookup(valobj, dict):
if rust_type == RustType.STD_REF_CELL:
return StdRefSummaryProvider(valobj, dict)

if rust_type == RustType.STD_NONZERO_NUMBER:
return StdNonZeroNumberSummaryProvider(valobj, dict)

return ""


Expand Down
8 changes: 8 additions & 0 deletions src/etc/lldb_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,3 +739,11 @@ def update(self):
def has_children(self):
# type: () -> bool
return True


def StdNonZeroNumberSummaryProvider(valobj, _dict):
# type: (SBValue, dict) -> str
objtype = valobj.GetType()
field = objtype.GetFieldAtIndex(0)
element = valobj.GetChildMemberWithName(field.name)
return element.GetValue()
3 changes: 3 additions & 0 deletions src/etc/rust_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class RustType(object):
STD_REF = "StdRef"
STD_REF_MUT = "StdRefMut"
STD_REF_CELL = "StdRefCell"
STD_NONZERO_NUMBER = "StdNonZeroNumber"


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

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

Expand All @@ -72,6 +74,7 @@ class RustType(object):
RustType.STD_REF_MUT: STD_REF_MUT_REGEX,
RustType.STD_REF_CELL: STD_REF_CELL_REGEX,
RustType.STD_CELL: STD_CELL_REGEX,
RustType.STD_NONZERO_NUMBER: STD_NONZERO_NUMBER_REGEX,
}

def is_tuple_fields(fields):
Expand Down
85 changes: 84 additions & 1 deletion src/test/debuginfo/numeric-types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// only-cdb
// compile-flags:-g

// Tests the visualizations for `NonZero{I,U}{8,16,32,64,128,size}`, `Wrapping<T>` and
Expand Down Expand Up @@ -153,6 +152,90 @@
// cdb-check:a_usize : 0x400 [Type: core::sync::atomic::AtomicUsize]
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicUsize]


// === GDB TESTS ===================================================================================

// gdb-command:run

// gdb-command:print nz_i8
// gdbg-check:[...]$1 = 11

// gdb-command:print nz_i16
// gdbg-check:[...]$2 = 22

// gdb-command:print nz_i32
// gdbg-check:[...]$3 = 33

// gdb-command:print nz_i64
// gdbg-check:[...]$4 = 44

// gdb-command:print nz_i128
// gdbg-check:[...]$5 = 55

// gdb-command:print nz_isize
// gdbg-check:[...]$6 = 66

// gdb-command:print nz_u8
// gdbg-check:[...]$7 = 77

// gdb-command:print nz_u16
// gdbg-check:[...]$8 = 88

// gdb-command:print nz_u32
// gdbg-check:[...]$9 = 99

// gdb-command:print nz_u64
// gdbg-check:[...]$10 = 100

// gdb-command:print nz_u128
// gdbg-check:[...]$11 = 111

// gdb-command:print nz_usize
// gdbg-check:[...]$12 = 122



// === LLDB TESTS ==================================================================================

// lldb-command:run

// lldb-command:print nz_i8
// lldb-check:[...]$0 = 11

// lldb-command:print nz_i16
// lldb-check:[...]$1 = 22

// lldb-command:print nz_i32
// lldb-check:[...]$2 = 33

// lldb-command:print nz_i64
// lldb-check:[...]$3 = 44

// lldb-command:print nz_i128
// lldb-check:[...]$4 = 55

// lldb-command:print nz_isize
// lldb-check:[...]$5 = 66

// lldb-command:print nz_u8
// lldb-check:[...]$6 = 77

// lldb-command:print nz_u16
// lldb-check:[...]$7 = 88

// lldb-command:print nz_u32
// lldb-check:[...]$8 = 99

// lldb-command:print nz_u64
// lldb-check:[...]$9 = 100

// lldb-command:print nz_u128
// lldb-check:[...]$10 = 111

// lldb-command:print nz_usize
// lldb-check:[...]$11 = 122


use std::num::*;
use std::sync::atomic::*;

Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ impl<'test> TestCx<'test> {
"^(core::([a-z_]+::)+)Ref<.+>$",
"^(core::([a-z_]+::)+)RefMut<.+>$",
"^(core::([a-z_]+::)+)RefCell<.+>$",
"^core::num::([a-z_]+::)*NonZero.+$",
];

script_str
Expand Down

0 comments on commit e629404

Please sign in to comment.