Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | lib/smol_str/src/gdb_smolstr_printer.py | 16 | ||||
| -rw-r--r-- | rust-version | 2 |
2 files changed, 14 insertions, 4 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() diff --git a/rust-version b/rust-version index f545ef4d2b..bddb68a06b 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -6159a44067ebce42b38f062cc7df267a1348e092 +1be6b13be73dc12e98e51b403add4c41a0b77759 |