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 7306e88
Index: gdb-7.11.50.20160630/gdb/f-lang.h
Jan Kratochvil 92b52c5
===================================================================
Jan Kratochvil 7306e88
--- gdb-7.11.50.20160630.orig/gdb/f-lang.h	2016-07-16 10:56:11.682762722 +0200
Jan Kratochvil 7306e88
+++ gdb-7.11.50.20160630/gdb/f-lang.h	2016-07-16 10:56:15.554793704 +0200
Jan Kratochvil 7306e88
@@ -49,9 +49,9 @@
Jan Kratochvil 556378e
   struct symbol *contents[1];
Jan Kratochvil 556378e
 };
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 7306e88
Index: gdb-7.11.50.20160630/gdb/f-typeprint.c
Jan Kratochvil 92b52c5
===================================================================
Jan Kratochvil 7306e88
--- gdb-7.11.50.20160630.orig/gdb/f-typeprint.c	2016-07-16 10:56:11.682762722 +0200
Jan Kratochvil 7306e88
+++ gdb-7.11.50.20160630/gdb/f-typeprint.c	2016-07-16 10:56:43.795019660 +0200
Jan Kratochvil 7306e88
@@ -147,7 +147,7 @@
Jan Kratochvil 92b52c5
 			     int show, int passed_a_ptr, int demangled_args,
Jan Kratochvil 7306e88
 			     int arrayprint_recurse_level, int print_rank_only)
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 7306e88
@@ -194,7 +194,7 @@
Jan Kratochvil 7306e88
 	{
Jan Kratochvil 7306e88
 	  lower_bound = f77_get_lowerbound (type);
Jan Kratochvil 7306e88
 	  if (lower_bound != 1)	/* Not the default.  */
Jan Kratochvil 7306e88
-	    fprintf_filtered (stream, "%d:", lower_bound);
Jan Kratochvil 7306e88
+	    fprintf_filtered (stream, "%s:", plongest (lower_bound));
Jan Kratochvil eb6cb2d
 
Jan Kratochvil 7306e88
 	  /* Make sure that, if we have an assumed size array, we
Jan Kratochvil 7306e88
 	     print out a warning and print the upperbound as '*'.  */
Jan Kratochvil 7306e88
@@ -204,7 +204,7 @@
Jan Kratochvil 7306e88
 	  else
Jan Kratochvil 7306e88
 	    {
Jan Kratochvil 7306e88
 	      upper_bound = f77_get_upperbound (type);
Jan Kratochvil 7306e88
-	      fprintf_filtered (stream, "%d", upper_bound);
Jan Kratochvil 7306e88
+	      fprintf_filtered (stream, "%s", plongest (upper_bound));
Jan Kratochvil 7306e88
 	    }
Jan Kratochvil 7306e88
 	}
Jan Kratochvil eb6cb2d
 
Jan Kratochvil 7306e88
@@ -276,7 +276,7 @@
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 7306e88
@@ -358,7 +358,7 @@
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 7306e88
Index: gdb-7.11.50.20160630/gdb/f-valprint.c
Jan Kratochvil 92b52c5
===================================================================
Jan Kratochvil 7306e88
--- gdb-7.11.50.20160630.orig/gdb/f-valprint.c	2016-07-16 10:56:11.682762722 +0200
Jan Kratochvil 7306e88
+++ gdb-7.11.50.20160630/gdb/f-valprint.c	2016-07-16 10:56:15.554793704 +0200
Jan Kratochvil 7306e88
@@ -43,7 +43,7 @@
Jan Kratochvil eb6cb2d
 /* Array which holds offsets to be applied to get a row's elements
Jan Kratochvil eb6cb2d
    for a given array.  Array also holds the size of each subarray.  */
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 eb6cb2d
   if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
Jan Kratochvil 7306e88
@@ -52,7 +52,7 @@
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 eb6cb2d
   if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))