From 77791f9c21ec05423db6724a3be543f2cb6e5822 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Mon, 26 Jul 2021 17:29:05 +0100 Subject: [PATCH] gdb: fix missing space in some info variables output Fixes PR gdb/28121. When a user declares an array like this: int * const foo_1[3]; And in GDB the user does this: (gdb) info variables foo All variables matching regular expression "foo": File test.c: 1: int * constfoo_1[3]; Notice the missing space between 'const' and 'foo_1'. This is fixed in c_type_print_varspec_prefix (c-typeprint.c) by passing through the flag that indicates if a trailing space is needed, rather than hard coding the flag to false as we currently do. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28121 --- gdb/c-typeprint.c | 4 ++-- gdb/testsuite/gdb.base/info-var-f1.c | 8 ++++++++ gdb/testsuite/gdb.base/info-var.exp | 16 ++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 0502d31eff9..741541749b3 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -436,8 +436,8 @@ c_type_print_varspec_prefix (struct type *type, case TYPE_CODE_ARRAY: c_type_print_varspec_prefix (TYPE_TARGET_TYPE (type), - stream, show, 0, 0, language, flags, - podata); + stream, show, 0, need_post_space, + language, flags, podata); if (passed_a_ptr) fprintf_filtered (stream, "("); break; diff --git a/gdb/testsuite/gdb.base/info-var-f1.c b/gdb/testsuite/gdb.base/info-var-f1.c index be6e8e9f3ad..b66ce98abaf 100644 --- a/gdb/testsuite/gdb.base/info-var-f1.c +++ b/gdb/testsuite/gdb.base/info-var-f1.c @@ -15,6 +15,14 @@ #include "info-var.h" +/* Some array variables. */ +int * const foo_1[3]; +const int *foo_2[3]; +int *foo_3[3]; +int const foo_4[3]; +const int foo_5[3]; +int foo_6[3]; + static int f1_var = -3; int diff --git a/gdb/testsuite/gdb.base/info-var.exp b/gdb/testsuite/gdb.base/info-var.exp index 03b9b7c4b9b..9e546543568 100644 --- a/gdb/testsuite/gdb.base/info-var.exp +++ b/gdb/testsuite/gdb.base/info-var.exp @@ -31,7 +31,13 @@ gdb_test "info variables" \ "All defined variables:" \ "" \ "File .*${srcfile}:" \ - "18:\[ \t\]+static int f1_var;" \ + "19:\\s+int \\* const foo_1\\\[3\\\];" \ + "20:\\s+const int \\*foo_2\\\[3\\\];" \ + "21:\\s+int \\*foo_3\\\[3\\\];" \ + "22:\\s+const int foo_4\\\[3\\\];" \ + "23:\\s+const int foo_5\\\[3\\\];" \ + "24:\\s+int foo_6\\\[3\\\];" \ + "26:\\s+static int f1_var;" \ "" \ "File .*${srcfile2}:" \ "18:\[ \t\]+int global_var;" \ @@ -48,7 +54,13 @@ gdb_test "info variables -n" \ "All defined variables:" \ "" \ "File .*${srcfile}:" \ - "18:\[ \t\]+static int f1_var;" \ + "19:\\s+int \\* const foo_1\\\[3\\\];" \ + "20:\\s+const int \\*foo_2\\\[3\\\];" \ + "21:\\s+int \\*foo_3\\\[3\\\];" \ + "22:\\s+const int foo_4\\\[3\\\];" \ + "23:\\s+const int foo_5\\\[3\\\];" \ + "24:\\s+int foo_6\\\[3\\\];" \ + "26:\\s+static int f1_var;" \ "" \ "File .*${srcfile2}:" \ "18:\[ \t\]+int global_var;" \ -- 2.30.2