From patchwork Wed Aug 3 13:19:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 14276 Received: (qmail 105123 invoked by alias); 3 Aug 2016 13:19:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 105013 invoked by uid 89); 3 Aug 2016 13:19:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=swallow, our X-HELO: mail-pf0-f196.google.com Received: from mail-pf0-f196.google.com (HELO mail-pf0-f196.google.com) (209.85.192.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 03 Aug 2016 13:19:46 +0000 Received: by mail-pf0-f196.google.com with SMTP id i6so14688426pfe.0 for ; Wed, 03 Aug 2016 06:19:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=b/gsDhqw1QVWArbvL8NcRB3OKVTZwudw35sh2CAuQM4=; b=CQo5vLBEOMYWPhM55Q4Ya+BFd/bs/zac6fHnj+AqfiePWmo8hnD9UrAZpTIIzAINyr zqEC7IyNwsHBK9AUwR7k6HJPTrhBA2ieEgPzAO1TwcNAV2b1/j8n+wr3/QV8TFXson0x QR6kG57gOkbEaqejifFoYVEnRmb2rSt8I5SzhWj0kjVyRHFg07Vk8yt+lGKf5sHwkRow uNFXyHL0Cka3eCRlDnQV0Va5Cllw4CNRJ7YOOeDxHJmqivpDuRrqHYtLwLuz4otRU2wV eCfn1Doeyd6SmejYisj2vQLGlfxqB8mCxkgrUJE3Wu4mfe/bF3yW228mReiCddTByXan xnlg== X-Gm-Message-State: AEkoouv/Av6dWkzwvRAVylQ9++sTPUEHGZzba+VR7VWw+drSx1/7sFBLtgFQ2/j4EjDCXw== X-Received: by 10.98.88.131 with SMTP id m125mr111736669pfb.63.1470230384117; Wed, 03 Aug 2016 06:19:44 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id uc1sm12876241pac.24.2016.08.03.06.19.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 Aug 2016 06:19:43 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH master/7.12] Throw error when ptrace fail in regsets_fetch_inferior_registers Date: Wed, 3 Aug 2016 14:19:39 +0100 Message-Id: <1470230379-6790-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes When I run process-dies-while-detaching.exp with GDBserver, I see many warnings printed by GDBserver, ptrace(regsets_fetch_inferior_registers) PID=26183: No such process ptrace(regsets_fetch_inferior_registers) PID=26183: No such process ptrace(regsets_fetch_inferior_registers) PID=26184: No such process ptrace(regsets_fetch_inferior_registers) PID=26184: No such process regsets_fetch_inferior_registers is called when GDBserver resumes each lwp. #2 0x0000000000428260 in regsets_fetch_inferior_registers (regsets_info=0x4690d0 , regcache=0x31832020) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:5412 #3 0x00000000004070e8 in get_thread_regcache (thread=0x31832940, fetch=fetch@entry=1) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/regcache.c:58 #4 0x0000000000429c40 in linux_resume_one_lwp_throw (info=, signal=0, step=0, lwp=0x31832830) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:4463 #5 linux_resume_one_lwp (lwp=0x31832830, step=, signal=, info=) at /home/yao/SourceCode/gnu/gdb/git/gdb/gdbserver/linux-low.c:4573 The is the case that threads are disappeared when GDB/GDBserver resumes them. Our fix nowadays is to throw exception, caller linux_resume_one_lwp catches the exception, and swallow it if the lwp is gone. See linux-low.c:linux_resume_one_lwp. So this patch fixes the problem by throwing exception in regsets_fetch_inferior_registers. Another caller of regsets_fetch_inferior_registers, linux_fetch_registers, needs to catch the exception the same way as linux_resume_one_lwp does. gdb/gdbserver: 2016-08-02 Yao Qi * linux-low.c (regsets_fetch_inferior_registers): Throw exception on ptrace fail. (linux_fetch_registers): Rename to ... (linux_fetch_registers_throw): ... it. (linux_fetch_registers): Call linux_fetch_registers_throw and catch the exception. If check_ptrace_stopped_lwp_gone is false, throw it again. --- gdb/gdbserver/linux-low.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index e251ac4..c72b78c 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -5410,7 +5410,7 @@ regsets_fetch_inferior_registers (struct regsets_info *regsets_info, char s[256]; sprintf (s, "ptrace(regsets_fetch_inferior_registers) PID=%d", pid); - perror (s); + perror_with_name (_(s)); } } else @@ -5702,7 +5702,7 @@ usr_store_inferior_registers (const struct regs_info *regs_info, static void -linux_fetch_registers (struct regcache *regcache, int regno) +linux_fetch_registers_throw (struct regcache *regcache, int regno) { int use_regsets; int all = 0; @@ -5735,6 +5735,23 @@ linux_fetch_registers (struct regcache *regcache, int regno) } static void +linux_fetch_registers (struct regcache *regcache, int regno) +{ + TRY + { + linux_fetch_registers_throw (regcache, regno); + } + CATCH (ex, RETURN_MASK_ERROR) + { + struct lwp_info *lwp = get_thread_lwp (current_thread); + + if (!check_ptrace_stopped_lwp_gone (lwp)) + throw_exception (ex); + } + END_CATCH +} + +static void linux_store_registers (struct regcache *regcache, int regno) { int use_regsets;