public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Multi-dimensional Fortran arrays issue PR11104
@ 2010-09-16 17:26 Andrew Burgess
  2010-10-18  7:53 ` Andrew Burgess
  0 siblings, 1 reply; 11+ messages in thread
From: Andrew Burgess @ 2010-09-16 17:26 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 546 bytes --]

The attached patch fixes issue PR11104 (http://sourceware.org/bugzilla/show_bug.cgi?id=11104 ), relating to printing multidimensional Fortran arrays.

This has also been mentioned on the gdb list recently: http://sourceware.org/ml/gdb/2010-09/msg00004.html

The tar file contains a test case for this issue, it adds two files to gdb/testsuite/gdb.fortran .

If people think that it looks sane then could it be applied please, or let me know if there are any changes needed, I've not submitted many patches before.


Thanks,
Andrew



[-- Attachment #2: arrays2.patch --]
[-- Type: application/octet-stream, Size: 4128 bytes --]

Index: gdb/eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.139
diff -c -p -r1.139 eval.c
*** gdb/eval.c	11 Aug 2010 16:48:26 -0000	1.139
--- gdb/eval.c	16 Sep 2010 07:54:41 -0000
*************** evaluate_subexp_standard (struct type *e
*** 2306,2321 ****
  
  	    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
! 	       type around for use when calling value_subscript()
! 	       below. This is done because we pretend to value_subscript
! 	       that we actually have a one-dimensional array 
! 	       of base element type that we apply a simple 
! 	       offset to. */
! 
! 	    if (i < nargs - 1)
! 	      tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type));
  	  }
  
  	/* Now let us calculate the offset for this item */
--- 2306,2312 ----
  
  	    subscript_array[nargs - i - 1] -= lower;
  
! 	    tmp_type = check_typedef (TYPE_TARGET_TYPE (tmp_type));
  	  }
  
  	/* Now let us calculate the offset for this item */
*************** evaluate_subexp_standard (struct type *e
*** 2326,2339 ****
  	  offset_item =
  	    array_size_array[i - 1] * offset_item + subscript_array[i - 1];
  
- 	/* 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
- 	   that it is actually a array of the final element 
- 	   type, this will ensure that value_subscript()
- 	   returns the correct type value */
- 
- 	deprecated_set_value_type (arg1, tmp_type);
  	return value_subscripted_rvalue (arg1, offset_item, 0);
        }
  
--- 2317,2322 ----
Index: gdb/valarith.c
===================================================================
RCS file: /cvs/src/src/gdb/valarith.c,v
retrieving revision 1.86
diff -c -p -r1.86 valarith.c
*** gdb/valarith.c	11 Aug 2010 16:48:26 -0000	1.86
--- gdb/valarith.c	16 Sep 2010 07:54:42 -0000
*************** struct value *
*** 193,202 ****
  value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
  {
    struct type *array_type = check_typedef (value_type (array));
!   struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
!   unsigned int elt_size = TYPE_LENGTH (elt_type);
!   unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
    struct value *v;
  
    if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
  			     && elt_offs >= TYPE_LENGTH (array_type)))
--- 193,211 ----
  value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
  {
    struct type *array_type = check_typedef (value_type (array));
!   struct type *elt_type = array_type; 
!   unsigned int elt_size, elt_offs;
    struct value *v;
+   
+   /* Peel of the array indices until we reach the array element type */
+   do {
+     elt_type = TYPE_TARGET_TYPE(elt_type);
+   }
+   while ( TYPE_CODE(elt_type) == TYPE_CODE_ARRAY);
+ 
+   elt_type = check_typedef(elt_type);
+   elt_size = TYPE_LENGTH (elt_type);
+   elt_offs = elt_size * longest_to_int (index - lowerbound);
  
    if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
  			     && elt_offs >= TYPE_LENGTH (array_type)))
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/ChangeLog,v
retrieving revision 1.928
diff -c -p -r1.928 ChangeLog
*** ChangeLog	18 Jul 2010 08:12:39 -0000	1.928
--- ChangeLog	16 Sep 2010 08:00:41 -0000
***************
*** 1,3 ****
--- 1,13 ----
+ 2010-09-16 Andrew Burgess <aburgess@broadcom.com>
+ 
+  	* valarith.c (value_subscripted_rvalue) Walk through
+  	multi-dimensional arrays to find the element type for the
+  	array. Allows the upper bound check to work with multi-dimensional
+  	arrays.
+  	* eval.c (evaluate_subexp_standard) Remove hack from
+  	multi_f77_subscript case now that multi-dimensional arrays are
+  	supported in valarith.c
+ 
  2010-07-17  Jack Howarth  <howarth@bromo.med.uc.edu>
  
  	PR target/44862

[-- Attachment #3: multi-dim.tar.bz2 --]
[-- Type: application/octet-stream, Size: 1446 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2010-11-23 19:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-16 17:26 [PATCH] Multi-dimensional Fortran arrays issue PR11104 Andrew Burgess
2010-10-18  7:53 ` Andrew Burgess
2010-10-18 21:20   ` Jan Kratochvil
2010-10-19 16:23     ` Andrew Burgess
2010-11-17  8:45       ` Andrew Burgess
2010-11-22  7:10         ` Jan Kratochvil
2010-11-23  8:02         ` Jan Kratochvil
2010-11-23 10:04           ` Andrew Burgess
2010-11-23 17:23             ` Jan Kratochvil
2010-11-23 19:10               ` Jan Kratochvil
2010-10-18 21:21   ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).