This is the mail archive of the gdb-patches@sourceware.org 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] gdb can't print array element for fortran


Hello,

Gdb fails to print values of array elements of a fortran array passed to a function. On attempting to print the value, the 
following error appears : "no such vector element"

Steps to reproduce :

$ cat test.f

	real x(3)
        x(1)=25.0
        x(2)=24.0
        x(3)=23.0
        call this(x,3)
        end
        subroutine this(y,n)
        real y(n)
        print *,y
        end

0. gfortran -g test.f -o test
1. gdb ./test
2. break this
3. run
4. print y(1)

(gdb) print y(1)
no such vector element


The issue here is because in fortran, an array passed to a function is considered as a variable size array. gdb didn't 
know what the upper bound was and set it to -1 and subsequently set the array length to 0. This was caught in value_subscripted_rvalue
while checking if the element offset was greater than or equal to the array length.

The below patch fixes this by identifying this when the array type is created by gdb and dealing with it when we get 
to the point of retrieving the array elements.



Signed-off by: Vinay Sridhar <vinay@linux.vnet.ibm.com>

diff -Nuarp gdb_orig/gdb/gdbtypes.c gdb/gdb/gdbtypes.c
--- gdb_orig/gdb/gdbtypes.c	2009-01-03 11:27:51.000000000 +0530
+++ gdb/gdb/gdbtypes.c	2009-01-09 16:46:56.000000000 +0530
@@ -824,8 +824,14 @@ create_array_type (struct type *result_t
   /* Be careful when setting the array length.  Ada arrays can be
      empty arrays with the high_bound being smaller than the low_bound.
      In such cases, the array length should be zero.  */
-  if (high_bound < low_bound)
-    TYPE_LENGTH (result_type) = 0;
+  if (high_bound < low_bound) {
+  /* First check if we're dealing with a variable size array. If so, 
+     set length to -1 so we can deal with it later.  */
+    if (high_bound == -1)
+        TYPE_LENGTH (result_type) = -1;
+    else
+        TYPE_LENGTH (result_type) = 0;
+  }
   else
     TYPE_LENGTH (result_type) =
       TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
diff -Nuarp gdb_orig/gdb/valarith.c gdb/gdb/valarith.c
--- gdb_orig/gdb/valarith.c	2009-01-03 11:27:54.000000000 +0530
+++ gdb/gdb/valarith.c	2009-01-09 16:51:05.000000000 +0530
@@ -222,8 +222,9 @@ value_subscripted_rvalue (struct value *
   LONGEST index = value_as_long (idx);
   unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
   struct value *v;
+  int arr_size = TYPE_LENGTH (array_type);
 
-  if (index < lowerbound || elt_offs >= TYPE_LENGTH (array_type))
+  if (index < lowerbound || (arr_size != -1 && elt_offs >= arr_size))
     error (_("no such vector element"));
 
   v = allocate_value (elt_type);


---
Vinay Sridhar,
Linux Technology Centre,
IBM ISTL,
Bangalore, India


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