Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: gdb-patches@sourceware.org
Subject: [PATCH master/7.12] Throw error when ptrace fail in regsets_fetch_inferior_registers
Date: Wed, 03 Aug 2016 13:19:00 -0000	[thread overview]
Message-ID: <1470230379-6790-1-git-send-email-yao.qi@linaro.org> (raw)

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 <aarch64_regsets_info>, 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=<optimized out>, 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=<optimized out>, signal=<optimized out>, info=<optimized out>)
    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  <yao.qi@linaro.org>

	* 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;
-- 
1.9.1


             reply	other threads:[~2016-08-03 13:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-03 13:19 Yao Qi [this message]
2016-08-03 14:21 ` Pedro Alves
2016-08-03 15:43   ` Yao Qi
2016-08-03 17:54     ` Pedro Alves
2016-08-04 10:13       ` Yao Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1470230379-6790-1-git-send-email-yao.qi@linaro.org \
    --to=qiyaoltc@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox