From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24060 invoked by alias); 18 Apr 2013 08:31:20 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 24049 invoked by uid 89); 18 Apr 2013 08:31:19 -0000 X-Spam-SWARE-Status: No, score=-4.7 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL autolearn=ham version=3.3.1 Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 18 Apr 2013 08:31:18 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1USkFQ-0003Oj-Co from Hafiz_Abid@mentor.com ; Thu, 18 Apr 2013 01:31:16 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Thu, 18 Apr 2013 01:31:16 -0700 Received: from abidh-ubunto1104 (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server (TLS) id 14.2.247.3; Thu, 18 Apr 2013 09:31:14 +0100 Date: Thu, 18 Apr 2013 08:31:00 -0000 From: "Abid, Hafiz" Subject: Re: GDB function call failing due to memory protection of stack page in QEMU To: CC: , , References: <1365679257.9625.0@abidh-ubunto1104> In-Reply-To: <1365679257.9625.0@abidh-ubunto1104> (from hafiz_abid@mentor.com on Thu Apr 11 12:20:57 2013) Message-ID: <1366273870.30939.2@abidh-ubunto1104> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; delsp=Yes; format=Flowed Content-Disposition: inline Content-Transfer-Encoding: quoted-printable X-SW-Source: 2013-04/txt/msg00051.txt.bz2 ping. On 11/04/13 12:20:57, Abid, Hafiz wrote: > Hi All, > I have faced a problem using GDB with user-mode qemu. Although=20=20 > problem was observed for MIPS, I think it is a generic problem. I=20=20 > would appreciate an advice from experts on how best to deal with.=20=20 > Here is the problem description. >=20 > GDB has ability to call function from the program being debugged=20=20 > (http://sourceware.org/gdb/onlinedocs/gdb/Calling.html#Calling). For=20=20 > MIPS (and on other architectures), it put a breakpoint on the stack=20=20 > that is used as return address of the function. When that breakpoint=20=20 > is hit, GDB knows that function is complete and it can return control=20= =20 > to user. This breakpoint on stack causes problem for QEMU. When it=20=20 > runs that instruction from stack, it add write-protection to that=20=20 > page. So after the function call, GDB is not able to write to stack.=20=20 > So any future function call or other operation that need to write to=20=20 > stack will fail. I show an example session below taken mostly from=20=20 > call-sc.exp of GDB testsuite. >=20 > There are 2 possible solution in my mind. One was to allow writing=20=20 > memory if this page originally had write access. This is a single=20=20 > line fix and a patch is below. >=20 > Second option was to not add write protection to the page in the=20=20 > first place if > i) Page currently has write access. > ii) First instruction is a breakpoint. >=20 > If 2nd looks a better option then I can prepare a patch for it. If=20=20 > there some other approach that will better solve this problem then=20=20 > please let me know. >=20 > Thanks, > Abid >=20 > GDB session: > GNU gdb (GDB) 7.4.50.20120716-cvs > Copyright (C) 2012 Free Software Foundation, Inc. > License GPLv3+: GNU GPL version 3 or later=20=20 > > This is free software: you are free to change and redistribute it. > There is NO WARRANTY, to the extent permitted by law. Type "show=20=20 > copying" > and "show warranty" for details. > This GDB was configured as "--host=3Di686-pc-linux-gnu=20=20 > --target=3Dmips-linux-gnu". > For bug reporting instructions, please see: > ... > Reading symbols from /home/abidh/work/mips-demo/call_static...done. > (gdb) target remote :8000 > Remote debugging using :8000 > [New Remote target] > [Switching to Remote target] > __start () at ../ports/sysdeps/mips/start.S:84 > 84 ../ports/sysdeps/mips/start.S: No such file or directory. > (gdb) break main > Breakpoint 1 at 0x4011e8: file call.c, line 63. > (gdb) c > Continuing. >=20 > Breakpoint 1, main () at call.c:63 > 63 Fun(foo);=09 > (gdb) p /c fun() > $1 =3D 49 '1' > (gdb) p /c fun() > Cannot access memory at address 0x40800258 > (gdb) >=20 > Signed-off-by: Hafiz Abid Qadeer > --- > exec.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) >=20 > diff --git a/exec.c b/exec.c > index fa1e0c3..af5610b 100644 > --- a/exec.c > +++ b/exec.c > @@ -1844,8 +1844,9 @@ int cpu_memory_rw_debug(CPUArchState *env,=20=20 > target_ulong addr, > if (!(flags & PAGE_VALID)) > return -1; > if (is_write) { > - if (!(flags & PAGE_WRITE)) > + if ((!(flags & PAGE_WRITE)) && (!(flags &=20=20 > PAGE_WRITE_ORG))) { > return -1; > + } > /* XXX: this code should not depend on lock_user */ > if (!(p =3D lock_user(VERIFY_WRITE, addr, l, 0))) > return -1; >--=20 > 1.7.9.5