Unnamed repository; edit this file 'description' to name the repository.
Merge ref '1be6b13be73d' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: 1be6b13be73dc12e98e51b403add4c41a0b77759 Filtered ref: 53d2132341f509072e83b49d4d82f17465ab164c Upstream diff: https://github.com/rust-lang/rust/compare/6159a44067ebce42b38f062cc7df267a1348e092...1be6b13be73dc12e98e51b403add4c41a0b77759 This merge was created using https://github.com/rust-lang/josh-sync.
The rustc-josh-sync Cronjob Bot 5 months ago
parent 4788e6b · parent 53d2132 · commit 8b2e56b
-rw-r--r--lib/smol_str/src/gdb_smolstr_printer.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/smol_str/src/gdb_smolstr_printer.py b/lib/smol_str/src/gdb_smolstr_printer.py
index 9b2984fc6d..5f28ddd5e6 100644
--- a/lib/smol_str/src/gdb_smolstr_printer.py
+++ b/lib/smol_str/src/gdb_smolstr_printer.py
@@ -25,15 +25,17 @@ import re
SMOL_INLINE_SIZE_RE = re.compile(r".*::_V(\d+)$")
+
def _read_utf8(mem):
try:
return mem.tobytes().decode("utf-8", errors="replace")
except Exception:
return repr(mem.tobytes())
+
def _active_variant(enum_val):
"""Return (variant_name, variant_value) for a Rust enum value using discriminant logic.
- Assume layout: fields[0] is unnamed u8 discriminant; fields[1] is the active variant.
+ Assume layout: fields[0] is unnamed u8 discriminant; fields[1] is the active variant.
"""
fields = enum_val.type.fields()
if len(fields) < 2:
@@ -41,6 +43,7 @@ def _active_variant(enum_val):
variant_field = fields[1]
return variant_field.name, enum_val[variant_field]
+
class SmolStrProvider:
def __init__(self, val):
self.val = val
@@ -86,8 +89,10 @@ class SmolStrProvider:
length = int(inner["length"])
# ArcInner layout:
# strong: Atomic<usize>, weak: Atomic<usize> | unsized tail 'data' bytes.
- sizeof_AtomicUsize = gdb.lookup_type("core::sync::atomic::AtomicUsize").sizeof
- header_size = sizeof_AtomicUsize * 2 # strong + weak counters
+ sizeof_AtomicUsize = gdb.lookup_type(
+ "core::sync::atomic::AtomicUsize"
+ ).sizeof
+ header_size = sizeof_AtomicUsize * 2 # strong + weak counters
data_arr = int(data_ptr) + header_size
mem = gdb.selected_inferior().read_memory(data_arr, length)
return _read_utf8(mem)
@@ -99,6 +104,7 @@ class SmolStrProvider:
def display_hint(self):
return "string"
+
class SmolStrSubPrinter(gdb.printing.SubPrettyPrinter):
def __init__(self):
super(SmolStrSubPrinter, self).__init__("SmolStr")
@@ -114,6 +120,7 @@ class SmolStrSubPrinter(gdb.printing.SubPrettyPrinter):
pass
return None
+
class SmolStrPrettyPrinter(gdb.printing.PrettyPrinter):
def __init__(self):
super(SmolStrPrettyPrinter, self).__init__("smol_str", [])
@@ -129,9 +136,12 @@ class SmolStrPrettyPrinter(gdb.printing.PrettyPrinter):
return pp
return None
+
printer = SmolStrPrettyPrinter()
+
def register_printers(objfile=None):
gdb.printing.register_pretty_printer(objfile, printer, replace=True)
+
register_printers()