From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Subject: [patch] Fix i386 memory-by-register access on amd64
Date: Wed, 29 Apr 2009 10:27:00 -0000 [thread overview]
Message-ID: <20090429102719.GA10117@host0.dyn.jankratochvil.net> (raw)
Hi,
original bugreport:
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=181390
(gdb) x/x $esp
0xffffce70: 0x00000001
(gdb) x/x $ebx
0xffffce70: Cannot access memory at address 0xffffce70
(gdb) x/x 0xffffce70
0xffffce70: 0x00000001
One point is there should have been printed this error message instead:
0xffffffffffffce70: Cannot access memory at address 0xffffffffffffce70
but this problem is just a consequence of paddress() truncating the printed
address width. This printing issue is unrelated to the patch below.
The error happens because $ebx is considered signed while $esp unsigned, as
initialized by i386_register_type (or also amd64_register_type). Therefore
the address width should be cut to the right size at the right point of
processing, I hope I caught (one of) such points.
Regression-tested on x86_64-unknown-linux-gnu (PASS), i386 build with
unix/-m32 (test skipped) and native build with unix/-m64 (new test FAILs as
the test's additionla_flags=-m32 gets overriden by target board's -m64).
Thanks,
Jan
2006-09-28 Jan Kratochvil <jan.kratochvil@redhat.com>
Fix signed 32bit inferior registers on 64bit GDB.
* gdb/value.c (value_as_address): Make it static, rename it to ...
(value_as_address1): ... this function.
(value_as_address): New function.
2008-03-02 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.arch/amd64-i386-address.exp, gdb.arch/amd64-i386-address.S: New.
--- gdb/value.c 21 Mar 2009 03:03:53 -0000 1.79
+++ gdb/value.c 29 Apr 2009 10:07:20 -0000
@@ -1258,11 +1258,11 @@ value_as_double (struct value *val)
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)
+/* Extract a value as a C pointer. Helper for value_as_address still does not
+ truncate the CORE_ADDR width. */
+
+static CORE_ADDR
+value_as_address1 (struct value *val)
{
/* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
whether we want this to be true eventually. */
@@ -1362,6 +1362,27 @@ 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.
+
+ This wrapper truncates the width to match target address width, */
+
+CORE_ADDR
+value_as_address (struct value *val)
+{
+ CORE_ADDR addr;
+ int addr_bit = gdbarch_addr_bit (current_gdbarch);
+
+ addr = value_as_address1 (val);
+
+ /* Compare ADDR_BIT first to avoid a compiler warning on shift overflow. */
+ if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
+ addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
+
+ return addr;
+}
\f
/* Unpack raw data (copied from debugee, target byte order) at VALADDR
as a long, or as a double, assuming the raw data is described
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.arch/amd64-i386-address.S 29 Apr 2009 10:07:20 -0000
@@ -0,0 +1,25 @@
+/* Copyright 2009 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ This file is part of the gdb testsuite. */
+
+_start: .globl _start
+ nop
+ int3
+ movl %esp, %ebx
+ /* Examining memory from $ebx fails, from $esp it succeeds. */
+ int3
+ nop
+ nop
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gdb/testsuite/gdb.arch/amd64-i386-address.exp 29 Apr 2009 10:07:20 -0000
@@ -0,0 +1,44 @@
+# Copyright 2009 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the gdb testsuite.
+
+# Test UNsigned extension of the 32-bit inferior address on a 64-bit host.
+
+if {![istarget "x86_64-*-*"]} then {
+ verbose "Skipping amd64->i386 adress test."
+ return
+}
+
+if [prepare_for_testing amd64-i386-address.exp amd64-i386-address amd64-i386-address.S [list debug "additional_flags=-m32 -nostdlib"]] {
+ return -1
+}
+
+gdb_run_cmd
+
+set test "trap stop"
+gdb_test_multiple "" $test {
+ -re "Program received signal SIGTRAP,.*_start .*$gdb_prompt $" {
+ pass $test
+ }
+}
+
+gdb_test "stepi" ".*_start .*int3.*"
+
+gdb_test "x/x \$esp" "0x\[0-9a-f\]*:\t0x0*1"
+
+# Failure case would be:
+# 0xff8d7f00: Cannot access memory at address 0xff8d7f00
+gdb_test "x/x \$ebx" "0x\[0-9a-f\]*:\t0x0*1"
next reply other threads:[~2009-04-29 10:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-29 10:27 Jan Kratochvil [this message]
2009-04-29 19:05 ` Mark Kettenis
2009-04-29 20:29 ` Jan Kratochvil
2009-04-29 20:45 ` Jan Kratochvil
2009-06-25 16:33 ` Tom Tromey
2009-07-06 8:19 ` Jan Kratochvil
2009-07-07 16:24 ` Ulrich Weigand
2009-07-07 16:54 ` Daniel Jacobowitz
2009-07-07 18:00 ` Mark Kettenis
2009-07-07 18:22 ` Jan Kratochvil
2009-07-07 18:43 ` Mark Kettenis
2009-07-08 13:20 ` [patch] /* */ for target_thread_architecture [Re: [patch] Fix i386 memory-by-register access on amd64] Jan Kratochvil
2009-07-09 12:51 ` Ulrich Weigand
2009-07-09 16:36 ` Jan Kratochvil
2009-07-08 14:42 ` [patch] Fix i386 memory-by-register access on amd64 Jan Kratochvil
2009-07-13 18:10 ` Ulrich Weigand
2009-07-13 19:42 ` Mark Kettenis
2009-07-13 20:32 ` Jan Kratochvil
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=20090429102719.GA10117@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