This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
FYI: fix completion in anonymous unions
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 30 Sep 2010 11:50:59 -0600
- Subject: FYI: fix completion in anonymous unions
I'm checking this in.
While looking at another bug, I noticed that field completion in
anonymous unions does not work. This patch adds support for that.
Built and regtested on x86-64 (compile farm).
New test case included.
Tom
2010-09-30 Tom Tromey <tromey@redhat.com>
* completer.c (count_struct_fields): Handle anonymous structs and
unions.
(add_struct_fields): Likewise.
2010-09-30 Tom Tromey <tromey@redhat.com>
* gdb.base/completion.exp: Test completion through anonymous
union.
* gdb.base/break1.c (struct some_struct): Add anonymous union.
Index: completer.c
===================================================================
RCS file: /cvs/src/src/gdb/completer.c,v
retrieving revision 1.40
diff -u -r1.40 completer.c
--- completer.c 18 Aug 2010 19:02:32 -0000 1.40
+++ completer.c 30 Sep 2010 17:44:27 -0000
@@ -351,7 +351,15 @@
if (i < TYPE_N_BASECLASSES (type))
result += count_struct_fields (TYPE_BASECLASS (type, i));
else if (TYPE_FIELD_NAME (type, i))
- ++result;
+ {
+ if (TYPE_FIELD_NAME (type, i)[0] != '\0')
+ ++result;
+ else if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_UNION)
+ {
+ /* Recurse into anonymous unions. */
+ result += count_struct_fields (TYPE_FIELD_TYPE (type, i));
+ }
+ }
}
for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
@@ -380,11 +388,22 @@
if (i < TYPE_N_BASECLASSES (type))
add_struct_fields (TYPE_BASECLASS (type, i), nextp, output,
fieldname, namelen);
- else if (TYPE_FIELD_NAME (type, i)
- && ! strncmp (TYPE_FIELD_NAME (type, i), fieldname, namelen))
+ else if (TYPE_FIELD_NAME (type, i))
{
- output[*nextp] = xstrdup (TYPE_FIELD_NAME (type, i));
- ++*nextp;
+ if (TYPE_FIELD_NAME (type, i)[0] != '\0')
+ {
+ if (! strncmp (TYPE_FIELD_NAME (type, i), fieldname, namelen))
+ {
+ output[*nextp] = xstrdup (TYPE_FIELD_NAME (type, i));
+ ++*nextp;
+ }
+ }
+ else if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_UNION)
+ {
+ /* Recurse into anonymous unions. */
+ add_struct_fields (TYPE_FIELD_TYPE (type, i), nextp, output,
+ fieldname, namelen);
+ }
}
}
Index: testsuite/gdb.base/break1.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/break1.c,v
retrieving revision 1.9
diff -u -r1.9 break1.c
--- testsuite/gdb.base/break1.c 1 Jan 2010 07:32:00 -0000 1.9
+++ testsuite/gdb.base/break1.c 30 Sep 2010 17:44:39 -0000
@@ -24,6 +24,7 @@
{
int a_field;
int b_field;
+ union { int z_field; };
};
struct some_struct values[50];
Index: testsuite/gdb.base/completion.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/completion.exp,v
retrieving revision 1.47
diff -u -r1.47 completion.exp
--- testsuite/gdb.base/completion.exp 18 Aug 2010 19:02:34 -0000 1.47
+++ testsuite/gdb.base/completion.exp 30 Sep 2010 17:44:39 -0000
@@ -684,6 +684,10 @@
timeout { fail "(timeout) complete 'p &values\[0\] -> a' 2" }
}
+gdb_test "complete p &values\[0\]->z" \
+ "p &values.0.->z_field" \
+ "copmletion of field in anonymous union"
+
# The following tests used to simply try to complete `${objdir}/file',
# and so on. The problem is that ${objdir} can be very long; the
# completed filename may be more than eighty characters wide. When