Jan Kratochvil 92b52c5
http://sourceware.org/ml/gdb-patches/2012-08/msg00562.html
Jan Kratochvil 92b52c5
Subject: [PATCH] Expand fortran array bounds sizes to LONGEST
Jan Kratochvil 92b52c5
Jan Kratochvil 92b52c5
Jan Kratochvil 92b52c5
--MP_/90J7bck2fqDySEX9JkZtaqL
Jan Kratochvil 92b52c5
Content-Type: text/plain; charset=US-ASCII
Jan Kratochvil 92b52c5
Content-Transfer-Encoding: 7bit
Jan Kratochvil 92b52c5
Content-Disposition: inline
Jan Kratochvil 92b52c5
Jan Kratochvil 92b52c5
Hi,
Jan Kratochvil 92b52c5
Jan Kratochvil 92b52c5
Range bounds for a gdb type can have LONGEST values for low and high
Jan Kratochvil 92b52c5
bounds. Fortran range bounds functions however use only int. The larger
Jan Kratochvil 92b52c5
ranges don't compile by default on gcc, but it is possible to override
Jan Kratochvil 92b52c5
the check in the compiler by using -fno-range-check. As a result, this
Jan Kratochvil 92b52c5
check is necessary so that we don't print junk in case of an overflow.
Jan Kratochvil 92b52c5
Jan Kratochvil 92b52c5
Attached patch does this expansion and also includes a test case that
Jan Kratochvil 92b52c5
verifies that the problem is fixed. I have also verified on x86_64 that
Jan Kratochvil 92b52c5
this patch does not cause any regressions.
Jan Kratochvil 92b52c5
Jan Kratochvil 92b52c5
Regards,
Jan Kratochvil 92b52c5
Siddhesh
Jan Kratochvil 92b52c5
Jan Kratochvil 92b52c5
gdb/ChangeLog:
Jan Kratochvil 92b52c5
Jan Kratochvil 92b52c5
	* f-lang.h (f77_get_upperbound): Return LONGEST.
Jan Kratochvil 92b52c5
	(f77_get_lowerbound): Likewise.
Jan Kratochvil 92b52c5
	* f-typeprint.c (f_type_print_varspec_suffix): Expand
Jan Kratochvil 92b52c5
	UPPER_BOUND and LOWER_BOUND to LONGEST.  Use plongest to format
Jan Kratochvil 92b52c5
	print them.
Jan Kratochvil 92b52c5
	(f_type_print_base): Expand UPPER_BOUND to LONGEST.  Use
Jan Kratochvil 92b52c5
	plongest to format print it.
Jan Kratochvil 92b52c5
	* f-valprint.c (f77_get_lowerbound): Return LONGEST.
Jan Kratochvil 92b52c5
	(f77_get_upperbound): Likewise.
Jan Kratochvil 92b52c5
	(f77_get_dynamic_length_of_aggregate): Expand UPPER_BOUND,
Jan Kratochvil 92b52c5
	LOWER_BOUND to LONGEST.
Jan Kratochvil 92b52c5
	(f77_create_arrayprint_offset_tbl): Likewise.
Jan Kratochvil 92b52c5
Jan Kratochvil 92b52c5
testsuite/ChangeLog:
Jan Kratochvil 92b52c5
Jan Kratochvil 92b52c5
	* gdb.fortran/array-bounds.exp: New test case.
Jan Kratochvil 92b52c5
	* gdb.fortran/array-bounds.f: New test case.
