From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17880 invoked by alias); 8 Jan 2015 05:40:48 -0000 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 Received: (qmail 17865 invoked by uid 89); 8 Jan 2015 05:40:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 08 Jan 2015 05:40:44 +0000 Received: from svr-orw-fem-03.mgc.mentorg.com ([147.34.97.39]) by relay1.mentorg.com with esmtp id 1Y95po-00071R-RV from Yao_Qi@mentor.com ; Wed, 07 Jan 2015 21:40:40 -0800 Received: from GreenOnly (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.3.224.2; Wed, 7 Jan 2015 21:40:40 -0800 From: Yao Qi To: Pedro Alves CC: Subject: Re: [PATCH] Clear upper bits during sign extension References: <1419815569-21854-1-git-send-email-yao@codesourcery.com> <54A13184.1070902@redhat.com> <874msdwl39.fsf@codesourcery.com> <54A29886.8030603@redhat.com> <87vbktuu5p.fsf@codesourcery.com> Date: Thu, 08 Jan 2015 05:40:00 -0000 In-Reply-To: <87vbktuu5p.fsf@codesourcery.com> (Yao Qi's message of "Tue, 30 Dec 2014 21:46:58 +0800") Message-ID: <87bnm9u8wx.fsf@codesourcery.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2015-01/txt/msg00162.txt.bz2 Yao Qi writes: >> + byte_order =3D gdbarch_byte_order (get_type_arch (type)); > > How about getting gdbarch via get_frame_arch (frame)? How about > removing gdb_sign_extend as it is no longer used? > > I'll post a full version on top of yours. Here is the patch, what do you think? --=20 Yao (=E9=BD=90=E5=B0=A7) Subject: [PATCH] always read synthetic pointers as signed integers I see the error message "access outside bounds of object referenced via synthetic pointer" in the two fails below of mips gdb testing print d[-2]^M access outside bounds of object referenced via synthetic pointer^M (gdb) FAIL: gdb.dwarf2/implptrconst.exp: print d[-2] (gdb) print/d p[-1]^M access outside bounds of object referenced via synthetic pointer^M (gdb) FAIL: gdb.dwarf2/implptrpiece.exp: print/d p[-1] in the first test, 'd[-2]' is processed by GDB as '* (&d[-2])'. 'd' is a synthetic pointer, so its value is zero, the address of 'd[-2]' is -2. In dwarf2loc.c:indirect_pieced_value, /* This is an offset requested by GDB, such as value subscripts. However, due to how synthetic pointers are implemented, this is always presented to us as a pointer type. This means we have to sign-extend it manually as appropriate. */ byte_offset =3D value_as_address (value); if (TYPE_LENGTH (value_type (value)) < sizeof (LONGEST)) byte_offset =3D gdb_sign_extend (byte_offset, 8 * TYPE_LENGTH (value_type (value))); byte_offset +=3D piece->v.ptr.offset; We know that the value is really an offset instead of address, so the fix is to extract the value as an (signed) offset. gdb: 2015-01-08 Pedro Alves Yao Qi * dwarf2loc.c (indirect_pieced_value): Don't call gdb_sign_extend. Call extract_signed_integer instead. * utils.c (gdb_sign_extend): Remove. * utils.h (gdb_sign_extend): Remove declaration. --- gdb/dwarf2loc.c | 16 +++++++++++----- gdb/utils.c | 17 ----------------- gdb/utils.h | 5 ----- 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index 2bd12d6..bdb2160 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -2012,6 +2012,7 @@ indirect_pieced_value (struct value *value) int i, bit_offset, bit_length; struct dwarf_expr_piece *piece =3D NULL; LONGEST byte_offset; + enum bfd_endian byte_order; =20 type =3D check_typedef (value_type (value)); if (TYPE_CODE (type) !=3D TYPE_CODE_PTR) @@ -2056,11 +2057,16 @@ indirect_pieced_value (struct value *value) /* This is an offset requested by GDB, such as value subscripts. However, due to how synthetic pointers are implemented, this is always presented to us as a pointer type. This means we have to - sign-extend it manually as appropriate. */ - byte_offset =3D value_as_address (value); - if (TYPE_LENGTH (value_type (value)) < sizeof (LONGEST)) - byte_offset =3D gdb_sign_extend (byte_offset, - 8 * TYPE_LENGTH (value_type (value))); + sign-extend it manually as appropriate. Use raw + extract_signed_integer directly rather than value_as_address and + sign extend afterwards on architectures that would need it + (mostly everywhere except MIPS, which has signed addresses) as + the later would go through gdbarch_pointer_to_address and thus + return a CORE_ADDR with high bits set on architectures that + encode address spaces and other things in CORE_ADDR. */ + byte_order =3D gdbarch_byte_order (get_frame_arch (frame)); + byte_offset =3D extract_signed_integer (value_contents (value), + TYPE_LENGTH (type), byte_order); byte_offset +=3D piece->v.ptr.offset; =20 gdb_assert (piece); diff --git a/gdb/utils.c b/gdb/utils.c index 084db87..72b1e2a 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3021,23 +3021,6 @@ align_down (ULONGEST v, int n) return (v & -n); } =20 -/* See utils.h. */ - -LONGEST -gdb_sign_extend (LONGEST value, int bit) -{ - gdb_assert (bit >=3D 1 && bit <=3D 8 * sizeof (LONGEST)); - - if (((value >> (bit - 1)) & 1) !=3D 0) - { - LONGEST signbit =3D ((LONGEST) 1) << (bit - 1); - - value =3D (value ^ signbit) - signbit; - } - - return value; -} - /* Allocation function for the libiberty hash table which uses an obstack. The obstack is passed as DATA. */ =20 diff --git a/gdb/utils.h b/gdb/utils.h index 0a73864..3debde7 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -340,11 +340,6 @@ extern int myread (int, char *, int); extern ULONGEST align_up (ULONGEST v, int n); extern ULONGEST align_down (ULONGEST v, int n); =20 -/* Sign extend VALUE. BIT is the (1-based) index of the bit in VALUE - to sign-extend. */ - -extern LONGEST gdb_sign_extend (LONGEST value, int bit); - /* Resource limits used by getrlimit and setrlimit. */ =20 enum resource_limit_kind --=20 1.9.3