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] Expand fortran array bounds sizes to LONGEST


Hi,

Range bounds for a gdb type can have LONGEST values for low and high
bounds. Fortran range bounds functions however use only int. The larger
ranges don't compile by default on gcc, but it is possible to override
the check in the compiler by using -fno-range-check. As a result, this
check is necessary so that we don't print junk in case of an overflow.

Attached patch does this expansion and also includes a test case that
verifies that the problem is fixed. I have also verified on x86_64 that
this patch does not cause any regressions.

Regards,
Siddhesh

gdb/ChangeLog:

	* f-lang.h (f77_get_upperbound): Return LONGEST.
	(f77_get_lowerbound): Likewise.
	* f-typeprint.c (f_type_print_varspec_suffix): Expand
	UPPER_BOUND and LOWER_BOUND to LONGEST.  Use plongest to format
	print them.
	(f_type_print_base): Expand UPPER_BOUND to LONGEST.  Use
	plongest to format print it.
	* f-valprint.c (f77_get_lowerbound): Return LONGEST.
	(f77_get_upperbound): Likewise.
	(f77_get_dynamic_length_of_aggregate): Expand UPPER_BOUND,
	LOWER_BOUND to LONGEST.
	(f77_create_arrayprint_offset_tbl): Likewise.

testsuite/ChangeLog:

	* gdb.fortran/array-bounds.exp: New test case.
	* gdb.fortran/array-bounds.f: New test case.
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
index d20a46f..46ea267 100644
--- a/gdb/f-lang.h
+++ b/gdb/f-lang.h
@@ -96,9 +96,9 @@ extern SAVED_F77_COMMON_PTR find_common_for_function (const char *,
 extern char *real_main_name;	/* Name of main function.  */
 extern int real_main_c_value;	/* C_value field of main function.  */
 
-extern int f77_get_upperbound (struct type *);
+extern LONGEST f77_get_upperbound (struct type *);
 
-extern int f77_get_lowerbound (struct type *);
+extern LONGEST f77_get_lowerbound (struct type *);
 
 extern void f77_get_dynamic_array_length (struct type *);
 
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index c59e639..f6877fa 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -150,7 +150,7 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
 			     int show, int passed_a_ptr, int demangled_args,
 			     int arrayprint_recurse_level)
 {
-  int upper_bound, lower_bound;
+  LONGEST upper_bound, lower_bound;
 
   /* No static variables are permitted as an error call may occur during
      execution of this function.  */
@@ -177,7 +177,7 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
 
       lower_bound = f77_get_lowerbound (type);
       if (lower_bound != 1)	/* Not the default.  */
-	fprintf_filtered (stream, "%d:", lower_bound);
+	fprintf_filtered (stream, "%s:", plongest (lower_bound));
 
       /* Make sure that, if we have an assumed size array, we
          print out a warning and print the upperbound as '*'.  */
@@ -187,7 +187,7 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
       else
 	{
 	  upper_bound = f77_get_upperbound (type);
-	  fprintf_filtered (stream, "%d", upper_bound);
+	  fprintf_filtered (stream, "%s", plongest (upper_bound));
 	}
 
       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_ARRAY)
@@ -255,7 +255,7 @@ void
 f_type_print_base (struct type *type, struct ui_file *stream, int show,
 		   int level)
 {
-  int upper_bound;
+  LONGEST upper_bound;
   int index;
 
   QUIT;
@@ -337,7 +337,7 @@ f_type_print_base (struct type *type, struct ui_file *stream, int show,
       else
 	{
 	  upper_bound = f77_get_upperbound (type);
-	  fprintf_filtered (stream, "character*%d", upper_bound);
+	  fprintf_filtered (stream, "character*%s", plongest (upper_bound));
 	}
       break;
 
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index a422ac2..b4ce356 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -60,7 +60,7 @@ LONGEST f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
 
 #define F77_DIM_OFFSET(n) (f77_array_offset_tbl[n][0])
 
-int
+LONGEST
 f77_get_lowerbound (struct type *type)
 {
   if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
@@ -69,7 +69,7 @@ f77_get_lowerbound (struct type *type)
   return TYPE_ARRAY_LOWER_BOUND_VALUE (type);
 }
 
-int
+LONGEST
 f77_get_upperbound (struct type *type)
 {
   if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
@@ -90,8 +90,8 @@ f77_get_upperbound (struct type *type)
 static void
 f77_get_dynamic_length_of_aggregate (struct type *type)
 {
-  int upper_bound = -1;
-  int lower_bound = 1;
+  LONGEST upper_bound = -1;
+  LONGEST lower_bound = 1;
 
   /* Recursively go all the way down into a possibly multi-dimensional
      F77 array and get the bounds.  For simple arrays, this is pretty
@@ -126,7 +126,7 @@ f77_create_arrayprint_offset_tbl (struct type *type, struct ui_file *stream)
   struct type *tmp_type;
   LONGEST eltlen;
   int ndimen = 1;
-  int upper, lower;
+  LONGEST upper, lower;
 
   tmp_type = type;
 
diff --git a/gdb/testsuite/gdb.fortran/array-bounds.exp b/gdb/testsuite/gdb.fortran/array-bounds.exp
new file mode 100644
index 0000000..68873fe
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/array-bounds.exp
@@ -0,0 +1,35 @@
+# Copyright 2012 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the gdb testsuite.  It contains test to ensure that
+# array bounds accept LONGEST.
+
+if { [skip_fortran_tests] } { return -1 }
+
+standard_testfile .f
+
+if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug additional_flags=-fno-range-check f90}]} {
+    print "compile failed"
+    return -1
+}
+
+if { ![runto MAIN__] } {
+    perror "Could not run to breakpoint `MAIN__'."
+    continue
+}
+
+gdb_test "print &foo" {.*\(4294967296:4294967297\).*}
+gdb_test "print &bar" {.*\(-4294967297:-4294967296\).*}
+
diff --git a/gdb/testsuite/gdb.fortran/array-bounds.f b/gdb/testsuite/gdb.fortran/array-bounds.f
new file mode 100644
index 0000000..a43184c
--- /dev/null
+++ b/gdb/testsuite/gdb.fortran/array-bounds.f
@@ -0,0 +1,21 @@
+c Copyright 2012 Free Software Foundation, Inc.
+
+c This program is free software; you can redistribute it and/or modify
+c it under the terms of the GNU General Public License as published by
+c the Free Software Foundation; either version 3 of the License, or
+c (at your option) any later version.
+c
+c This program is distributed in the hope that it will be useful,
+c but WITHOUT ANY WARRANTY; without even the implied warranty of
+c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+c GNU General Public License for more details.
+c
+c You should have received a copy of the GNU General Public License
+c along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+        dimension foo(4294967296:4294967297)
+        dimension bar(-4294967297:-4294967296)
+        foo=bar
+        stop
+        end
+

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