Jan Kratochvil 92b52c5
Jan Kratochvil 92b52c5
--MP_/90J7bck2fqDySEX9JkZtaqL
Jan Kratochvil 92b52c5
Content-Type: text/x-patch
Jan Kratochvil 92b52c5
Content-Transfer-Encoding: 7bit
Jan Kratochvil 92b52c5
Content-Disposition: attachment; filename=f77-bounds.patch
Jan Kratochvil 92b52c5
Jan Kratochvil 92b52c5
Index: gdb-7.5.0.20120926/gdb/f-lang.h
Jan Kratochvil 92b52c5
===================================================================
Jan Kratochvil 92b52c5
--- gdb-7.5.0.20120926.orig/gdb/f-lang.h	2012-11-07 22:12:39.000000000 +0100
Jan Kratochvil 92b52c5
+++ gdb-7.5.0.20120926/gdb/f-lang.h	2012-11-07 22:52:02.688632498 +0100
Jan Kratochvil 92b52c5
@@ -66,9 +66,9 @@ enum f90_range_type
Jan Kratochvil 92b52c5
 extern char *real_main_name;	/* Name of main function.  */
Jan Kratochvil 92b52c5
 extern int real_main_c_value;	/* C_value field of main function.  */
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
-extern int f77_get_upperbound (struct type *);
Jan Kratochvil 92b52c5
+extern LONGEST f77_get_upperbound (struct type *);
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
-extern int f77_get_lowerbound (struct type *);
Jan Kratochvil 92b52c5
+extern LONGEST f77_get_lowerbound (struct type *);
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
 extern void f77_get_dynamic_array_length (struct type *);
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
Index: gdb-7.5.0.20120926/gdb/f-typeprint.c
Jan Kratochvil 92b52c5
===================================================================
Jan Kratochvil 92b52c5
--- gdb-7.5.0.20120926.orig/gdb/f-typeprint.c	2012-11-07 22:00:41.000000000 +0100
Jan Kratochvil 92b52c5
+++ gdb-7.5.0.20120926/gdb/f-typeprint.c	2012-11-07 22:52:02.689632497 +0100
Jan Kratochvil 92b52c5
@@ -182,7 +182,7 @@ f_type_print_varspec_suffix (struct type
Jan Kratochvil 92b52c5
 			     int show, int passed_a_ptr, int demangled_args,
Jan Kratochvil 92b52c5
 			     int arrayprint_recurse_level)
