From: Tom Tromey Date: Mon, 17 Mar 2025 18:57:34 +0000 (-0600) Subject: Fix pp.rs test for gccrs X-Git-Tag: binutils-2_45~981 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=254809b28f1c9c2a43d25ca1a71a5603d4d1bda6;p=thirdparty%2Fbinutils-gdb.git Fix pp.rs test for gccrs 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. --- diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 8bec934983e..adcec6391d1 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -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) {