2004-08-29 David Lecomber <david@streamline-computing.com>
authorDavid Lecomber <david@lecomber.net>
Sun, 29 Aug 2004 10:12:24 +0000 (10:12 +0000)
committerDavid Lecomber <david@lecomber.net>
Sun, 29 Aug 2004 10:12:24 +0000 (10:12 +0000)
Fix PR gdb/648
* language.h (enum array_ordering): New enum.
* language.h (struct language_defn): New la_array_ordering
attribute.
* language.c (unknown_language_defn, auto_language_defn)
(local_language_defn): Ditto.
* ada-lang.c (ada_language_defn): Ditto.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Ditto.
* f-lang.c (f_language_defn): Ditto.
* jv-lang.c (java_language_defn): Ditto.
* m2-lang.c (f_language_defn): Ditto.
* objc-lang.c (objc_language_defn): Ditto.
* p-lang.c (pascal_language_defn): Ditto.
* scm-lang.c (scm_language_defn): Ditto.
* eval.c (evaluate_subexp_standard): Assume Fortran arrays are
oriented large to small in type structure.
* dwarf2read.c (read_array_order): New function.
(read_array_type): Use read_array_order to check row/column
major ordering.

13 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/c-lang.c
gdb/dwarf2read.c
gdb/eval.c
gdb/f-lang.c
gdb/jv-lang.c
gdb/language.c
gdb/language.h
gdb/m2-lang.c
gdb/objc-lang.c
gdb/p-lang.c
gdb/scm-lang.c

index e5fa2245fe1a53849572848fbc924c8a852b6667..c141526e6036b9d3f9d4076849c0bfe0c8c187f2 100644 (file)
@@ -1,3 +1,26 @@
+2004-08-29  David Lecomber  <david@streamline-computing.com>
+       
+       Fix PR gdb/648
+       * language.h (enum array_ordering): New enum.
+       * language.h (struct language_defn): New la_array_ordering 
+       attribute.
+       * language.c (unknown_language_defn, auto_language_defn)
+       (local_language_defn): Ditto.
+       * ada-lang.c (ada_language_defn): Ditto.
+       * c-lang.c (c_language_defn, cplus_language_defn)
+       (asm_language_defn, minimal_language_defn): Ditto.
+       * f-lang.c (f_language_defn): Ditto.
+       * jv-lang.c (java_language_defn): Ditto.
+       * m2-lang.c (f_language_defn): Ditto.
+       * objc-lang.c (objc_language_defn): Ditto.
+       * p-lang.c (pascal_language_defn): Ditto.
+       * scm-lang.c (scm_language_defn): Ditto.
+       * eval.c (evaluate_subexp_standard): Assume Fortran arrays are
+       oriented large to small in type structure.
+       * dwarf2read.c (read_array_order): New function.
+       (read_array_type): Use read_array_order to check row/column
+       major ordering.
+
 2004-08-27  Nathan J. Williams  <nathanw@wasabisystems.com>
 
        * target.c (target_resize_to_sections): Check
index 1bb3ca09ea27f7a59925c3d01e59b3c9d339bc69..fd73fc58daef4cf9ec8321acb11c23f63777d505 100644 (file)
@@ -10166,6 +10166,7 @@ const struct language_defn ada_language_defn = {
   ada_lookup_symbol,
   ada_lookup_minimal_symbol,
 #endif /* GNAT_GDB */
+  array_row_major,
   &ada_exp_descriptor,
   parse,
   ada_error,
index 5ab15b8edf2dedfa0fc29bdac666deffea5d24cf..ad8fa5c8ebd475ecdd88f584c8b64da987a4b173 100644 (file)
@@ -570,6 +570,7 @@ const struct language_defn c_language_defn =
   range_check_off,
   type_check_off,
   case_sensitive_on,
+  array_row_major,
   &exp_descriptor_standard,
   c_preprocess_and_parse,
   c_error,
@@ -631,6 +632,7 @@ const struct language_defn cplus_language_defn =
   range_check_off,
   type_check_off,
   case_sensitive_on,
+  array_row_major,
   &exp_descriptor_standard,
   c_preprocess_and_parse,
   c_error,
@@ -669,6 +671,7 @@ const struct language_defn asm_language_defn =
   range_check_off,
   type_check_off,
   case_sensitive_on,
+  array_row_major,
   &exp_descriptor_standard,
   c_preprocess_and_parse,
   c_error,
@@ -712,6 +715,7 @@ const struct language_defn minimal_language_defn =
   range_check_off,
   type_check_off,
   case_sensitive_on,
+  array_row_major,
   &exp_descriptor_standard,
   c_preprocess_and_parse,
   c_error,
index fa11475a69117f6ed88abaaa13579ffe93374053..4e9cdfa89f3f9b5674b46adb0b1dd5ab48c9519d 100644 (file)
@@ -848,6 +848,9 @@ static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *);
 
 static void read_array_type (struct die_info *, struct dwarf2_cu *);
 
