gdb/gdb-6.5-bz181390-memory-address-width.patch

198 lines
7.3 KiB
Diff
Raw Normal View History

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=181390
2006-09-28 Jan Kratochvil <jan.kratochvil@redhat.com>
* 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_address1): 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.
2008-03-02 Jan Kratochvil <jan.kratochvil@redhat.com>
Port to GDB-6.8pre.
New testcase `gdb.arch/amd64-i386-address.exp'.
Index: gdb-6.7.50.20080227/gdb/utils.c
===================================================================
--- gdb-6.7.50.20080227.orig/gdb/utils.c 2008-03-02 14:28:44.000000000 +0100
+++ gdb-6.7.50.20080227/gdb/utils.c 2008-03-02 14:35:09.000000000 +0100
@@ -2540,6 +2540,14 @@ paddr_nz (CORE_ADDR addr)
const char *
paddress (CORE_ADDR addr)
{
+ /* Do not 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
@@ -2553,6 +2561,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-6.7.50.20080227/gdb/value.c
===================================================================
--- gdb-6.7.50.20080227.orig/gdb/value.c 2008-01-18 18:07:40.000000000 +0100
+++ gdb-6.7.50.20080227/gdb/value.c 2008-03-02 14:36:38.000000000 +0100
@@ -983,11 +983,9 @@ 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)
+/* See `value_as_address' below - core of value to C pointer extraction. */
+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. */
@@ -1087,6 +1085,34 @@ 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;
+ int addr_bit;
+
+ addr = value_as_address1 (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? */
+
+ addr_bit = gdbarch_addr_bit (current_gdbarch);
+
+ 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
--- /dev/null 2008-03-01 10:30:54.797374318 +0100
+++ gdb-6.7.50.20080227/gdb/testsuite/gdb.arch/amd64-i386-address.S 2008-03-02 12:47:06.000000000 +0100
@@ -0,0 +1,32 @@
+/* Copyright 2008 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/>.
+
+ Please email any bugs, comments, and/or additions to this file to:
+ bug-gdb@gnu.org
+
+ This file is part of the gdb testsuite.
+
+ Test UNsigned extension of the 32-bit inferior address on a 64-bit host.
+ This file is based on the work by John Reiser.
+ This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
+ https://bugzilla.redhat.com/show_bug.cgi?id=181390 */
+
+_start: .globl _start
+ nop
+ int3
+ movl %esp,%ebx
+ int3 # examining memory from $ebx fails, from $esp succeeds
+ nop
+ nop
--- /dev/null 2008-03-01 10:30:54.797374318 +0100
+++ gdb-6.7.50.20080227/gdb/testsuite/gdb.arch/amd64-i386-address.exp 2008-03-02 12:57:11.000000000 +0100
@@ -0,0 +1,62 @@
+# Copyright 2008 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/>.
+
+# Please email any bugs, comments, and/or additions to this file to:
+# bug-gdb@gnu.org
+
+# This file is part of the gdb testsuite.
+
+# Test UNsigned extension of the 32-bit inferior address on a 64-bit host.
+# This file is based on the work by John Reiser.
+# This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
+# https://bugzilla.redhat.com/show_bug.cgi?id=181390
+
+if {![istarget "x86_64-*-*"]} then {
+ verbose "Skipping amd64->i386 adress test."
+ return
+}
+
+set testfile "amd64-i386-address"
+set srcfile ${testfile}.S
+set binfile ${objdir}/${subdir}/${testfile}
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "additional_flags=-m32 -nostdlib"]] != "" } {
+ untested amd64-i386-address.exp
+ return -1
+}
+
+# Get things started.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+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"