]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: fix completion of anonymous struct members
authorSimon Marchi <simon.marchi@polymtl.ca>
Thu, 24 Apr 2025 15:13:37 +0000 (11:13 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Thu, 24 Apr 2025 16:50:20 +0000 (12:50 -0400)
Completing fields inside an anonymous struct does not work.  With:

    struct commit_counters_hot {
     union {
     struct {
     long owner;
     };
     char padding[16];
     };
    };

I get:

    (gdb) complete print cc_hot.
    print cc_hot.padding

After this patch, I get:

    (gdb) complete print cc_hot.
    print cc_hot.owner
    print cc_hot.padding

Update break1.c to include an anonymous struct.  The tests that complete
"z_field" inside gdb.base/completion.exp would start to fail without the
fix.

Change-Id: I46b65a95ad16b0825de58dfa241777fe57acc361
Reviewed-By: Keith Seitz <keiths@redhat.com>
gdb/eval.c
gdb/testsuite/gdb.base/break1.c

index 95d2532af8f5a49e9cd1a4681083259adc599ffa..19770ad63d61438c192a9944c6242c0d1d428cba 100644 (file)
@@ -994,9 +994,10 @@ add_struct_fields (struct type *type, completion_list &output,
                output.emplace_back (concat (prefix, type->field (i).name (),
                                             nullptr));
            }
-         else if (type->field (i).type ()->code () == TYPE_CODE_UNION)
+         else if (type->field (i).type ()->code () == TYPE_CODE_UNION
+                  || type->field (i).type ()->code () == TYPE_CODE_STRUCT)
            {
-             /* Recurse into anonymous unions.  */
+             /* Recurse into anonymous unions and structures.  */
              add_struct_fields (type->field (i).type (),
                                 output, fieldname, namelen, prefix);
            }
index 110341c137715d3096f1347092b545bfdd6dea34..26c4663edc3fd294a34509f1c02897c681c9bccb 100644 (file)
@@ -23,7 +23,13 @@ struct some_struct
 {
   int a_field;
   int b_field;
-  union { int z_field; };
+  union
+  {
+    struct
+    {
+      int z_field;
+    };
+  };
 };
 
 struct some_struct values[50];