Unnamed repository; edit this file 'description' to name the repository.
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: "<SmolStr Static error: There is no member named data_ptr.>" Output after: "preferred-width"
David Faure 5 months ago
parent 05f8b07 · commit 3be2b2a
-rw-r--r--lib/smol_str/src/gdb_smolstr_printer.py8
1 files 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 5f28ddd5e6..2792aae09b 100644
--- a/lib/smol_str/src/gdb_smolstr_printer.py
+++ b/lib/smol_str/src/gdb_smolstr_printer.py
@@ -73,16 +73,14 @@ class SmolStrProvider:
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"<SmolStr Static error: {e}>"
if variant_name == "Heap":
try:
- # variant_val is an Arc<str>
+ # variant_val["__0"] is an Arc<str>
inner = variant_val["__0"]["ptr"]["pointer"]
# inner is a fat pointer to ArcInner<str>
data_ptr = inner["data_ptr"]