From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16169 invoked by alias); 3 Nov 2010 23:22:45 -0000 Received: (qmail 16150 invoked by uid 22791); 3 Nov 2010 23:22:44 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 03 Nov 2010 23:22:39 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 605872BAB16; Wed, 3 Nov 2010 19:22:37 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 7c4fYCN54E89; Wed, 3 Nov 2010 19:22:37 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 266992BAAFC; Wed, 3 Nov 2010 19:22:37 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id 7B2DCF588F; Wed, 3 Nov 2010 16:22:34 -0700 (PDT) From: Joel Brobecker To: gdb-patches@sourceware.org Cc: Joel Brobecker Subject: [commit/Ada] fix warning when printing empty array Date: Wed, 03 Nov 2010 23:22:00 -0000 Message-Id: <1288826552-17869-1-git-send-email-brobecker@adacore.com> In-Reply-To: <20101103211550.GC2445@adacore.com> References: <20101103211550.GC2445@adacore.com> 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: 2010-11/txt/msg00075.txt.bz2 This patch should fix the following regression: (gdb) print my_table -$1 = () -(gdb) PASS: gdb.ada/null_array.exp: print my_table +$1 = (warning: unable to get bounds of array, assuming null array +) +(gdb) FAIL: gdb.ada/null_array.exp: print my_table The problem was introduced by a change in val_print_array_elements which removed a check for the case where the array's high bound is smaller than the array's low bound (empty array). This change restores the check and forces the len to zero in that case. Looking at the patch that caused the regression, I suspect that we may have other parts that might have been broken (non-zero array low bound?). gdb/ChangeLog: * valprint.c (val_print_array_elements): Put back handling of empty arrays. Tested on x86_64-linux. Checked in. --- gdb/ChangeLog | 5 +++++ gdb/valprint.c | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 719582b..221868b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2010-11-03 Joel Brobecker + + * valprint.c (val_print_array_elements): Put back handling of + empty arrays. + 2010-11-03 Ken Werner * dwarf2read.c (read_array_type): Read the DW_AT_byte_size from the diff --git a/gdb/valprint.c b/gdb/valprint.c index dba528b..ddb16e4 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -1118,7 +1118,17 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr, index_type = TYPE_INDEX_TYPE (type); if (get_array_bounds (type, &low_bound, &high_bound)) - len = high_bound - low_bound + 1; + { + /* The array length should normally be HIGH_BOUND - LOW_BOUND + 1. + But we have to be a little extra careful, because some languages + such as Ada allow LOW_BOUND to be greater than HIGH_BOUND for + empty arrays. In that situation, the array length is just zero, + not negative! */ + if (low_bound > high_bound) + len = 0; + else + len = high_bound - low_bound + 1; + } else { warning (_("unable to get bounds of array, assuming null array")); -- 1.7.1