From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10510 invoked by alias); 13 Jul 2006 11:55:02 -0000 Received: (qmail 10454 invoked by uid 22791); 13 Jul 2006 11:55:01 -0000 X-Spam-Check-By: sourceware.org Received: from aquarius.hirmke.de (HELO calimero.vinschen.de) (217.91.18.234) by sourceware.org (qpsmtpd/0.31.1) with ESMTP; Thu, 13 Jul 2006 11:54:59 +0000 Received: by calimero.vinschen.de (Postfix, from userid 500) id 9F5476D42F3; Thu, 13 Jul 2006 13:54:56 +0200 (CEST) Date: Thu, 13 Jul 2006 11:55:00 -0000 From: Corinna Vinschen To: gdb-patches@sourceware.org Subject: Re: [PATCH] mips-tdep.c: Fix bug in evaluating signed address Message-ID: <20060713115456.GU8759@calimero.vinschen.de> Reply-To: gdb-patches@sourceware.org Mail-Followup-To: gdb-patches@sourceware.org References: <20060616162332.GA11814@calimero.vinschen.de> <20060712193149.GP24622@nevyn.them.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060712193149.GP24622@nevyn.them.org> User-Agent: Mutt/1.4.2i X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-07/txt/msg00146.txt.bz2 On Jul 12 15:31, Daniel Jacobowitz wrote: > On Fri, Jun 16, 2006 at 06:23:32PM +0200, Corinna Vinschen wrote: > > Hi, > > > > the below patch fixes the mips_integer_to_address function. What > > happens is this: > > > > If the incoming type is an *unsigned* value, then unpack_long takes the > > (un)signedness into account. This results in `val' not being signed > > extended, as the mips_integer_to_address function was originally > > designed for. > > > > So, to enforce correct signedness of the resulting address, I changed > > the unpack_long call to extract_signed_integer. This way, val is always > > sign extended and the mips address is correctly signed. > > I might be missing something, but isn't the function mostly redundant > now? > > > Index: gdb/mips-tdep.c > > =================================================================== > > RCS file: /cvs/cvsfiles/gnupro/gdb/mips-tdep.c,v > > retrieving revision 1.24 > > diff -u -p -r1.24 mips-tdep.c > > --- gdb/mips-tdep.c 15 Jun 2006 08:57:17 -0000 1.24 > > +++ gdb/mips-tdep.c 16 Jun 2006 16:15:48 -0000 > > @@ -4749,7 +4749,7 @@ mips_integer_to_address (struct gdbarch > > struct type *type, const gdb_byte *buf) > > { > > gdb_byte *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr)); > > - LONGEST val = unpack_long (type, buf); > > + LONGEST val = extract_signed_integer (buf, TYPE_LENGTH (type)); > > store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val); > > return extract_signed_integer (tmp, > > TYPE_LENGTH (builtin_type_void_data_ptr)); > > Those last two have got to be a no-op. Hmm, yes, you're right. I didn't realize that when changing unpack_long to extract_signed_integer. Thanks, correct version below. Corinna * mips-tdep.c (mips_integer_to_address): Simplify be calling extract_signed_integer directly. Fix comment. Index: mips-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/mips-tdep.c,v retrieving revision 1.396 diff -u -p -r1.396 mips-tdep.c --- mips-tdep.c 19 Jun 2006 18:50:09 -0000 1.396 +++ mips-tdep.c 13 Jul 2006 11:36:13 -0000 @@ -4647,19 +4647,14 @@ mips_register_sim_regno (int regnum) } -/* Convert an integer into an address. By first converting the value - into a pointer and then extracting it signed, the address is - guarenteed to be correctly sign extended. */ +/* Convert an integer into an address. Extracting the value signed + guarantees a correctly sign extended address. */ static CORE_ADDR mips_integer_to_address (struct gdbarch *gdbarch, struct type *type, const gdb_byte *buf) { - gdb_byte *tmp = alloca (TYPE_LENGTH (builtin_type_void_data_ptr)); - LONGEST val = unpack_long (type, buf); - store_signed_integer (tmp, TYPE_LENGTH (builtin_type_void_data_ptr), val); - return extract_signed_integer (tmp, - TYPE_LENGTH (builtin_type_void_data_ptr)); + return (CORE_ADDR) extract_signed_integer (buf, TYPE_LENGTH (type)); } static void -- Corinna Vinschen Cygwin Project Co-Leader Red Hat