From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31551 invoked by alias); 21 Aug 2012 09:56:38 -0000 Received: (qmail 31536 invoked by uid 22791); 21 Aug 2012 09:56:36 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,MAY_BE_FORGED,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 21 Aug 2012 09:56:17 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q7L9uGVS020800 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 21 Aug 2012 05:56:16 -0400 Received: from spoyarek (dhcp223-8.pnq.redhat.com [10.65.223.8] (may be forged)) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q7L9uEYZ027417 for ; Tue, 21 Aug 2012 05:56:15 -0400 Date: Tue, 21 Aug 2012 09:56:00 -0000 From: Siddhesh Poyarekar To: gdb-patches@sourceware.org Subject: [PATCH] Expand fortran array bounds sizes to LONGEST Message-ID: <20120821152540.013b4d99@spoyarek> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/90J7bck2fqDySEX9JkZtaqL" Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-08/txt/msg00562.txt.bz2 --MP_/90J7bck2fqDySEX9JkZtaqL Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 1221 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. --MP_/90J7bck2fqDySEX9JkZtaqL Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=f77-bounds.patch Content-length: 6084 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 . + +# 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 . + + dimension foo(4294967296:4294967297) + dimension bar(-4294967297:-4294967296) + foo=bar + stop + end + --MP_/90J7bck2fqDySEX9JkZtaqL--