summaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2010-09-30 17:51:34 +0000
committerTom Tromey <tromey@redhat.com>2010-09-30 17:51:34 +0000
commit58beeed5ce32cac71f4abde3b190984f9dbe0664 (patch)
tree332908aface69190c41e98b0567028323da84f5c /gdb
parentc290e784cf9943779c0531a3e9f6d7aa7c22cb9c (diff)
downloadgdb-58beeed5ce32cac71f4abde3b190984f9dbe0664.tar.gz
gdb
* completer.c (count_struct_fields): Handle anonymous structs and unions. (add_struct_fields): Likewise. gdb/testsuite * gdb.base/completion.exp: Test completion through anonymous union. * gdb.base/break1.c (struct some_struct): Add anonymous union.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog6
-rw-r--r--gdb/completer.c29
-rw-r--r--gdb/testsuite/ChangeLog6
-rw-r--r--gdb/testsuite/gdb.base/break1.c1
-rw-r--r--gdb/testsuite/gdb.base/completion.exp4
5 files changed, 41 insertions, 5 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c10ed117f64..dfbae8b08b1 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+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 Jan Kratochvil <jan.kratochvil@redhat.com>
Fix printing parameters of inlined functions.
diff --git a/gdb/completer.c b/gdb/completer.c
index 91b899d900f..5d0898d04c5 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -351,7 +351,15 @@ count_struct_fields (struct type *type)
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 @@ add_struct_fields (struct type *type, int *nextp, char **output,
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);
+ }
}
}
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 42e71921093..56ee414d821 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+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.
+
2010-09-30 Jan Kratochvil <jan.kratochvil@redhat.com>
Fix printing parameters of inlined functions.
diff --git a/gdb/testsuite/gdb.base/break1.c b/gdb/testsuite/gdb.base/break1.c
index 93b563a2933..ab8e00f64da 100644
--- a/gdb/testsuite/gdb.base/break1.c
+++ b/gdb/testsuite/gdb.base/break1.c
@@ -24,6 +24,7 @@ struct some_struct
{
int a_field;
int b_field;
+ union { int z_field; };
};
struct some_struct values[50];
diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index 1f7c214a6f5..904ee9852bd 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -684,6 +684,10 @@ gdb_expect {
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