This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project. See the GDB home page for more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Fortran array patch



There is a bad bug in the code that prints array elements of a fortran
program-- the upper and lower array bounds are extracted in the opposite
order from that of the subscripts, meaning that a bad address is
calculated.  The patch is against the stable gdb-4.17 release. 


--- eval.c.orig	Mon Jan  4 16:48:13 1999
+++ eval.c	Mon Jan  4 17:41:31 1999
@@ -1188,6 +1188,7 @@
 	int subscript_array[MAX_FORTRAN_DIMS+1]; /* 1-based array of 
 						    subscripts, max == 7 */
 	int array_size_array[MAX_FORTRAN_DIMS+1];
+	int upper_bound[MAX_FORTRAN_DIMS+1], lower_bound[MAX_FORTRAN_DIMS+1];
 	int ndimensions=1,i;
 	struct type *tmp_type; 
 	int offset_item;   /* The array offset where the item lives */ 
@@ -1222,11 +1223,10 @@
 	    if (retcode == BOUND_FETCH_ERROR)
 	      error("Cannot obtain dynamic lower bound"); 
 
-	    array_size_array[i] = upper - lower + 1;
-               
-	    /* Zero-normalize subscripts so that offsetting will work. */ 
-               
-	    subscript_array[i] -= lower;
+	    /* Bounds are fetched in reverse order of the subscripts */
+
+	    upper_bound[nargs + 1 - i] = upper;
+	    lower_bound[nargs + 1 - i] = lower;
 
 	    /* If we are at the bottom of a multidimensional 
 	       array type then keep a ptr to the last ARRAY
@@ -1238,6 +1238,17 @@
 
 	    if (i < nargs) 
 	      tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type)); 
+	  }
+
+	/* Calculate size of each dimension */
+
+	for (i = 1; i <= nargs; i++)
+	  {
+	    array_size_array[i] = upper_bound[i] - lower_bound[i] + 1;
+               
+	    /* Zero-normalize subscripts so that offsetting will work. */ 
+               
+	    subscript_array[i] -= lower_bound[i];
 	  }
 
 	/* Now let us calculate the offset for this item */



       Andy


-----------------                        XOLD(K,IC,I)=
Andy Vaught               ....        DO ITERS=1, 10  XOLD(K,IC,I)
andy@maxwell.la.asu.edu   |  |   /CALLMSOLVE(A,B,X,I,ITERS,TOL)+(RANNYU(0)
Arizona State University  ======|WRITE(6,'(I5,2X,F12.6)')ITERS,TOL -HALF)
Tempe, Arizona USA        OOOOOO \ENDDORETURN PARAMETER(ZERO=1.D0)*TENTH*DELTA