1 https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=181390
3 2006-09-28 Jan Kratochvil <jan.kratochvil@redhat.com>
5 * gdb/utils.c (paddress): Disable cutting of the printed addresses
6 to the target's address bit size; user wants to see everything.
7 * gdb/value.c (value_as_address1): Original `value_as_address'.
8 (value_as_address): New `value_as_address' wrapper - cut memory address
9 to the target's address bit size, bugreport by John Reiser.
11 2008-03-02 Jan Kratochvil <jan.kratochvil@redhat.com>
14 New testcase `gdb.arch/amd64-i386-address.exp'.
16 Index: gdb-6.7.50.20080227/gdb/utils.c
17 ===================================================================
18 --- gdb-6.7.50.20080227.orig/gdb/utils.c 2008-03-02 14:28:44.000000000 +0100
19 +++ gdb-6.7.50.20080227/gdb/utils.c 2008-03-02 14:35:09.000000000 +0100
20 @@ -2540,6 +2540,14 @@ paddr_nz (CORE_ADDR addr)
22 paddress (CORE_ADDR addr)
24 + /* Do not cut the address as the user should see all the information
25 + available. Otherwise 64-bit gdb debugging 32-bit inferior would
26 + report for `x/x 0xffffffffffffce70' error
27 + `Cannot access memory at 0xffffce70' while the error occured just
28 + because of the higher order bits 0xffffffff00000000 there.
29 + This specific error no longer occurs as the address is now cut
30 + during execution by `value_as_address'. */
32 /* Truncate address to the size of a target address, avoiding shifts
33 larger or equal than the width of a CORE_ADDR. The local
34 variable ADDR_BIT stops the compiler reporting a shift overflow
35 @@ -2553,6 +2561,8 @@ paddress (CORE_ADDR addr)
37 if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
38 addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
41 return hex_string (addr);
44 Index: gdb-6.7.50.20080227/gdb/value.c
45 ===================================================================
46 --- gdb-6.7.50.20080227.orig/gdb/value.c 2008-01-18 18:07:40.000000000 +0100
47 +++ gdb-6.7.50.20080227/gdb/value.c 2008-03-02 14:36:38.000000000 +0100
48 @@ -983,11 +983,9 @@ value_as_double (struct value *val)
52 -/* Extract a value as a C pointer. Does not deallocate the value.
53 - Note that val's type may not actually be a pointer; value_as_long
54 - handles all the cases. */
56 -value_as_address (struct value *val)
57 +/* See `value_as_address' below - core of value to C pointer extraction. */
59 +value_as_address1 (struct value *val)
61 /* Assume a CORE_ADDR can fit in a LONGEST (for now). Not sure
62 whether we want this to be true eventually. */
63 @@ -1087,6 +1085,34 @@ value_as_address (struct value *val)
64 return unpack_long (value_type (val), value_contents (val));
68 +/* Extract a value as a C pointer. Does not deallocate the value.
69 + Note that val's type may not actually be a pointer; value_as_long
70 + handles all the cases. */
72 +value_as_address (struct value *val)
77 + addr = value_as_address1 (val);
79 + /* Truncate address to the size of a target address, avoiding shifts
80 + larger or equal than the width of a CORE_ADDR. The local
81 + variable ADDR_BIT stops the compiler reporting a shift overflow
82 + when it won't occur. */
83 + /* NOTE: This assumes that the significant address information is
84 + kept in the least significant bits of ADDR - the upper bits were
85 + either zero or sign extended. Should ADDRESS_TO_POINTER() or
86 + some ADDRESS_TO_PRINTABLE() be used to do the conversion? */
88 + addr_bit = gdbarch_addr_bit (current_gdbarch);
90 + if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
91 + addr &= ((CORE_ADDR) 1 << addr_bit) - 1;
96 /* Unpack raw data (copied from debugee, target byte order) at VALADDR
97 as a long, or as a double, assuming the raw data is described
98 --- /dev/null 2008-03-01 10:30:54.797374318 +0100
99 +++ gdb-6.7.50.20080227/gdb/testsuite/gdb.arch/amd64-i386-address.S 2008-03-02 12:47:06.000000000 +0100
101 +/* Copyright 2008 Free Software Foundation, Inc.
103 + This program is free software; you can redistribute it and/or modify
104 + it under the terms of the GNU General Public License as published by
105 + the Free Software Foundation; either version 3 of the License, or
106 + (at your option) any later version.
108 + This program is distributed in the hope that it will be useful,
109 + but WITHOUT ANY WARRANTY; without even the implied warranty of
110 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
111 + GNU General Public License for more details.
113 + You should have received a copy of the GNU General Public License
114 + along with this program. If not, see <http://www.gnu.org/licenses/>.
116 + Please email any bugs, comments, and/or additions to this file to:
119 + This file is part of the gdb testsuite.
121 + Test UNsigned extension of the 32-bit inferior address on a 64-bit host.
122 + This file is based on the work by John Reiser.
123 + This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
124 + https://bugzilla.redhat.com/show_bug.cgi?id=181390 */
126 +_start: .globl _start
130 + int3 # examining memory from $ebx fails, from $esp succeeds
133 --- /dev/null 2008-03-01 10:30:54.797374318 +0100
134 +++ gdb-6.7.50.20080227/gdb/testsuite/gdb.arch/amd64-i386-address.exp 2008-03-02 12:57:11.000000000 +0100
136 +# Copyright 2008 Free Software Foundation, Inc.
138 +# This program is free software; you can redistribute it and/or modify
139 +# it under the terms of the GNU General Public License as published by
140 +# the Free Software Foundation; either version 3 of the License, or
141 +# (at your option) any later version.
143 +# This program is distributed in the hope that it will be useful,
144 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
145 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
146 +# GNU General Public License for more details.
148 +# You should have received a copy of the GNU General Public License
149 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
151 +# Please email any bugs, comments, and/or additions to this file to:
154 +# This file is part of the gdb testsuite.
156 +# Test UNsigned extension of the 32-bit inferior address on a 64-bit host.
157 +# This file is based on the work by John Reiser.
158 +# This file was created by Jan Kratochvil <jan.kratochvil@redhat.com>.
159 +# https://bugzilla.redhat.com/show_bug.cgi?id=181390
161 +if {![istarget "x86_64-*-*"]} then {
162 + verbose "Skipping amd64->i386 adress test."
166 +set testfile "amd64-i386-address"
167 +set srcfile ${testfile}.S
168 +set binfile ${objdir}/${subdir}/${testfile}
170 +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "additional_flags=-m32 -nostdlib"]] != "" } {
171 + untested amd64-i386-address.exp
175 +# Get things started.
179 +gdb_reinitialize_dir $srcdir/$subdir
184 +set test "trap stop"
185 +gdb_test_multiple "" $test {
186 + -re "Program received signal SIGTRAP,.*_start .*$gdb_prompt $" {
191 +gdb_test "stepi" ".*_start .*int3.*"
193 +gdb_test "x/x \$esp" "0x\[0-9a-f\]*:\t0x0*1"
195 +# Failure case would be:
196 +# 0xff8d7f00: Cannot access memory at address 0xff8d7f00
197 +gdb_test "x/x \$ebx" "0x\[0-9a-f\]*:\t0x0*1"