]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
(Ada) Remove printing of array's first index when unneeded
authorXavier Roirand <roirand@adacore.com>
Fri, 5 Jan 2018 04:47:05 +0000 (23:47 -0500)
committerJoel Brobecker <brobecker@adacore.com>
Fri, 5 Jan 2018 04:47:15 +0000 (23:47 -0500)
Consider the following code:

  type Table is array (Character) of Natural;
  My_Table : Table := (others => 4874);

Printing this table in gdb leads to:

  (gdb) p my_table
  $1 = ('["00"]' => 4874 <repeats 256 times>)

In this case, the index of the first element in this array is also
the first element of the index type (character type). Similar to what
we do we enumeration types, we do not need to print the index of the
first element when printing the array.

This patch fixes this issue and changes the output as follow:

  (gdb) p my_table
  $1 = (4874 <repeats 256 times>)

gdb/ChangeLog:

        * ada-valprint.c (print_optional_low_bound): Handle
        character-indexed array printing like boolean-indexed array
        printing.

gdb/testuite/ChangeLog:

        * testsuite/gdb.ada/array_char_idx/pck.ads (Table): New type.
        (My_Table): New global variable.
        * testsuite/gdb.ada/array_char_idx.exp: Add test.

Tested on x86_64-linux.

gdb/ChangeLog
gdb/ada-valprint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/array_char_idx.exp
gdb/testsuite/gdb.ada/array_char_idx/pck.ads

index b63238288ec7c0c5e1af7a0ba4f8e0e76ca60e26..ab98fb40ffe8e8c01f459040af9b8e007f7e4342 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-03  Xavier Roirand  <roirand@adacore.com>
+
+       * ada-valprint.c (print_optional_low_bound): Handle
+       character-indexed array printing like boolean-indexed array
+       printing.
+
 2018-01-05  Joel Brobecker  <brobecker@adacore.com>
 
        * NEWS: Create a new section for the next release branch.
index c5efdf1c1c5367b312c04675b7be089434ac4ed5..f5a2c3c63b4b5c2cbad3e42d5318ac3ac41dd277 100644 (file)
@@ -88,9 +88,11 @@ print_optional_low_bound (struct ui_file *stream, struct type *type,
       index_type = TYPE_TARGET_TYPE (index_type);
     }
 
+  /* Don't print the lower bound if it's the default one.  */
   switch (TYPE_CODE (index_type))
     {
     case TYPE_CODE_BOOL:
+    case TYPE_CODE_CHAR:
       if (low_bound == 0)
        return 0;
       break;
index ea9d65cd759b9c67dd17665241f7c0b7d5e5cfd4..f45ae0c61f3ef40363babb7c8ee6c9b348f172fd 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-05  Xavier Roirand  <brobecker@adacore.com>
+
+       * testsuite/gdb.ada/array_char_idx/pck.ads (Table): New type.
+       (My_Table): New global variable.
+       * testsuite/gdb.ada/array_char_idx.exp: Add test.
+
 2018-01-04  Joel Brobecker  <brobecker@adacore.com>
 
        PR gdb/22670
index 2608a8e296df30f32db538f19e19f48591f0c49f..89805fbea0641e2182282a740d20a2ca5d40024f 100644 (file)
@@ -30,3 +30,6 @@ gdb_test "ptype char_table" \
 
 gdb_test "ptype global_char_table" \
          "= array \\(character\\) of natural"
+
+gdb_test "print my_table" "= \\(0 <repeats 256 times>\\)" \
+         "Display my_table"
index a26393a1f396baf76145bf674052da5f8cf77fcc..699fef9b6e61685975635df0bba764ba339c936b 100644 (file)
@@ -19,5 +19,8 @@ package Pck is
       of Natural;
    Global_Char_Table : Char_Table := (others => 0);
 
+   type Table is array (Character) of Natural;
+   My_Table : Table := (others => 4874);
+
    procedure Do_Nothing (A : System.Address);
 end Pck;