mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-12-23 08:48:08 +00:00
Reformat python script
This commit is contained in:
parent
cf4b1faea3
commit
ef944f193f
1 changed files with 13 additions and 3 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue