From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Subject: [patch] Cut memory address width
Date: Wed, 27 Sep 2006 16:15:00 -0000 [thread overview]
Message-ID: <20060927161501.GA23340@host0.dyn.jankratochvil.net> (raw)
[-- 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 (¤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;
next reply other threads:[~2006-09-27 16:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-27 16:15 Jan Kratochvil [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060927161501.GA23340@host0.dyn.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox