gdb: fix missing space in some info variables output
authorAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 26 Jul 2021 16:29:05 +0000 (17:29 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 28 Jul 2021 08:38:32 +0000 (09:38 +0100)
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
gdb/testsuite/gdb.base/info-var-f1.c
gdb/testsuite/gdb.base/info-var.exp

index 0502d31eff9605e7e2e430c8ad72908792c1b475..741541749b350d7d7c444b3ca1bfc1cf203bc86f 100644 (file)
@@ -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;
index be6e8e9f3adb22004e0b20f6ca14cab2c340a515..b66ce98abaf61b0e72b97646feb339cf4c787d6d 100644 (file)
 
 #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
index 03b9b7c4b9b0ee3e3b1b88f42da841812002b1fe..9e54654356857724c2bd02e9cdfbcf9141ce6d14 100644 (file)
@@ -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;" \