From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26716 invoked by alias); 5 Oct 2005 23:28:20 -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 26707 invoked by uid 22791); 5 Oct 2005 23:28:17 -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 23:28:17 +0000 Received: by takamaka.act-europe.fr (Postfix, from userid 507) id 6A78047E74; Wed, 5 Oct 2005 16:28:15 -0700 (PDT) Date: Wed, 05 Oct 2005 23:28:00 -0000 From: Joel Brobecker To: gdb-patches@sources.redhat.com Subject: [RFA/ada] fix bug in ada-valprint.c:print_optional_low_bound() Message-ID: <20051005232815.GG1590@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="oC1+HKm2/end4ao3" Content-Disposition: inline User-Agent: Mutt/1.4i X-SW-Source: 2005-10/txt/msg00048.txt.bz2 --oC1+HKm2/end4ao3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 2336 Hello, This is a regression I noticed after introducing "set print array-indexes". Consider the code submitted in the gdb.ada/arrayidx testcase: http://sources.redhat.com/ml/gdb-patches/2005-10/msg00046.html You have an enumerated type declared, and then an array type declared using that enumerated type as its index: type Index is (One, Two, Three); type RTable is array (Index range Two .. Three) of Integer; As you see, the array type does not use the entire enumerated type range as its index, but only a subrange of it. So when printing an array of this type, such as: R_Two_Three : RTable := (2, 3); The debugger should notice that the lower bound of the array is not the first element of the enumerated type, and therefore should explicitly print the index of the first array element, like this: (gdb) print r_two_three $1 = (two => 2, 3) However, we currently get this: (gdb) print r_two_three $1 = (two => 2, 3) What happens is that GDB sees in print_optional_low_bound() that the index type is a TYPE_CODE_RANGE, failing to see that underneath there is an enumerated type. So it therefore compares the value of the low bound against 1, which it should compare it against the value of the first enumeration in the enumerated type. The underlying value of an enumerated type is typically zero, so "one" is zero, and "two" is 1. Just to make it easier to see what's after the patch, here is a copy of the switch seen in the patch: switch (TYPE_CODE (index_type)) { case TYPE_CODE_ENUM: if (low_bound == TYPE_FIELD_BITPOS (index_type, 0)) return 0; break; case TYPE_CODE_UNDEF: index_type = builtin_type_long; /* FALL THROUGH */ default: if (low_bound == 1) return 0; break; } The patch fixes this problem. It's not sufficient to fix the problem, due to another problem I eluded to when submitting gdb.ada/arrayidx.exp. But this patch will be needed. 2005-10-05 Joel Brobecker * ada-valprint.c (print_optional_low_bound): Handle properly cases where the array index type is a TYPE_CODE_RANGE. Tested on x86-linux. No regression. Thanks, -- Joel --oC1+HKm2/end4ao3 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ada-valprint.c.diff" Content-length: 887 Index: ada-valprint.c =================================================================== RCS file: /cvs/src/src/gdb/ada-valprint.c,v retrieving revision 1.24 diff -u -p -r1.24 ada-valprint.c --- ada-valprint.c 3 Oct 2005 21:21:20 -0000 1.24 +++ ada-valprint.c 5 Oct 2005 23:26:09 -0000 @@ -94,6 +94,16 @@ print_optional_low_bound (struct ui_file index_type = TYPE_INDEX_TYPE (type); + if (TYPE_CODE (index_type) == TYPE_CODE_RANGE) + { + /* We need to know what the base type is, in order to do the + appropriate check below. Otherwise, if this is a subrange + of an enumerated type, where the underlying value of the + first element is typically 0, we might test the low bound + against the wrong value. */ + index_type = TYPE_TARGET_TYPE (index_type); + } + switch (TYPE_CODE (index_type)) { case TYPE_CODE_ENUM: --oC1+HKm2/end4ao3--