From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2087 invoked by alias); 27 Sep 2006 16:15:13 -0000 Received: (qmail 2079 invoked by uid 22791); 27 Sep 2006 16:15:11 -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; Wed, 27 Sep 2006 16:15:06 +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 k8RGF2Oh023681 for ; Wed, 27 Sep 2006 18:15:02 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.13.8/8.13.8/Submit) id k8RGF1ZH023680 for gdb-patches@sourceware.org; Wed, 27 Sep 2006 18:15:01 +0200 Date: Wed, 27 Sep 2006 16:15:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] Cut memory address width Message-ID: <20060927161501.GA23340@host0.dyn.jankratochvil.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ZGiS0Q5IWpPtfppv" Content-Disposition: inline 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/msg00191.txt.bz2 --ZGiS0Q5IWpPtfppv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1424 Hi, `x/x $ebx' on gdb/amd64 debugging inferior/i386 causes Cannot access memory at address 0xffffce70 (or so) as $ebx is considered `int' and sign-extended to 64-bit while the resulting address 0xffffffffffffce70 fails to be accessed. $esp does not exhibit this problem as it is `builtin_type_void_data_ptr' not `builtin_type_int' as $ebx is. Therefore it gets extended as unsigned. Simulate the part of paddress(); it is questionable how deep in the functions calling stack the address width cut should be. Regards, Jan As bugreported by John Reiser : When debugging a 32-bit executable on x86_64, gdb does not allow examining the stack if pointed to by a non-$esp register. For example, -----foo.S _start: .globl _start nop int3 movl %esp,%ebx int3 # examining memory from $ebx fails, from $esp succeeds nop nop ----- $ gcc -m32 -o foo -nostartfiles -nostdlib foo.S $ gdb foo Program received signal SIGTRAP, Trace/breakpoint trap. 0x08048076 in _start () (gdb) x/i $pc 0x8048076 <_start+2>: mov %esp,%ebx (gdb) stepi 0x08048078 in _start () (gdb) x/x $esp 0xffffce70: 0x00000001 (gdb) x/x $ebx 0xffffce70: Cannot access memory at address 0xffffce70 (gdb) x/x 0xffffce70 0xffffce70: 0x00000001 Expected Results: "x/x $ebx" should have succeeded, too, when %ebx has the same value as %esp and examining from $esp works. --ZGiS0Q5IWpPtfppv Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gdb-6.5-memory-address-width.patch" Content-length: 1672 2006-09-27 Jan Kratochvil * target.c (target_read_memory): Cut memory address to the target's address bit size, bugreport by John Reiser. (target_write_memory): Likewise. Index: gdb/target.c =================================================================== RCS file: /cvs/src/src/gdb/target.c,v retrieving revision 1.126 diff -u -p -r1.126 target.c --- gdb/target.c 21 Sep 2006 14:00:53 -0000 1.126 +++ gdb/target.c 27 Sep 2006 16:01:27 -0000 @@ -1032,6 +1032,16 @@ target_xfer_partial (struct target_ops * int target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len) { + /* `x/x $ebx' on gdb/amd64 debugging inferior/i386 causes + Cannot access memory at address 0xffffce70 + as $ebx is considered `int' and sign-extended to 64-bit. + $esp does not exhibit this problem as it is `builtin_type_void_data_ptr', + not `builtin_type_int' as $ebx is. + Simulate the part of paddress() here. */ + int addr_bit = TARGET_ADDR_BIT; + if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT)) + memaddr &= ((CORE_ADDR) 1 << addr_bit) - 1; + if (target_read (¤t_target, TARGET_OBJECT_MEMORY, NULL, myaddr, memaddr, len) == len) return 0; @@ -1042,6 +1052,11 @@ target_read_memory (CORE_ADDR memaddr, g int target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, int len) { + /* See `target_read_memory' above. */ + int addr_bit = TARGET_ADDR_BIT; + if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT)) + memaddr &= ((CORE_ADDR) 1 << addr_bit) - 1; + if (target_write (¤t_target, TARGET_OBJECT_MEMORY, NULL, myaddr, memaddr, len) == len) return 0; --ZGiS0Q5IWpPtfppv--