aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2025-03-17 12:57:34 -0600
committerTom Tromey <tom@tromey.com>2025-04-03 08:16:23 -0600
commit254809b28f1c9c2a43d25ca1a71a5603d4d1bda6 (patch)
treedfda90b5ff834c11bf6a9e678f2a0108dff9c7b8
parent0326df1b9b1f69886dfd0d4d4aba739db5bdbd65 (diff)
downloadbinutils-254809b28f1c9c2a43d25ca1a71a5603d4d1bda6.zip
binutils-254809b28f1c9c2a43d25ca1a71a5603d4d1bda6.tar.gz
binutils-254809b28f1c9c2a43d25ca1a71a5603d4d1bda6.tar.bz2
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.
-rw-r--r--gdb/rust-lang.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 8bec934..adcec63 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)
{