Skip to content

Commit 34fe0ce

Browse files
committed
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"
1 parent c984395 commit 34fe0ce

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/tools/rust-analyzer/lib/smol_str/src/gdb_smolstr_printer.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,14 @@ def to_string(self):
7373

7474
if variant_name == "Static":
7575
try:
76-
data_ptr = variant_val["data_ptr"]
77-
length = int(variant_val["length"])
78-
mem = gdb.selected_inferior().read_memory(int(data_ptr), length)
79-
return _read_utf8(mem)
76+
# variant_val["__0"] is &'static str
77+
return variant_val["__0"]
8078
except Exception as e:
8179
return f"<SmolStr Static error: {e}>"
8280

8381
if variant_name == "Heap":
8482
try:
85-
# variant_val is an Arc<str>
83+
# variant_val["__0"] is an Arc<str>
8684
inner = variant_val["__0"]["ptr"]["pointer"]
8785
# inner is a fat pointer to ArcInner<str>
8886
data_ptr = inner["data_ptr"]

0 commit comments

Comments
 (0)