From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24225 invoked by alias); 4 Oct 2005 07:41:39 -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 24211 invoked by uid 22791); 4 Oct 2005 07:41:37 -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; Tue, 04 Oct 2005 07:41:37 +0000 Received: by takamaka.act-europe.fr (Postfix, from userid 507) id C47FB47E74; Tue, 4 Oct 2005 00:41:34 -0700 (PDT) Date: Tue, 04 Oct 2005 07:41:00 -0000 From: Joel Brobecker To: gdb-patches@sources.redhat.com Subject: Re: [RFA] print arrays with indexes Message-ID: <20051004074134.GB8849@adacore.com> References: <20050920193132.GY2496@adacore.com> <20050920193339.GA28294@nevyn.them.org> <20050920193918.GB10186@adacore.com> <20050922164622.GF5841@adacore.com> <20050926012259.GA22284@nevyn.them.org> <20050927010420.GW922@adacore.com> <20051002224218.GA3083@nevyn.them.org> <20051003061733.GL938@adacore.com> <20051004070220.GZ8849@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="/Uq4LBwYP4y1W6pO" Content-Disposition: inline In-Reply-To: <20051004070220.GZ8849@adacore.com> User-Agent: Mutt/1.4i X-SW-Source: 2005-10/txt/msg00042.txt.bz2 --/Uq4LBwYP4y1W6pO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1410 BTW, I forgot to mention a couple of things regarding: > 2. More annoying, I just tried something else, which is to print an > empty Ada array. Ada allows you to create this by using declarations > such as this: > > Table : array (1 .. 0) of Integer; > > Basically, if the lower/left bound is greater than the right/higher > bound, then the array is empty. > > I just discovered that ada_val_print_1 calls val_print_array_elements > even if the array is empty. This triggers one of the guards in > get_array_low_bound(), since the function expects a non-empty array. > > I'm happy to just put a check in the Ada part to avoid calling > val_print_array_elements for empty arrays. This should be fine, but > I'm wondering if other languages might be doing the same, in which > case it's probably going to be safer to modify a bit > val_print_array_elements to handle empty arrays... a. I tried with a C example, something like this: int table [] = {}; And verified that GDB worked correctly (printed the address of the array, but no value). So there is no issue with C, at least. Don't have a pascal compiler handy, though. b. I prefer the second approach. It just feels safer and more elegant. In fact I just finished testing the attached patch. I will submit a proper patch together with a testcase tomorrow. -- Joel --/Uq4LBwYP4y1W6pO 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 4 Oct 2005 07:40:59 -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++) --/Uq4LBwYP4y1W6pO--