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"
This commit is contained in:
David Faure 2025-11-30 10:31:16 +01:00
parent 05f8b070b8
commit 3be2b2aaa5

View file

@ -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"]