From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22772 invoked by alias); 11 Apr 2013 11:21:28 -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 22758 invoked by uid 89); 11 Apr 2013 11:21:28 -0000 X-Spam-SWARE-Status: No, score=-3.9 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,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, 11 Apr 2013 11:21:06 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1UQFYs-00053R-Tt from Hafiz_Abid@mentor.com ; Thu, 11 Apr 2013 04:21:02 -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, 11 Apr 2013 04:21:02 -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.1.289.1; Thu, 11 Apr 2013 12:21:00 +0100 Date: Thu, 11 Apr 2013 11:21:00 -0000 From: "Abid, Hafiz" Subject: GDB function call failing due to memory protection of stack page in QEMU To: CC: , , Message-ID: <1365679257.9625.0@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/msg00025.txt.bz2 Hi All, I have faced a problem using GDB with user-mode qemu. Although problem=20=20 was observed for MIPS, I think it is a generic problem. I would=20=20 appreciate an advice from experts on how best to deal with. Here is the=20= =20 problem description. 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 is=20= =20 hit, GDB knows that function is complete and it can return control to=20=20 user. This breakpoint on stack causes problem for QEMU. When it runs=20=20 that instruction from stack, it add write-protection to that page. So=20=20 after the function call, GDB is not able to write to stack. So any=20=20 future function call or other operation that need to write to stack=20=20 will fail. I show an example session below taken mostly from=20=20 call-sc.exp of GDB testsuite. 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 line=20=20 fix and a patch is below. Second option was to not add write protection to the page in the first=20=20 place if i) Page currently has write access. ii) First instruction is a breakpoint. 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. Thanks, Abid 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. 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) Signed-off-by: Hafiz Abid Qadeer --- exec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 >From gdb-return-41991-listarch-gdb=sources.redhat.com@sourceware.org Fri Apr 12 06:19:57 2013 Return-Path: Delivered-To: listarch-gdb@sources.redhat.com Received: (qmail 7002 invoked by alias); 12 Apr 2013 06:19:56 -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 Delivered-To: mailing list gdb@sourceware.org Received: (qmail 6991 invoked by uid 89); 12 Apr 2013 06:19:56 -0000 X-Spam-SWARE-Status: No, score=-4.3 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RCVD_IN_DNSWL_NONE,RCVD_IN_HOSTKARMA_NO,SPF_SOFTFAIL autolearn=no version=3.3.1 Received: from mtaout21.012.net.il (HELO mtaout21.012.net.il) (80.179.55.169) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 12 Apr 2013 06:19:54 +0000 Received: from conversion-daemon.a-mtaout21.012.net.il by a-mtaout21.012.net.il (HyperSendmail v2007.08) id <0ML400B00P6OPF00@a-mtaout21.012.net.il> for gdb@sourceware.org; Fri, 12 Apr 2013 09:19:21 +0300 (IDT) Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout21.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0ML400BTCPK9K5A0@a-mtaout21.012.net.il> for gdb@sourceware.org; Fri, 12 Apr 2013 09:19:21 +0300 (IDT) Date: Fri, 12 Apr 2013 06:19:00 -0000 From: Eli Zaretskii Subject: Re: Completion on static functions In-reply-to: <83d2u6cnkv.fsf@gnu.org> To: gdb@sourceware.org Reply-to: Eli Zaretskii Message-id: <83li8o9sph.fsf@gnu.org> References: <83d2u6cnkv.fsf@gnu.org> X-SW-Source: 2013-04/txt/msg00026.txt.bz2 Content-length: 606 > Date: Sun, 07 Apr 2013 19:28:16 +0300 > From: Eli Zaretskii > > Sometimes "break foo TAB" does not complete the name of a function, > even though typing its full name as in "break foo_bar RET" sets a > breakpoint without any complaints. It happens with static functions, > but with all of them. Perhaps only inlined functions? > > I see this both in 7.5.1 and in 7.5.91, on MS-Windows, with programs > compiled with MinGW GCC 4.7.2. > > Does anyone else see this? Can this annoyance be fixed somehow? [No replies.] So does this silence mean that no one else bumped into this yet?