aboutsummaryrefslogtreecommitdiff
path: root/gdb/completer.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2010-09-30 17:51:39 +0000
committerTom Tromey <tromey@redhat.com>2010-09-30 17:51:39 +0000
commit9ae8282da74ec1fbc0f89d87e645cbaabfa609ce (patch)
treea9242e14a57148f7c249f096ae437ade3f50e6ce /gdb/completer.c
parente7390eec2e49ac9d5bf459e26dcf905aa74c2e07 (diff)
downloadgdb-9ae8282da74ec1fbc0f89d87e645cbaabfa609ce.zip
gdb-9ae8282da74ec1fbc0f89d87e645cbaabfa609ce.tar.gz
gdb-9ae8282da74ec1fbc0f89d87e645cbaabfa609ce.tar.bz2
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/completer.c')
-rw-r--r--gdb/completer.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/gdb/completer.c b/gdb/completer.c
index 91b899d..5d0898d 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);
+ }
}
}