From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29006 invoked by alias); 28 Sep 2006 17:27:41 -0000 Received: (qmail 28995 invoked by uid 22791); 28 Sep 2006 17:27:39 -0000 X-Spam-Check-By: sourceware.org Received: from 195.22.55.53.adsl.nextra.cz (HELO host0.dyn.jankratochvil.net) (195.22.55.53) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 28 Sep 2006 17:27:35 +0000 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.13.8/8.13.8) with ESMTP id k8SHRQfY026455; Thu, 28 Sep 2006 19:27:27 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.13.8/8.13.8/Submit) id k8SHRP4Z026454; Thu, 28 Sep 2006 19:27:25 +0200 Date: Thu, 28 Sep 2006 17:27:00 -0000 From: Jan Kratochvil To: Mark Kettenis , Jim Blandy Cc: gdb-patches@sourceware.org Subject: Re: [patch] Cut memory address width Message-ID: <20060928172725.GA18498@host0.dyn.jankratochvil.net> References: <20060927161501.GA23340@host0.dyn.jankratochvil.net> <20060927161501.GA23340@host0.dyn.jankratochvil.net> <200609271901.k8RJ1BD1030473@elgar.sibelius.xs4all.nl> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="XsQoSWH+UP9D9v3l" Content-Disposition: inline In-Reply-To: <200609271901.k8RJ1BD1030473@elgar.sibelius.xs4all.nl> User-Agent: Mutt/1.4.2.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-09/txt/msg00207.txt.bz2 --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 990 Hi, On Wed, 27 Sep 2006 21:01:11 +0200, Mark Kettenis wrote: ... > This should almost certainly be handled in value.c:value_as_address(). > You could add an i386-specific integer_to_address(), that would > truncate the address to 32 bits. But in fact, I can't think of a > reason why truncating to the size of a pointer shouldn't be the > default behaviour. Made the default way, I also do not see the reason to keep larger addresses. There is some note about `ADDR_BITS_REMOVE' but I believe it is only about the lowest (0-2 or so) bits and the high bits should not hurt anyone. On Wed, 27 Sep 2006 21:24:27 +0200, Jim Blandy wrote: ... > Just as a sanity check: what does 'show architecture' say when you're > debugging an i386 inferior on gdb/amd64? as expected: The target architecture is set automatically (currently i386) ... > Is there some code there assuming that host == target? I do not believe so, it is handled everything by `LONGEST' / `unpack_long'. Regards, Jan --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdb-6.5-memory-address-width-v2.patch" Content-length: 3734 2006-09-28 Jan Kratochvil * gdb/utils.c (paddress): Disable cutting of the printed addresses to the target's address bit size; user wants to see everything. * gdb/value.c (value_as_address_core): Original `value_as_address'. (value_as_address): New `value_as_address' wrapper - cut memory address to the target's address bit size, bugreport by John Reiser. Index: gdb/utils.c =================================================================== RCS file: /cvs/src/src/gdb/utils.c,v retrieving revision 1.169 diff -u -p -r1.169 utils.c --- gdb/utils.c 21 Sep 2006 13:50:51 -0000 1.169 +++ gdb/utils.c 28 Sep 2006 17:06:03 -0000 @@ -2596,6 +2596,14 @@ paddr_nz (CORE_ADDR addr) const char * paddress (CORE_ADDR addr) { + /* Do no cut the address as the user should see all the information + available. Otherwise 64-bit gdb debugging 32-bit inferior would + report for `x/x 0xffffffffffffce70' error + `Cannot access memory at 0xffffce70' while the error occured just + because of the higher order bits 0xffffffff00000000 there. + This specific error no longer occurs as the address is now cut + during execution by `value_as_address'. */ +#if 0 /* Truncate address to the size of a target address, avoiding shifts larger or equal than the width of a CORE_ADDR. The local variable ADDR_BIT stops the compiler reporting a shift overflow @@ -2609,6 +2617,8 @@ paddress (CORE_ADDR addr) if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT)) addr &= ((CORE_ADDR) 1 << addr_bit) - 1; +#endif + return hex_string (addr); } Index: gdb/value.c =================================================================== RCS file: /cvs/src/src/gdb/value.c,v retrieving revision 1.36 diff -u -p -r1.36 value.c --- gdb/value.c 31 Mar 2006 10:36:18 -0000 1.36 +++ gdb/value.c 28 Sep 2006 17:06:03 -0000 @@ -950,11 +950,10 @@ value_as_double (struct value *val) error (_("Invalid floating value found in program.")); return foo; } -/* Extract a value as a C pointer. Does not deallocate the value. - Note that val's type may not actually be a pointer; value_as_long - handles all the cases. */ -CORE_ADDR -value_as_address (struct value *val) + +/* See `value_as_address' below - core of value to C pointer extraction. */ +static CORE_ADDR +value_as_address_core (struct value *val) { /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure whether we want this to be true eventually. */ @@ -1054,6 +1053,33 @@ value_as_address (struct value *val) return unpack_long (value_type (val), value_contents (val)); #endif } + +/* Extract a value as a C pointer. Does not deallocate the value. + Note that val's type may not actually be a pointer; value_as_long + handles all the cases. */ +CORE_ADDR +value_as_address (struct value *val) +{ + CORE_ADDR addr; + + addr = value_as_address_core (val); + + /* Truncate address to the size of a target address, avoiding shifts + larger or equal than the width of a CORE_ADDR. The local + variable ADDR_BIT stops the compiler reporting a shift overflow + when it won't occur. */ + /* NOTE: This assumes that the significant address information is + kept in the least significant bits of ADDR - the upper bits were + either zero or sign extended. Should ADDRESS_TO_POINTER() or + some ADDRESS_TO_PRINTABLE() be used to do the conversion? */ + + int addr_bit = TARGET_ADDR_BIT; + + if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT)) + addr &= ((CORE_ADDR) 1 << addr_bit) - 1; + + return addr; +} /* Unpack raw data (copied from debugee, target byte order) at VALADDR as a long, or as a double, assuming the raw data is described --XsQoSWH+UP9D9v3l--