]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix pp.rs test for gccrs
authorTom Tromey <tom@tromey.com>
Mon, 17 Mar 2025 18:57:34 +0000 (12:57 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 3 Apr 2025 14:16:23 +0000 (08:16 -0600)
gccrs still can't process all of gdb's Rust tests, but I did manage to
manually test it on a few.  In addition to filing some bug reports, I
came up with this patch.

There are two fixes here.  First, gccrs emits tuple field names as
integers ("0", "1", etc) whereas rustc uses a leading double
underscore ("__0", "__1", etc).  This patch changes gdb to accept the
gccrs output, which IMO makes sense (and for which there's already a
rustc feature request).

Second, it changes rust_struct_anon::evaluate to use check_typedef.
This is a gdb necessity in general, so could be described as an
oversight; but in this case it works around the gccrs oddity that most
named types are emitted as DW_TAG_typedef.  I've filed a gccrs bug
report for that.

gdb/rust-lang.c

index 8bec934983ec66cd348f6d32df01b9c40b845017..adcec6391d15f25d3337b1f7c282623ee6924e9b 100644 (file)
@@ -116,7 +116,8 @@ rust_tuple_type_p (struct type *type)
 }
 
 /* Return true if all non-static fields of a structlike type are in a
-   sequence like __0, __1, __2.  */
+   sequence like 0, 1, 2.  "__" prefixes are also accepted -- rustc
+   emits "__0" but gccrs emits "0".  */
 
 static bool
 rust_underscore_fields (struct type *type)
@@ -131,8 +132,12 @@ rust_underscore_fields (struct type *type)
        {
          char buf[20];
 
-         xsnprintf (buf, sizeof (buf), "__%d", field_number);
-         if (strcmp (buf, type->field (i).name ()) != 0)
+         xsnprintf (buf, sizeof (buf), "%d", field_number);
+
+         const char *field_name = type->field (i).name ();
+         if (startswith (field_name, "__"))
+           field_name += 2;
+         if (strcmp (buf, field_name) != 0)
            return false;
          field_number++;
        }
@@ -1476,7 +1481,7 @@ rust_struct_anon::evaluate (struct type *expect_type,
   value *lhs = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
   int field_number = std::get<0> (m_storage);
 
-  struct type *type = lhs->type ();
+  struct type *type = check_typedef (lhs->type ());
 
   if (type->code () == TYPE_CODE_STRUCT)
     {