50a6238
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=181390
50a6238
50a6238
2006-09-28  Jan Kratochvil  <jan.kratochvil@redhat.com>
50a6238
50a6238
	* gdb/utils.c (paddress): Disable cutting of the printed addresses
50a6238
	to the target's address bit size; user wants to see everything.
407ebe9
	* gdb/value.c (value_as_address1): Original `value_as_address'.
50a6238
	(value_as_address): New `value_as_address' wrapper - cut memory address
50a6238
	to the target's address bit size, bugreport by John Reiser.
50a6238
25ff8a1
2008-03-02  Jan Kratochvil  <jan.kratochvil@redhat.com>
25ff8a1
25ff8a1
	Port to GDB-6.8pre.
25ff8a1
	New testcase `gdb.arch/amd64-i386-address.exp'.
50a6238
25ff8a1
Index: gdb-6.7.50.20080227/gdb/utils.c
50a6238
===================================================================
25ff8a1
--- gdb-6.7.50.20080227.orig/gdb/utils.c	2008-03-02 14:28:44.000000000 +0100
25ff8a1
+++ gdb-6.7.50.20080227/gdb/utils.c	2008-03-02 14:35:09.000000000 +0100
25ff8a1
@@ -2540,6 +2540,14 @@ paddr_nz (CORE_ADDR addr)
50a6238
 const char *
50a6238
 paddress (CORE_ADDR addr)
50a6238
 {
50a6238
+  /* Do not cut the address as the user should see all the information
50a6238
+     available.  Otherwise 64-bit gdb debugging 32-bit inferior would
50a6238
+     report for `x/x 0xffffffffffffce70' error
50a6238
+     `Cannot access memory at 0xffffce70' while the error occured just
50a6238
+     because of the higher order bits 0xffffffff00000000 there.
50a6238
+     This specific error no longer occurs as the address is now cut
50a6238
+     during execution by `value_as_address'.  */
50a6238
+#if 0
50a6238
   /* Truncate address to the size of a target address, avoiding shifts
50a6238
      larger or equal than the width of a CORE_ADDR.  The local
50a6238
      variable ADDR_BIT stops the compiler reporting a shift overflow
25ff8a1
@@ -2553,6 +2561,8 @@ paddress (CORE_ADDR addr)
50a6238
 
50a6238
   if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
50a6238
     addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
50a6238
+#endif
50a6238
+
50a6238
   return hex_string (addr);
50a6238
 }
50a6238
 
25ff8a1
Index: gdb-6.7.50.20080227/gdb/value.c
50a6238
===================================================================
25ff8a1
--- gdb-6.7.50.20080227.orig/gdb/value.c	2008-01-18 18:07:40.000000000 +0100
25ff8a1
+++ gdb-6.7.50.20080227/gdb/value.c	2008-03-02 14:36:38.000000000 +0100
25ff8a1
@@ -983,11 +983,9 @@ value_as_double (struct value *val)
50a6238
   return foo;
50a6238
 }
25ff8a1
 
50a6238
-/* Extract a value as a C pointer. Does not deallocate the value.  
50a6238
-   Note that val's type may not actually be a pointer; value_as_long
50a6238
-   handles all the cases.  */
50a6238
-CORE_ADDR
50a6238
-value_as_address (struct value *val)
50a6238
+/* See `value_as_address' below - core of value to C pointer extraction.  */
50a6238
+static CORE_ADDR
407ebe9
+value_as_address1 (struct value *val)
50a6238
 {
50a6238
   /* Assume a CORE_ADDR can fit in a LONGEST (for now).  Not sure
50a6238
      whether we want this to be true eventually.  */
25ff8a1
@@ -1087,6 +1085,34 @@ value_as_address (struct value *val)
50a6238
   return unpack_long (value_type (val), value_contents (val));
50a6238
 #endif
50a6238
 }
50a6238
+
50a6238
+/* Extract a value as a C pointer. Does not deallocate the value.  
50a6238
+   Note that val's type may not actually be a pointer; value_as_long
50a6238
+   handles all the cases.  */
50a6238
+CORE_ADDR
50a6238
+value_as_address (struct value *val)
50a6238
+{
50a6238
+  CORE_ADDR addr;
eb9d945
+  int addr_bit;
50a6238
+
407ebe9
+  addr = value_as_address1 (val);
50a6238
+
50a6238
+  /* Truncate address to the size of a target address, avoiding shifts
50a6238
+     larger or equal than the width of a CORE_ADDR.  The local
50a6238
+     variable ADDR_BIT stops the compiler reporting a shift overflow
50a6238
+     when it won't occur. */
50a6238
+  /* NOTE: This assumes that the significant address information is
50a6238
+     kept in the least significant bits of ADDR - the upper bits were
50a6238
+     either zero or sign extended.  Should ADDRESS_TO_POINTER() or
50a6238
+     some ADDRESS_TO_PRINTABLE() be used to do the conversion?  */
50a6238
+
eb9d945
+  addr_bit = gdbarch_addr_bit (current_gdbarch);
50a6238
+
50a6238
+  if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
50a6238
+    addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
50a6238
+
50a6238
+  return addr;
50a6238
+}
50a6238
 
