From 432ce4cf6800a3693656fde1306d83ce767e2b2a Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 22 Apr 2021 19:39:56 -0600 Subject: Fix ptype/o bug with "" I noticed that when using ptype/o, the "" 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 * c-typeprint.c (c_type_print_base_struct_union): Use print_spaces_filtered_with_print_options. gdb/testsuite/ChangeLog 2021-04-22 Tom Tromey * gdb.base/ptype-offsets.cc (struct empty_member): New. (main): Use empty_member. * gdb.base/ptype-offsets.exp: Add new test. --- gdb/ChangeLog | 5 +++++ gdb/c-typeprint.c | 7 +++---- gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.base/ptype-offsets.cc | 7 +++++++ gdb/testsuite/gdb.base/ptype-offsets.exp | 17 ++++++++++++++++- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 67de5ca..5d869db 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-04-22 Tom Tromey + + * c-typeprint.c (c_type_print_base_struct_union): Use + print_spaces_filtered_with_print_options. + 2021-04-22 Simon Marchi PR gdb/27757 diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index f81f1c2..72616a5 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -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[%p]\n"), - level + 4, "", + fprintf_filtered (stream, _("%p[%p]\n"), metadata_style.style ().ptr (), nullptr); else - fprintf_filtered (stream, _("%*s%p[%p]\n"), - level + 4, "", + fprintf_filtered (stream, _("%p[%p]\n"), metadata_style.style ().ptr (), nullptr); } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 266645b..1a181f3 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2021-04-22 Tom Tromey + + * 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 * gdb.python/flexible-array-member.exp: Add check for Python diff --git a/gdb/testsuite/gdb.base/ptype-offsets.cc b/gdb/testsuite/gdb.base/ptype-offsets.cc index 4582af4..dc21e34 100644 --- a/gdb/testsuite/gdb.base/ptype-offsets.cc +++ b/gdb/testsuite/gdb.base/ptype-offsets.cc @@ -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; } diff --git a/gdb/testsuite/gdb.base/ptype-offsets.exp b/gdb/testsuite/gdb.base/ptype-offsets.exp index f466db9..0a0bbc8 100644 --- a/gdb/testsuite/gdb.base/ptype-offsets.exp +++ b/gdb/testsuite/gdb.base/ptype-offsets.exp @@ -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 {" \ +" " \ +"" \ +" /* total size (bytes): 1 */" \ +" } empty;" \ +"/* XXX 3-byte hole */" \ +"/* 4 | 4 */ int an_int;" \ +"" \ +" /* total size (bytes): 8 */" \ +" \}"]] -- cgit v1.1