+static enum dwarf_array_dim_ordering read_array_order (struct die_info *, 
+                                                      struct dwarf2_cu *);
+
 static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *);
 
 static void read_tag_ptr_to_member_type (struct die_info *,
@@ -3724,9 +3727,20 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
 
   /* Dwarf2 dimensions are output from left to right, create the
      necessary array types in backwards order.  */
+
   type = element_type;
-  while (ndim-- > 0)
-    type = create_array_type (NULL, type, range_types[ndim]);
+
+  if (read_array_order (die, cu) == DW_ORD_col_major)
+    {
+      int i = 0;
+      while (i < ndim)
+       type = create_array_type (NULL, type, range_types[i++]);
+    }
+  else
+    {
+      while (ndim-- > 0)
+       type = create_array_type (NULL, type, range_types[ndim]);
+    }
 
   /* Understand Dwarf2 support for vector types (like they occur on
      the PowerPC w/ AltiVec).  Gcc just adds another attribute to the
@@ -3744,6 +3758,41 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
   die->type = type;
 }
 
+static enum dwarf_array_dim_ordering
+read_array_order (struct die_info *die, struct dwarf2_cu *cu) 
+{
+  struct attribute *attr;
+
+  attr = dwarf2_attr (die, DW_AT_ordering, cu);
+
+  if (attr) return DW_SND (attr);
+
+  /*
+    GNU F77 is a special case, as at 08/2004 array type info is the
+    opposite order to the dwarf2 specification, but data is still 
+    laid out as per normal fortran.
+
+    FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need 
+    version checking.
+  */
+
+  if (cu->language == language_fortran &&
+      cu->producer && strstr (cu->producer, "GNU F77"))
+    {
+      return DW_ORD_row_major;
+    }
+
+  switch (cu->language_defn->la_array_ordering) 
+    {
+    case array_column_major:
+      return DW_ORD_col_major;
+    case array_row_major:
+    default:
+      return DW_ORD_row_major;
+    };
+}
+
+
 /* First cut: install each common block member as a global variable.  */
 
 static void
