Fix ptype/o bug with "<no data fields>"
authorTom Tromey <tom@tromey.com>
Fri, 23 Apr 2021 01:39:56 +0000 (19:39 -0600)
committerTom Tromey <tom@tromey.com>
Fri, 23 Apr 2021 01:39:56 +0000 (19:39 -0600)
I noticed that when using ptype/o, the "<no data fields>" text that
may be emitted is indented incorrectly.  This patch fixes the bug and
adds a new test case.

I also removed a stray backslash from ptype-offsets.exp that I noticed
while writing the test.  This seemed too trivial to warrant a separate
patch.

gdb/ChangeLog
2021-04-22  Tom Tromey  <tom@tromey.com>

* c-typeprint.c (c_type_print_base_struct_union): Use
print_spaces_filtered_with_print_options.

gdb/testsuite/ChangeLog
2021-04-22  Tom Tromey  <tom@tromey.com>

* gdb.base/ptype-offsets.cc (struct empty_member): New.
(main): Use empty_member.
* gdb.base/ptype-offsets.exp: Add new test.

gdb/ChangeLog
gdb/c-typeprint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/ptype-offsets.cc
gdb/testsuite/gdb.base/ptype-offsets.exp

index 67de5ca80bb34e071a7106a527841fddec2022aa..5d869dbfa7d4ed45e695a7a22a3d1b72e5964d5b 100644 (file)
@@ -1,3 +1,8 @@
+2021-04-22  Tom Tromey  <tom@tromey.com>
+
+       * c-typeprint.c (c_type_print_base_struct_union): Use
+       print_spaces_filtered_with_print_options.
+
 2021-04-22  Simon Marchi  <simon.marchi@polymtl.ca>
 
        PR gdb/27757
index f81f1c2c1131b32c8ba33d0298ae894117b35497..72616a59af0063de9a3ccb94732dae5a4e649f70 100644 (file)
@@ -1121,13 +1121,12 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
       if (type->num_fields () == 0 && TYPE_NFN_FIELDS (type) == 0
          && TYPE_TYPEDEF_FIELD_COUNT (type) == 0)
        {
+         print_spaces_filtered_with_print_options (level + 4, stream, flags);
          if (type->is_stub ())
-           fprintf_filtered (stream, _("%*s%p[<incomplete type>%p]\n"),
-                             level + 4, "",
+           fprintf_filtered (stream, _("%p[<incomplete type>%p]\n"),
                              metadata_style.style ().ptr (), nullptr);
          else
-           fprintf_filtered (stream, _("%*s%p[<no data fields>%p]\n"),
-                             level + 4, "",
+           fprintf_filtered (stream, _("%p[<no data fields>%p]\n"),
                              metadata_style.style ().ptr (), nullptr);
        }
 
index 266645bd6ad6624889ece82f5c0369ca6be105fb..1a181f374755fe51a7ca5f21ded919ceb4f9de29 100644 (file)
@@ -1,3 +1,9 @@
+2021-04-22  Tom Tromey  <tom@tromey.com>
+
+       * gdb.base/ptype-offsets.cc (struct empty_member): New.
+       (main): Use empty_member.
+       * gdb.base/ptype-offsets.exp: Add new test.
+
 2021-04-22  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * gdb.python/flexible-array-member.exp: Add check for Python
index 4582af48cef0007bdc6545eb959a2fe9e61b8fae..dc21e34752f43619323694c5cc0a3ed58657fcf6 100644 (file)
@@ -185,6 +185,12 @@ struct static_member
   int abc;
 };
 
+struct empty_member
+{
+  struct { } empty;
+  int an_int;
+};
+
 int
 main (int argc, char *argv[])
 {
@@ -196,6 +202,7 @@ main (int argc, char *argv[])
   struct asd f;
   uint8_t i;
   static_member stmember;
+  empty_member emember;
 
   return 0;
 }
index f466db9a7f2cd115ffca4afbfa28a54efc4d6760..0a0bbc8706245c350aa6790e98985752fcf32a2c 100644 (file)
@@ -336,7 +336,22 @@ gdb_test "ptype/o static_member" \
     [string_to_regexp [multi_line \
 "/* offset    |  size */  type = struct static_member \{" \
 "                           static static_member Empty;" \
-"\/*    0      |     4 */    int abc;" \
+"/*    0      |     4 */    int abc;" \
 "" \
 "                           /* total size (bytes):    4 */" \
 "                         \}"]]
+
+# Test that the "no data fields" text is indented properly.
+gdb_test "ptype/o empty_member" \
+    [string_to_regexp [multi_line \
+"/* offset    |  size */  type = struct empty_member \{" \
+"/*    0      |     1 */    struct {" \
+"                               <no data fields>" \
+"" \
+"                               /* total size (bytes):    1 */" \
+"                           } empty;" \
+"/* XXX  3-byte hole  */" \
+"/*    4      |     4 */    int an_int;" \
+"" \
+"                           /* total size (bytes):    8 */" \
+"                         \}"]]
This page took 0.038815 seconds and 4 git commands to generate.