50a6238
 /* Unpack raw data (copied from debugee, target byte order) at VALADDR
50a6238
    as a long, or as a double, assuming the raw data is described
25ff8a1
--- /dev/null	2008-03-01 10:30:54.797374318 +0100
25ff8a1
+++ gdb-6.7.50.20080227/gdb/testsuite/gdb.arch/amd64-i386-address.S	2008-03-02 12:47:06.000000000 +0100
25ff8a1
@@ -0,0 +1,32 @@
25ff8a1
+/* Copyright 2008 Free Software Foundation, Inc.
25ff8a1
+
25ff8a1
+   This program is free software; you can redistribute it and/or modify
25ff8a1
+   it under the terms of the GNU General Public License as published by
25ff8a1
+   the Free Software Foundation; either version 3 of the License, or
25ff8a1
+   (at your option) any later version.
25ff8a1
+
25ff8a1
+   This program is distributed in the hope that it will be useful,
25ff8a1
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
25ff8a1
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25ff8a1
+   GNU General Public License for more details.
25ff8a1
+
25ff8a1
+   You should have received a copy of the GNU General Public License
25ff8a1
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
25ff8a1
+
25ff8a1
+   Please email any bugs, comments, and/or additions to this file to:
25ff8a1
+   bug-gdb@gnu.org
25ff8a1
+
25ff8a1
+   This file is part of the gdb testsuite.
25ff8a1
+
25ff8a1
+   Test UNsigned extension of the 32-bit inferior address on a 64-bit host.
25ff8a1
+   This file is based on the work by John Reiser.
25ff8a1
+   This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
25ff8a1
+   https://bugzilla.redhat.com/show_bug.cgi?id=181390  */
25ff8a1
+
25ff8a1
+_start:	.globl	_start
25ff8a1
+	nop
25ff8a1
+	int3
25ff8a1
+	movl	%esp,%ebx
25ff8a1
+	int3	# examining memory from $ebx fails, from $esp succeeds
25ff8a1
+	nop
25ff8a1
+	nop
25ff8a1
--- /dev/null	2008-03-01 10:30:54.797374318 +0100
25ff8a1
+++ gdb-6.7.50.20080227/gdb/testsuite/gdb.arch/amd64-i386-address.exp	2008-03-02 12:57:11.000000000 +0100
25ff8a1
@@ -0,0 +1,62 @@
25ff8a1
+# Copyright 2008 Free Software Foundation, Inc.
25ff8a1
+
25ff8a1
+# This program is free software; you can redistribute it and/or modify
25ff8a1
+# it under the terms of the GNU General Public License as published by
25ff8a1
+# the Free Software Foundation; either version 3 of the License, or
25ff8a1
+# (at your option) any later version.
25ff8a1
+#
25ff8a1
+# This program is distributed in the hope that it will be useful,
25ff8a1
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25ff8a1
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25ff8a1
+# GNU General Public License for more details.
25ff8a1
+#
25ff8a1
+# You should have received a copy of the GNU General Public License
25ff8a1
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
25ff8a1
+
25ff8a1
+# Please email any bugs, comments, and/or additions to this file to:
25ff8a1
+# bug-gdb@gnu.org
25ff8a1
+
25ff8a1
+# This file is part of the gdb testsuite.
25ff8a1
+
25ff8a1
+# Test UNsigned extension of the 32-bit inferior address on a 64-bit host.
25ff8a1
+# This file is based on the work by John Reiser.
25ff8a1
+# This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
25ff8a1
+# https://bugzilla.redhat.com/show_bug.cgi?id=181390
25ff8a1
+
25ff8a1
+if {![istarget "x86_64-*-*"]} then {
25ff8a1
+    verbose "Skipping amd64->i386 adress test."
25ff8a1
+    return
25ff8a1
+}
25ff8a1
+
25ff8a1
+set testfile "amd64-i386-address"
25ff8a1
+set srcfile ${testfile}.S
25ff8a1
+set binfile ${objdir}/${subdir}/${testfile}
25ff8a1
+
25ff8a1
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "additional_flags=-m32 -nostdlib"]] != "" } {
25ff8a1
+    untested amd64-i386-address.exp
25ff8a1
+    return -1
25ff8a1
+}
25ff8a1
+
25ff8a1
+# Get things started.
25ff8a1
+
25ff8a1
+gdb_exit
25ff8a1
+gdb_start
25ff8a1
+gdb_reinitialize_dir $srcdir/$subdir
25ff8a1
+gdb_load ${binfile}
25ff8a1
+
25ff8a1
+gdb_run_cmd
25ff8a1
+
25ff8a1
+set test "trap stop"
25ff8a1
+gdb_test_multiple "" $test {
25ff8a1
+    -re "Program received signal SIGTRAP,.*_start .*$gdb_prompt $" {
25ff8a1
+	pass $test
25ff8a1
+    }
25ff8a1
+}
25ff8a1
+
25ff8a1
+gdb_test "stepi" ".*_start .*int3.*"
25ff8a1
+
25ff8a1
+gdb_test "x/x \$esp" "0x\[0-9a-f\]*:\t0x0*1"
25ff8a1
+
25ff8a1
+# Failure case would be:
25ff8a1
+# 	0xff8d7f00:     Cannot access memory at address 0xff8d7f00
25ff8a1
+gdb_test "x/x \$ebx" "0x\[0-9a-f\]*:\t0x0*1"