From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29006 invoked by alias); 5 Oct 2005 22:09:40 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 28987 invoked by uid 22791); 5 Oct 2005 22:09:38 -0000 Received: from s142-179-108-108.bc.hsia.telus.net (HELO takamaka.act-europe.fr) (142.179.108.108) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Wed, 05 Oct 2005 22:09:38 +0000 Received: by takamaka.act-europe.fr (Postfix, from userid 507) id 8BCBD47E74; Wed, 5 Oct 2005 15:09:35 -0700 (PDT) Date: Wed, 05 Oct 2005 22:09:00 -0000 From: Joel Brobecker To: gdb-patches@sources.redhat.com Subject: [RFA] Remove unexpected warning when printing empty array Message-ID: <20051005220935.GO1591@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="TB36FDmn/VVEgNH/" Content-Disposition: inline User-Agent: Mutt/1.4i X-SW-Source: 2005-10/txt/msg00047.txt.bz2 --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1043 This is to fix a small warning introduced after checking in this patch: http://sources.redhat.com/ml/gdb-patches/2005-10/msg00028.htm This fixes two FAILs for a testcase I just submitted: http://sources.redhat.com/ml/gdb-patches/2005-10/msg00046.html FAIL: gdb.ada/arrayidx.exp: print empty, indexes off FAIL: gdb.ada/arrayidx.exp: print empty The problem is that we were trying to get the lower bound of an empty array. To do that, we called get_array_low_bound(), which assumes that the array is not empty. So this routine determines that there is something abnormal about the array, and returns an error, causing us to then issue a warning to the user. By shifting slightly the code a bit, we can avoid the warnings in all situations. 2005-10-05 Joel Brobecker * valprint.c (val_print_array_elements): Check array size before computing its low bound. If zero, then use a default bound of zero. Tested on x86-linux, fixes the two FAILs above. OK to apply? Thanks, -- Joel --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="valprint.c.diff" Content-length: 1225 Index: valprint.c =================================================================== RCS file: /cvs/src/src/gdb/valprint.c,v retrieving revision 1.55 diff -u -p -r1.55 valprint.c --- valprint.c 3 Oct 2005 21:21:20 -0000 1.55 +++ valprint.c 5 Oct 2005 22:00:29 -0000 @@ -959,19 +959,21 @@ val_print_array_elements (struct type *t unsigned int rep1; /* Number of repetitions we have detected so far. */ unsigned int reps; - long low_bound_index; - - if (!get_array_low_bound (type, &low_bound_index)) - { - warning ("unable to get low bound of array, using zero as default"); - low_bound_index = 0; - } + long low_bound_index = 0; elttype = TYPE_TARGET_TYPE (type); eltlen = TYPE_LENGTH (check_typedef (elttype)); len = TYPE_LENGTH (type) / eltlen; index_type = TYPE_INDEX_TYPE (type); + /* Get the array low bound. This only makes sense if the array + has one or more element in it. */ + if (len > 0 && !get_array_low_bound (type, &low_bound_index)) + { + warning ("unable to get low bound of array, using zero as default"); + low_bound_index = 0; + } + annotate_array_section_begin (i, elttype); for (; i < len && things_printed < print_max; i++) --TB36FDmn/VVEgNH/--