Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] Cut memory address width
@ 2006-09-27 16:15 Jan Kratochvil
  2006-09-27 18:20 ` Michael Snyder
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Jan Kratochvil @ 2006-09-27 16:15 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1424 bytes --]

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 <jreiser(at)BitWagon.com>:

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.

[-- Attachment #2: gdb-6.5-memory-address-width.patch --]
[-- Type: text/plain, Size: 1672 bytes --]

2006-09-27  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* 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 (&current_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 (&current_target, TARGET_OBJECT_MEMORY, NULL,
 		    myaddr, memaddr, len) == len)
     return 0;

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2006-10-05 22:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-27 16:15 [patch] Cut memory address width Jan Kratochvil
2006-09-27 18:20 ` Michael Snyder
2006-09-27 18:22   ` Daniel Jacobowitz
2006-09-27 18:37     ` Jan Kratochvil
2006-09-27 18:55       ` Daniel Jacobowitz
2006-09-27 20:19         ` Jim Blandy
2006-09-27 19:01 ` Mark Kettenis
2006-09-28 17:27   ` Jan Kratochvil
2006-10-05 22:26     ` Daniel Jacobowitz
2006-09-27 19:23 ` Jim Blandy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox