From 3be2b2aaa5328c8089576cd3f9089a0e58240d86 Mon Sep 17 00:00:00 2001 From: David Faure Date: Sun, 30 Nov 2025 10:31:16 +0100 Subject: [PATCH] internal: fix gdb pretty printer when using Repr::Static I missed a ["__0"] to access the str in the Static case. Also, simplify the code to rely on the pretty printer for str rather than accessing data_ptr/length directly. This makes it more robust against changes in str. Output before: "" Output after: "preferred-width" --- lib/smol_str/src/gdb_smolstr_printer.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/smol_str/src/gdb_smolstr_printer.py b/lib/smol_str/src/gdb_smolstr_printer.py index 5f28ddd5e64e..2792aae09b33 100644 --- a/lib/smol_str/src/gdb_smolstr_printer.py +++ b/lib/smol_str/src/gdb_smolstr_printer.py @@ -73,16 +73,14 @@ def to_string(self): if variant_name == "Static": try: - data_ptr = variant_val["data_ptr"] - length = int(variant_val["length"]) - mem = gdb.selected_inferior().read_memory(int(data_ptr), length) - return _read_utf8(mem) + # variant_val["__0"] is &'static str + return variant_val["__0"] except Exception as e: return f"" if variant_name == "Heap": try: - # variant_val is an Arc + # variant_val["__0"] is an Arc inner = variant_val["__0"]["ptr"]["pointer"] # inner is a fat pointer to ArcInner data_ptr = inner["data_ptr"]