This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Evaluating arrays in Fortran


This is a patch that makes the evaluation of arrays cause fewer
segmentation faults in Fortran subroutines where the parameter array
has a (*) as the bound.  The existing implementation allocates the
entire array and then finds the right element.  Unfortunately the (*)
is recorded as -1 in the symtab, which makes a very nasty malloc..
This new method is the same as how C arrays are handled.

Note there are still a few other Fortran array problems for
subroutines - incorrect indexing and other ways to cause seg faults,
this won't fix them, but it's a start..

Attached is a test program.  Put a break in subs, and print out
(*x)(10,3) -- without the patch, gdb seg faults soon after.  With the
patch it doesn't.


2003-10-08  David Lecomber  <dsl@sources.redhat.com>
 
        * eval.c (evaluate_subexp_standard): Don't allocate entire array
        locally to read array values in Fortran; allocate required element
        only.  Fixes some segmentation faults when printing array elements
        in Fortran subroutines where array bounds are undefined ie. *.
 
Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.38
diff -u -r1.38 eval.c
--- eval.c	25 Sep 2003 16:39:38 -0000	1.38
+++ eval.c	8 Oct 2003 22:05:39 -0000
@@ -1666,10 +1666,6 @@
 	  offset_item =
 	    array_size_array[i] * offset_item + subscript_array[i];
 
-	/* Construct a value node with the value of the offset */
-
-	arg2 = value_from_longest (builtin_type_f_integer, offset_item);
-
 	/* Let us now play a dirty trick: we will take arg1 
 	   which is a value node pointing to the topmost level
 	   of the multidimensional array-set and pretend
@@ -1678,7 +1674,16 @@
 	   returns the correct type value */
 
 	VALUE_TYPE (arg1) = tmp_type;
-	return value_ind (value_add (value_coerce_array (arg1), arg2));
+
+	f77_get_dynamic_lowerbound (tmp_type, &lower);
+
+	/* Lower will get subtracted off in value_subscript,
+	   hence add it here */
+
+	arg2 = value_from_longest (builtin_type_f_integer, 
+				   offset_item + lower);
+
+	return value_subscript (arg1, arg2);
       }
 
     case BINOP_LOGICAL_AND:


Attachment: test.f
Description: Text document


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