Jan Kratochvil 92b52c5
 {
Jan Kratochvil 92b52c5
-  int upper_bound, lower_bound;
Jan Kratochvil 92b52c5
+  LONGEST upper_bound, lower_bound;
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
   /* No static variables are permitted as an error call may occur during
Jan Kratochvil 92b52c5
      execution of this function.  */
Jan Kratochvil 92b52c5
@@ -212,7 +212,7 @@ f_type_print_varspec_suffix (struct type
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
       lower_bound = f77_get_lowerbound (type);
Jan Kratochvil 92b52c5
       if (lower_bound != 1)	/* Not the default.  */
Jan Kratochvil 92b52c5
-	fprintf_filtered (stream, "%d:", lower_bound);
Jan Kratochvil 92b52c5
+	fprintf_filtered (stream, "%s:", plongest (lower_bound));
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
       /* Make sure that, if we have an assumed size array, we
Jan Kratochvil 92b52c5
          print out a warning and print the upperbound as '*'.  */
Jan Kratochvil 92b52c5
@@ -222,7 +222,7 @@ f_type_print_varspec_suffix (struct type
Jan Kratochvil 92b52c5
       else
Jan Kratochvil 92b52c5
 	{
Jan Kratochvil 92b52c5
 	  upper_bound = f77_get_upperbound (type);
Jan Kratochvil 92b52c5
-	  fprintf_filtered (stream, "%d", upper_bound);
Jan Kratochvil 92b52c5
+	  fprintf_filtered (stream, "%s", plongest (upper_bound));
Jan Kratochvil 92b52c5
 	}
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY)
Jan Kratochvil 92b52c5
@@ -291,7 +291,7 @@ void
Jan Kratochvil 92b52c5
 f_type_print_base (struct type *type, struct ui_file *stream, int show,
Jan Kratochvil 92b52c5
 		   int level)
Jan Kratochvil 92b52c5
 {
Jan Kratochvil 92b52c5
-  int upper_bound;
Jan Kratochvil 92b52c5
+  LONGEST upper_bound;
Jan Kratochvil 92b52c5
   int index;
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
   QUIT;
Jan Kratochvil 92b52c5
@@ -373,7 +373,7 @@ f_type_print_base (struct type *type, st
Jan Kratochvil 92b52c5
       else
Jan Kratochvil 92b52c5
 	{
Jan Kratochvil 92b52c5
 	  upper_bound = f77_get_upperbound (type);
Jan Kratochvil 92b52c5
-	  fprintf_filtered (stream, "character*%d", upper_bound);
Jan Kratochvil 92b52c5
+	  fprintf_filtered (stream, "character*%s", plongest (upper_bound));
Jan Kratochvil 92b52c5
 	}
Jan Kratochvil 92b52c5
       break;
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
Index: gdb-7.5.0.20120926/gdb/f-valprint.c
Jan Kratochvil 92b52c5
===================================================================
Jan Kratochvil 92b52c5
--- gdb-7.5.0.20120926.orig/gdb/f-valprint.c	2012-11-07 22:09:29.000000000 +0100
Jan Kratochvil 92b52c5
+++ gdb-7.5.0.20120926/gdb/f-valprint.c	2012-11-07 22:52:21.888604907 +0100
Jan Kratochvil 92b52c5
@@ -57,7 +57,7 @@ LONGEST f77_array_offset_tbl[MAX_FORTRAN
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
 #define F77_DIM_BYTE_STRIDE(n) (f77_array_offset_tbl[n][0])
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
-int
Jan Kratochvil 92b52c5
+LONGEST
Jan Kratochvil 92b52c5
 f77_get_lowerbound (struct type *type)
Jan Kratochvil 92b52c5
 {
Jan Kratochvil 92b52c5
   f_object_address_data_valid_or_error (type);
Jan Kratochvil 92b52c5
@@ -68,7 +68,7 @@ f77_get_lowerbound (struct type *type)
Jan Kratochvil 92b52c5
   return TYPE_ARRAY_LOWER_BOUND_VALUE (type);
Jan Kratochvil 92b52c5
 }
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
-int
Jan Kratochvil 92b52c5
+LONGEST
Jan Kratochvil 92b52c5
 f77_get_upperbound (struct type *type)
Jan Kratochvil 92b52c5
 {
Jan Kratochvil 92b52c5
   f_object_address_data_valid_or_error (type);
Jan Kratochvil 92b52c5
@@ -92,8 +92,8 @@ f77_get_upperbound (struct type *type)
Jan Kratochvil 92b52c5
 static void
Jan Kratochvil 92b52c5
 f77_get_dynamic_length_of_aggregate (struct type *type)
Jan Kratochvil 92b52c5
 {
Jan Kratochvil 92b52c5
-  int upper_bound = -1;
Jan Kratochvil 92b52c5
-  int lower_bound = 1;
Jan Kratochvil 92b52c5
+  LONGEST upper_bound = -1;
Jan Kratochvil 92b52c5
+  LONGEST lower_bound = 1;
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
   /* Recursively go all the way down into a possibly multi-dimensional
Jan Kratochvil 92b52c5
      F77 array and get the bounds.  For simple arrays, this is pretty
Jan Kratochvil 92b52c5
@@ -128,7 +128,7 @@ f77_create_arrayprint_offset_tbl (struct
Jan Kratochvil 92b52c5
   struct type *tmp_type;
Jan Kratochvil 92b52c5
   LONGEST eltlen;
Jan Kratochvil 92b52c5
   int ndimen = 1;
Jan Kratochvil 92b52c5
-  int upper, lower;
Jan Kratochvil 92b52c5
+  LONGEST upper, lower;
Jan Kratochvil 92b52c5
 
Jan Kratochvil 92b52c5
   tmp_type = type;
Jan Kratochvil 92b52c5