From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24162 invoked by alias); 8 Jul 2009 14:42:01 -0000 Received: (qmail 24153 invoked by uid 22791); 8 Jul 2009 14:42:00 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 08 Jul 2009 14:41:50 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n68Efk6K026676; Wed, 8 Jul 2009 10:41:46 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n68Efixl030787; Wed, 8 Jul 2009 10:41:45 -0400 Received: from host0.dyn.jankratochvil.net (sebastian-int.corp.redhat.com [172.16.52.221]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n68Effis018148; Wed, 8 Jul 2009 10:41:44 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id n68EfePg012699; Wed, 8 Jul 2009 16:41:40 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.3/Submit) id n68Efb7O012680; Wed, 8 Jul 2009 16:41:37 +0200 Date: Wed, 08 Jul 2009 14:42:00 -0000 From: Jan Kratochvil To: Ulrich Weigand , Mark Kettenis Cc: drow@false.org, Tom Tromey , gdb-patches@sourceware.org Subject: Re: [patch] Fix i386 memory-by-register access on amd64 Message-ID: <20090708144136.GA6490@host0.dyn.jankratochvil.net> References: <200907071624.n67GO6bj015890@d12av02.megacenter.de.ibm.com> <200907071759.n67HxhcF026713@brahms.sibelius.xs4all.nl> <20090707182203.GA24153@host0.dyn.jankratochvil.net> <200907071843.n67IhIdV005570@brahms.sibelius.xs4all.nl> <20090706081927.GA18324@host0.dyn.jankratochvil.net> <200907071624.n67GO6bj015890@d12av02.megacenter.de.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200907071624.n67GO6bj015890@d12av02.megacenter.de.ibm.com> User-Agent: Mutt/1.5.19 (2009-01-05) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-07/txt/msg00248.txt.bz2 On Tue, 07 Jul 2009 18:24:06 +0200, Ulrich Weigand wrote: > target_thread_architecture is wrong for this purpose; + > This should be done inside the TARGET_OBJECT_MEMORY case; Fixed in the patch. > (The assert seems superfluous to me; "offset" is a local variable to this > function, so we should know its type already. Other code in this function > would already fail if offset were of any other type.) Originally I thought OFFSET should be later changed to CORE_ADDR. Now I see for other `enum target_object' larger OFFSET may make sense. On Tue, 07 Jul 2009 20:43:18 +0200, Mark Kettenis wrote: > > Date: Tue, 7 Jul 2009 20:22:04 +0200 > > From: Jan Kratochvil > > > > On Tue, 07 Jul 2009 19:59:43 +0200, Mark Kettenis wrote: > > > But then I don't understand Jan's diff at all. Linux has its own > > > implementation for TARGET_OBJECT_MEMORY in linux-nat.c. Why isn't > > > that one used? > > > > Expecting the same problem must affect even non-Linux ptrace usage. I will > > move it to linux-nat.c if you think so. > > I suppose I should have been more specific. You are trying to fix a > bug that you see on Linux isn't it? Yes. > And this fix should only be relevant for TARGET_OBJECT_MEMORY isn't > it? Yes. I was not sure before and I though it would not hurt other `enum target_object's but - you are right, yes. > But Linux has its own implementation for doing TARGET_OBJECT_MEMORY > xfers in linux_proc_xfer_partial. I did not much notice linux_proc_xfer_partial role in this bug, thanks. * I was not able to reproduce the problem for linux_proc_xfer_partial without removing there: /* Don't bother for one word. */ if (len < 3 * sizeof (long)) return 0; because: * x/gx is the largest size - 8 bytes - which is still smaller. * x/NUMx generates NUM small transfers (not one NUM*8 transfer). * These already truncate the address to gdbarch_addr_bit in the caller: * dump memory * print *(struct large *) $ebx * inf_ptrace_xfer_partial gets silently used as a fallback when linux_proc_xfer_partial fails. * linux_proc_xfer_partial has been broken so far even on native 32bit GDB debugging 32bit inferior with GDB built using --enable-64-bit-bfd (and thus having 64-bit CORE_ADDR). Due to the silent fallback just nobody has noticed it. Therefore fixed linux_xfer_partial. Therefore it no longer needs the fix to be present also in inf_ptrace_xfer_partial. I do not know how non-Linux OSes handle the debugging of 32bit inferior on 64bit GDB so I have no opinion whether the inf_ptrace_xfer_partial patch makes sense, i can drop it. > So I don't understand how this change fixes anything on Linux. With my former patch linux_proc_xfer_partial failed and the fix in the ptrace backend did handle the transfer. Thanks, Jan 2009-07-08 Jan Kratochvil Fix memory access from signed 32bit inferior registers on 64bit GDB. * inf-ptrace.c (inf_ptrace_xfer_partial ): New variable addr_bit. Mask OFFSET by the ADDR_BIT width. * linux-nat.c (linux_xfer_partial ): Likewise. 2009-07-08 Jan Kratochvil * gdb.arch/amd64-i386-address.exp, gdb.arch/amd64-i386-address.S: New. --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -457,6 +457,19 @@ inf_ptrace_xfer_partial (struct target_ops *ops, enum target_object object, switch (object) { case TARGET_OBJECT_MEMORY: + { + int addr_bit = gdbarch_addr_bit (target_gdbarch); + + /* GDB calculates all the addresses in possibly larget width of the + address. Address width needs to be masked before its final use + - either by linux_proc_xfer_partial or inf_ptrace_xfer_partial. + + Compare ADDR_BIT first to avoid a compiler warning on shift + overflow. */ + + if (addr_bit < (sizeof (ULONGEST) * HOST_CHAR_BIT)) + offset &= ((ULONGEST) 1 << addr_bit) - 1; + } #ifdef PT_IO /* OpenBSD 3.1, NetBSD 1.6 and FreeBSD 5.0 have a new PT_IO request that promises to be much more efficient in reading --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -4260,6 +4260,20 @@ linux_xfer_partial (struct target_ops *ops, enum target_object object, return linux_nat_xfer_osdata (ops, object, annex, readbuf, writebuf, offset, len); + /* GDB calculates all the addresses in possibly larget width of the address. + Address width needs to be masked before its final use - either by + linux_proc_xfer_partial or inf_ptrace_xfer_partial. + + Compare ADDR_BIT first to avoid a compiler warning on shift overflow. */ + + if (object == TARGET_OBJECT_MEMORY) + { + int addr_bit = gdbarch_addr_bit (target_gdbarch); + + if (addr_bit < (sizeof (ULONGEST) * HOST_CHAR_BIT)) + offset &= ((ULONGEST) 1 << addr_bit) - 1; + } + xfer = linux_proc_xfer_partial (ops, object, annex, readbuf, writebuf, offset, len); if (xfer != 0) --- /dev/null +++ b/gdb/testsuite/gdb.arch/amd64-i386-address.S @@ -0,0 +1,24 @@ +/* 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 . + + This file is part of the gdb testsuite. */ + +_start: .globl _start + movl $0xdeadf00d, %eax + pushl %eax + movl %esp, %ebx + int3 + nop + nop --- /dev/null +++ b/gdb/testsuite/gdb.arch/amd64-i386-address.exp @@ -0,0 +1,43 @@ +# 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 . + +# This file is part of the gdb testsuite. + +# Test UNsigned extension of the 32-bit inferior address on a 64-bit host. +# On native 32-bit host the test always PASSed. + +if {![istarget "x86_64-*-*"] && ![istarget "i?86-*-*"]} 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 "x/wx \$esp" "0x\[0-9a-f\]*:\t0xdeadf00d" + +# Failure case would be: +# 0xff8d7f00: Cannot access memory at address 0xff8d7f00 +gdb_test "x/wx \$ebx" "0x\[0-9a-f\]*:\t0xdeadf00d"