index b690a78da09e6807e5628b1dc22ff365c1839a29..4418e0ad29bbf8d24ea11b18f8ddc1b43678ca77 100644 (file)
@@ -1610,9 +1610,8 @@ evaluate_subexp_standard (struct type *expect_type,
 
     multi_f77_subscript:
       {
-       int subscript_array[MAX_FORTRAN_DIMS + 1];      /* 1-based array of 
-                                                          subscripts, max == 7 */
-       int array_size_array[MAX_FORTRAN_DIMS + 1];
+       int subscript_array[MAX_FORTRAN_DIMS];
+       int array_size_array[MAX_FORTRAN_DIMS];
        int ndimensions = 1, i;
        struct type *tmp_type;
        int offset_item;        /* The array offset where the item lives */
@@ -1630,7 +1629,8 @@ evaluate_subexp_standard (struct type *expect_type,
           let us actually find out where this element exists in the array. */
 
        offset_item = 0;
-       for (i = 1; i <= nargs; i++)
+       /* Take array indices left to right */
+       for (i = 0; i < nargs; i++)
          {
            /* Evaluate each subscript, It must be a legal integer in F77 */
            arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
@@ -1638,7 +1638,11 @@ evaluate_subexp_standard (struct type *expect_type,
            /* Fill in the subscript and array size arrays */
 
            subscript_array[i] = value_as_long (arg2);
+         }
 
+       /* Internal type of array is arranged right to left */
+       for (i = 0; i < nargs; i++)
+         {
            retcode = f77_get_dynamic_upperbound (tmp_type, &upper);
            if (retcode == BOUND_FETCH_ERROR)
              error ("Cannot obtain dynamic upper bound");
@@ -1647,11 +1651,11 @@ evaluate_subexp_standard (struct type *expect_type,
            if (retcode == BOUND_FETCH_ERROR)
              error ("Cannot obtain dynamic lower bound");
 
-           array_size_array[i] = upper - lower + 1;
+           array_size_array[nargs - i - 1] = upper - lower + 1;
 
            /* Zero-normalize subscripts so that offsetting will work. */
 
-           subscript_array[i] -= lower;
+           subscript_array[nargs - i - 1] -= lower;
 
            /* If we are at the bottom of a multidimensional 
               array type then keep a ptr to the last ARRAY
@@ -1661,17 +1665,17 @@ evaluate_subexp_standard (struct type *expect_type,
               of base element type that we apply a simple 
               offset to. */
 
-           if (i < nargs)
+           if (i < nargs - 1)
              tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type));
          }
 
        /* Now let us calculate the offset for this item */
 
-       offset_item = subscript_array[ndimensions];
+       offset_item = subscript_array[ndimensions - 1];
 
-       for (i = ndimensions - 1; i >= 1; i--)
+       for (i = ndimensions - 1; i > 0; --i)
          offset_item =
-           array_size_array[i] * offset_item + subscript_array[i];
+           array_size_array[i - 1] * offset_item + subscript_array[i - 1];
 
        /* Construct a value node with the value of the offset */
 
index e354cad00e55b9cf09f4e3edb20470135e43f0d3..8430c97bdae4ceb41dcb37cf75c342114bb03770 100644 (file)
@@ -462,6 +462,7 @@ const struct language_defn f_language_defn =
   range_check_on,
   type_check_on,
   case_sensitive_off,
+  array_column_major,
   &exp_descriptor_standard,
   f_parse,                     /* parser */
   f_error,                     /* parser error function */
index 30a75c077ade50b4b3a8bd1e7b439e6c7ea8c7c3..fd0e712415c42b03e045e0254300e82086d78d18 100644 (file)
@@ -1088,6 +1088,7 @@ const struct language_defn java_language_defn =
   range_check_off,
   type_check_off,
   case_sensitive_on,
+  array_row_major,
   &exp_descriptor_java,
   java_parse,
   java_error,
index d1a1fb9aa6ace5b76c84196bce090cbd14a2685d..dfbfa3a6d265f6481f3ac52969c9853169b66ffe 100644 (file)
@@ -1294,6 +1294,7 @@ const struct language_defn unknown_language_defn =
   NULL,
   range_check_off,
   type_check_off,
+  array_row_major,
   case_sensitive_on,
   &exp_descriptor_standard,
   unk_lang_parser,
@@ -1333,6 +1334,7 @@ const struct language_defn auto_language_defn =
   NULL,
   range_check_off,
   type_check_off,
+  array_row_major,
   case_sensitive_on,
   &exp_descriptor_standard,
   unk_lang_parser,
@@ -1372,6 +1374,7 @@ const struct language_defn local_language_defn =
   range_check_off,
   type_check_off,
   case_sensitive_on,
+  array_row_major,
   &exp_descriptor_standard,
   unk_lang_parser,
   unk_lang_error,
index 489ca238634aa78fa723269fa52430a5ac5e61fc..98bdc3e1db97e158f718405e329e9450227155dc 100644 (file)
@@ -96,6 +96,17 @@ extern enum case_mode
   }
 case_mode;
 
+/* array_ordering ==
+   array_row_major:     Arrays are in row major order
+   array_column_major:  Arrays are in column major order.*/
+
+extern enum array_ordering
+  {
+    array_row_major, array_column_major
+  } 
+array_ordering;
+
+
 /* case_sensitivity ==
    case_sensitive_on:   Case sensitivity in name matching is used
    case_sensitive_off:  Case sensitivity in name matching is not used  */
@@ -187,6 +198,9 @@ struct language_defn
     /* Default case sensitivity */
     enum case_sensitivity la_case_sensitivity;
 
+    /* Multi-dimensional array ordering */
+    enum array_ordering la_array_ordering;
+
     /* Definitions related to expression printing, prefixifying, and
        dumping */
 
index 722805e2faf31e2839ef61a84c03679b97045ca2..746b2f4785e24e0bc66b9ef501613a812fdc92e7 100644 (file)
@@ -415,6 +415,7 @@ const struct language_defn m2_language_defn =
   range_check_on,
   type_check_on,
   case_sensitive_on,
+  array_row_major,
   &exp_descriptor_standard,
   m2_parse,                    /* parser */
   m2_error,                    /* parser error function */
index b9e48971533e99e8ad972b3e3d918e268876ee73..b02af1c236118700f6098e3307a6f58faed4e154 100644 (file)
@@ -659,6 +659,7 @@ const struct language_defn objc_language_defn = {
   range_check_off,
   type_check_off,
   case_sensitive_on,
+  array_row_major,
   &exp_descriptor_standard,
   objc_parse,
   objc_error,
index 115bfe106fa2843f0c38d39b0615e27bf0b8e87a..296a0ba51b9ea27d0dcecefa1258d0e9d9caec04 100644 (file)
@@ -451,6 +451,7 @@ const struct language_defn pascal_language_defn =
   range_check_on,
   type_check_on,
   case_sensitive_on,
+  array_row_major,
   &exp_descriptor_standard,
   pascal_parse,
   pascal_error,
index 4b1db1547ef886cbb6dd9d5710b0f247d73daff3..c459b813d997205b0501d2d679775aad6fa94a06 100644 (file)
@@ -248,6 +248,7 @@ const struct language_defn scm_language_defn =
   range_check_off,
   type_check_off,
   case_sensitive_off,
+  array_row_major,
   &exp_descriptor_scm,
   scm_parse,
   c_error,
This page took 0.039801 seconds and 4 git commands to generate.