From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25199 invoked by alias); 19 May 2005 03:23:37 -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 25141 invoked from network); 19 May 2005 03:23:34 -0000 Received: from unknown (HELO takamaka.act-europe.fr) (138.130.149.55) by sourceware.org with SMTP; 19 May 2005 03:23:34 -0000 Received: by takamaka.act-europe.fr (Postfix, from userid 507) id 5509447957; Thu, 19 May 2005 13:23:32 +1000 (EST) Date: Thu, 19 May 2005 03:33:00 -0000 From: Joel Brobecker To: Richard Henderson Cc: gdb-patches@sources.redhat.com Subject: Re: Question: Checking register value in buffer Message-ID: <20050519032332.GZ12565@adacore.com> References: <20050519020443.GP1462@adacore.com> <20050519022256.GA8204@redhat.com> <20050519024857.GY12565@adacore.com> <20050519030349.GA8255@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050519030349.GA8255@redhat.com> User-Agent: Mutt/1.4i X-SW-Source: 2005-05/txt/msg00465.txt.bz2 > > In terms of computing the mask, I'm thinking of using something > > like this: > > > > sign_mask = 1 << (sizeof (rav) * TARGET_CHAR_BIT - 1); > > This confuses host and target notions. You would have wanted > the *host* CHAR_BIT, since you're using the host sizeof. Ah yes, of course. > > zero_mask = sign_mask ^ -1; > > This fails if rav is *wider* than 64-bits. > > > Are there better ways of computing these masks? > > How about just > > sign = (LONGEST)1 << 63 > zero = sign - 1; Isn't this assument that LONGEST is exactly 64 bits? I think extract_signed_integer expands the value held in the given buffer to fit the size of LONGEST. Here is the implementation: LONGEST extract_signed_integer (const void *addr, int len) { LONGEST retval; const unsigned char *p; const unsigned char *startaddr = addr; const unsigned char *endaddr = startaddr + len; if (len > (int) sizeof (LONGEST)) error (_("\ That operation is not available on integers of more than %d bytes."), (int) sizeof (LONGEST)); /* Start at the most significant end of the integer, and work towards the least significant. */ if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG) { p = startaddr; /* Do the sign extension once at the start. */ retval = ((LONGEST) * p ^ 0x80) - 0x80; for (++p; p < endaddr; ++p) retval = (retval << 8) | *p; } else { p = endaddr - 1; /* Do the sign extension once at the start. */ retval = ((LONGEST) * p ^ 0x80) - 0x80; for (--p; p >= startaddr; --p) retval = (retval << 8) | *p; } return retval; } Using an example where we have len = 1 and sizeof LONGEST = 2, then the extract from "0xff" would lead to "0xffff", no? That's why I thought the little dance with sizeof and xor was necessary. -- Joel