92b52c5
http://sourceware.org/ml/gdb-patches/2012-08/msg00562.html
92b52c5
Subject: [PATCH] Expand fortran array bounds sizes to LONGEST
92b52c5
92b52c5
92b52c5
--MP_/90J7bck2fqDySEX9JkZtaqL
92b52c5
Content-Type: text/plain; charset=US-ASCII
92b52c5
Content-Transfer-Encoding: 7bit
92b52c5
Content-Disposition: inline
92b52c5
92b52c5
Hi,
92b52c5
92b52c5
Range bounds for a gdb type can have LONGEST values for low and high
92b52c5
bounds. Fortran range bounds functions however use only int. The larger
92b52c5
ranges don't compile by default on gcc, but it is possible to override
92b52c5
the check in the compiler by using -fno-range-check. As a result, this
92b52c5
check is necessary so that we don't print junk in case of an overflow.
92b52c5
92b52c5
Attached patch does this expansion and also includes a test case that
92b52c5
verifies that the problem is fixed. I have also verified on x86_64 that
92b52c5
this patch does not cause any regressions.
92b52c5
92b52c5
Regards,
92b52c5
Siddhesh
92b52c5
92b52c5
gdb/ChangeLog:
92b52c5
92b52c5
	* f-lang.h (f77_get_upperbound): Return LONGEST.
92b52c5
	(f77_get_lowerbound): Likewise.
92b52c5
	* f-typeprint.c (f_type_print_varspec_suffix): Expand
92b52c5
	UPPER_BOUND and LOWER_BOUND to LONGEST.  Use plongest to format
92b52c5
	print them.
92b52c5
	(f_type_print_base): Expand UPPER_BOUND to LONGEST.  Use
92b52c5
	plongest to format print it.
92b52c5
	* f-valprint.c (f77_get_lowerbound): Return LONGEST.
92b52c5
	(f77_get_upperbound): Likewise.
92b52c5
	(f77_get_dynamic_length_of_aggregate): Expand UPPER_BOUND,
92b52c5
	LOWER_BOUND to LONGEST.
92b52c5
	(f77_create_arrayprint_offset_tbl): Likewise.
92b52c5
92b52c5
testsuite/ChangeLog:
92b52c5
92b52c5
	* gdb.fortran/array-bounds.exp: New test case.
92b52c5
	* gdb.fortran/array-bounds.f: New test case.
92b52c5
92b52c5
--MP_/90J7bck2fqDySEX9JkZtaqL
92b52c5
Content-Type: text/x-patch
92b52c5
Content-Transfer-Encoding: 7bit
92b52c5
Content-Disposition: attachment; filename=f77-bounds.patch
92b52c5
d258670
Index: gdb-7.11.90.20160907/gdb/f-lang.h
92b52c5
===================================================================
d258670
--- gdb-7.11.90.20160907.orig/gdb/f-lang.h	2016-09-07 21:48:33.308624019 +0200
d258670
+++ gdb-7.11.90.20160907/gdb/f-lang.h	2016-09-07 21:48:40.967692469 +0200
7306e88
@@ -49,9 +49,9 @@
556378e
   struct symbol *contents[1];
556378e
 };
92b52c5
 
92b52c5
-extern int f77_get_upperbound (struct type *);
92b52c5
+extern LONGEST f77_get_upperbound (struct type *);
92b52c5
 
92b52c5
-extern int f77_get_lowerbound (struct type *);
92b52c5
+extern LONGEST f77_get_lowerbound (struct type *);
92b52c5
 
92b52c5
 extern void f77_get_dynamic_array_length (struct type *);
92b52c5
 
d258670
Index: gdb-7.11.90.20160907/gdb/f-typeprint.c
92b52c5
===================================================================
d258670
--- gdb-7.11.90.20160907.orig/gdb/f-typeprint.c	2016-09-07 21:48:33.309624028 +0200
d258670
+++ gdb-7.11.90.20160907/gdb/f-typeprint.c	2016-09-07 21:48:40.967692469 +0200
7306e88
@@ -147,7 +147,7 @@
92b52c5
 			     int show, int passed_a_ptr, int demangled_args,
7306e88
 			     int arrayprint_recurse_level, int print_rank_only)
92b52c5
 {
92b52c5
-  int upper_bound, lower_bound;
92b52c5
+  LONGEST upper_bound, lower_bound;
92b52c5
 
92b52c5
   /* No static variables are permitted as an error call may occur during
92b52c5
      execution of this function.  */
7306e88
@@ -194,7 +194,7 @@
7306e88
 	{
7306e88
 	  lower_bound = f77_get_lowerbound (type);
7306e88
 	  if (lower_bound != 1)	/* Not the default.  */
7306e88
-	    fprintf_filtered (stream, "%d:", lower_bound);
7306e88
+	    fprintf_filtered (stream, "%s:", plongest (lower_bound));
eb6cb2d
 
7306e88
 	  /* Make sure that, if we have an assumed size array, we
d258670
 	       print out a warning and print the upperbound as '*'.  */
7306e88
@@ -204,7 +204,7 @@
7306e88
 	  else
7306e88
 	    {
7306e88
 	      upper_bound = f77_get_upperbound (type);
7306e88
-	      fprintf_filtered (stream, "%d", upper_bound);
7306e88
+	      fprintf_filtered (stream, "%s", plongest (upper_bound));
7306e88
 	    }
7306e88
 	}
eb6cb2d
 
7306e88
@@ -276,7 +276,7 @@
92b52c5
 f_type_print_base (struct type *type, struct ui_file *stream, int show,
92b52c5
 		   int level)
92b52c5
 {
92b52c5
-  int upper_bound;
92b52c5
+  LONGEST upper_bound;
92b52c5
   int index;
92b52c5
 
92b52c5
   QUIT;
7306e88
@@ -358,7 +358,7 @@
92b52c5
       else
92b52c5
 	{
92b52c5
 	  upper_bound = f77_get_upperbound (type);
92b52c5
-	  fprintf_filtered (stream, "character*%d", upper_bound);
92b52c5
+	  fprintf_filtered (stream, "character*%s", plongest (upper_bound));
92b52c5
 	}
92b52c5
       break;
92b52c5
 
d258670
Index: gdb-7.11.90.20160907/gdb/f-valprint.c
92b52c5
===================================================================
d258670
--- gdb-7.11.90.20160907.orig/gdb/f-valprint.c	2016-09-07 21:48:33.309624028 +0200
d258670
+++ gdb-7.11.90.20160907/gdb/f-valprint.c	2016-09-07 21:48:40.967692469 +0200
7306e88
@@ -43,7 +43,7 @@
eb6cb2d
 /* Array which holds offsets to be applied to get a row's elements
eb6cb2d
    for a given array.  Array also holds the size of each subarray.  */
92b52c5
 
92b52c5
-int
92b52c5
+LONGEST
92b52c5
 f77_get_lowerbound (struct type *type)
92b52c5
 {
eb6cb2d
   if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
7306e88
@@ -52,7 +52,7 @@
92b52c5
   return TYPE_ARRAY_LOWER_BOUND_VALUE (type);
92b52c5
 }
92b52c5
 
92b52c5
-int
92b52c5
+LONGEST
92b52c5
 f77_get_upperbound (struct type *type)
92b52c5
 {
eb6cb2d
   if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))