Fix ada array bounds display
authorJoel Brobecker <brobecker@gnat.com>
Fri, 1 Jul 2011 18:27:12 +0000 (18:27 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Fri, 1 Jul 2011 18:27:12 +0000 (18:27 +0000)
Array bounds were not correctly displayed when the SHOW parameter of
print_type functions is set to -1.  This shows up in the following
type of situation, where we have a declaration as follow:

    Anon_Array_Int_Obj : array (1..10) of Integer := (others => 8);

In GDB/MI mode, trying to print the type info for our array object
yields:

    (gdb) -var-create ai 0 Anon_Array_Int_Obj
    (gdb) -var-info-type ai
    ^done,type="array (...) of integer"

The actual bounds are missing.  Contrast this with what happens
when in GDB/CLI mode:

    (gdb) ptype Anon_Array_Int_Obj
    type = array (1 .. 10) of integer

This patch fixes array type printing accordingly. And as it turns
out, it also improves the output for one of the tests already present,
so it shows that it's not just the GDB/MI mode that's affected.

gdb/ChangeLog (Jean-Charles Delay):

* ada-typeprint.c (print_array_type): removed if condition on show
being negative for bounds printing.

gdb/testsuite/ChangeLog (Jean-Charles Delay):

* gdb.ada/packed_array.exp: fixed expected output.

gdb/ChangeLog
gdb/ada-typeprint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.ada/packed_array.exp

index 292b899..572faa2 100644 (file)
@@ -1,3 +1,8 @@
+2011-07-01  Jean-Charles Delay  <delay@adacore.com>
+
+       * ada-typeprint.c (print_array_type): removed if condition on show
+       being negative for bounds printing.
+
 2011-07-01  Joel Brobecker  <brobecker@adacore.com>
 
        * ada-lang.c (ada_identical_enum_types_p): New function.
index 737e097..ff1b524 100644 (file)
@@ -340,57 +340,52 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
     }
 
   n_indices = -1;
-  if (show < 0)
-    fprintf_filtered (stream, "...");
-  else
+  if (ada_is_simple_array_type (type))
     {
-      if (ada_is_simple_array_type (type))
-       {
-         struct type *range_desc_type;
-         struct type *arr_type;
+      struct type *range_desc_type;
+      struct type *arr_type;
 
-         range_desc_type = ada_find_parallel_type (type, "___XA");
-         ada_fixup_array_indexes_type (range_desc_type);
+      range_desc_type = ada_find_parallel_type (type, "___XA");
+      ada_fixup_array_indexes_type (range_desc_type);
 
-         bitsize = 0;
-         if (range_desc_type == NULL)
-           {
-             for (arr_type = type; TYPE_CODE (arr_type) == TYPE_CODE_ARRAY;
-                  arr_type = TYPE_TARGET_TYPE (arr_type))
-               {
-                 if (arr_type != type)
-                   fprintf_filtered (stream, ", ");
-                 print_range (TYPE_INDEX_TYPE (arr_type), stream);
-                 if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
-                   bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
-               }
-           }
-         else
+      bitsize = 0;
+      if (range_desc_type == NULL)
+       {
+         for (arr_type = type; TYPE_CODE (arr_type) == TYPE_CODE_ARRAY;
+              arr_type = TYPE_TARGET_TYPE (arr_type))
            {
-             int k;
-
-             n_indices = TYPE_NFIELDS (range_desc_type);
-             for (k = 0, arr_type = type;
-                  k < n_indices;
-                  k += 1, arr_type = TYPE_TARGET_TYPE (arr_type))
-               {
-                 if (k > 0)
-                   fprintf_filtered (stream, ", ");
-                 print_range_type (TYPE_FIELD_TYPE (range_desc_type, k),
-                                   stream);
-                 if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
-                   bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
-               }
+             if (arr_type != type)
+               fprintf_filtered (stream, ", ");
+             print_range (TYPE_INDEX_TYPE (arr_type), stream);
+             if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
+               bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
            }
        }
       else
        {
-         int i, i0;
+         int k;
 
-         for (i = i0 = ada_array_arity (type); i > 0; i -= 1)
-           fprintf_filtered (stream, "%s<>", i == i0 ? "" : ", ");
+         n_indices = TYPE_NFIELDS (range_desc_type);
+         for (k = 0, arr_type = type;
+              k < n_indices;
+              k += 1, arr_type = TYPE_TARGET_TYPE (arr_type))
+           {
+             if (k > 0)
+               fprintf_filtered (stream, ", ");
+             print_range_type (TYPE_FIELD_TYPE (range_desc_type, k),
+                               stream);
+             if (TYPE_FIELD_BITSIZE (arr_type, 0) > 0)
+               bitsize = TYPE_FIELD_BITSIZE (arr_type, 0);
+           }
        }
     }
+  else
+    {
+      int i, i0;
+
+      for (i = i0 = ada_array_arity (type); i > 0; i -= 1)
+       fprintf_filtered (stream, "%s<>", i == i0 ? "" : ", ");
+    }
 
   fprintf_filtered (stream, ") of ");
   wrap_here ("");
index 0bea0b5..c684ee6 100644 (file)
@@ -1,3 +1,7 @@
+2011-07-01  Jean-Charles Delay  <delay@adacore.com>
+
+       * gdb.ada/packed_array.exp: fixed expected output.
+
 2011-07-01  Joel Brobecker  <brobecker@adacore.com>
 
        * gdb.ada/same_enum: New testcase.
index fc4dd17..3318873 100644 (file)
@@ -48,7 +48,7 @@ gdb_test "ptype &var" \
          "ptype &var"
 
 gdb_test "print &var" \
-         "= \\(access array \\(\\.\\.\\.\\) of boolean\\) \\(4 => true, false, true, false, true\\)" \
+         "= \\(access array \\(4 \\.\\. 8\\) of boolean <packed: 1-bit elements>\\) \\(4 => true, false, true, false, true\\)" \
          "print &var"
 
 # Print the value of U_Var, an unconstrainted packed array.