public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (sw) (timeout) with Linux 2.6.32 and older version
@ 2014-04-03  8:12 Hui Zhu
  2014-05-28 19:19 ` Pedro Alves
  0 siblings, 1 reply; 11+ messages in thread
From: Hui Zhu @ 2014-04-03  8:12 UTC (permalink / raw)
  To: gdb-patches ml

Got gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (sw)
(timeout) with Linux 2.6.32 and older version.

The rootcause is after the test use "set can-use-hw-watchpoints 0" let GDB
doesn't use hardware breakpoint and set a watchpoint on "global", GDB
continue will keep single step inside function "vfork".
The Linux 2.6.32 and older version doesn't have commit
6580807da14c423f0d0a708108e6df6ebc8bc83d (get more info please goto
http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/?id=6580807da14c423f0d0a708108e6df6ebc8bc83d).
When the function "vfork" do syscall, the single step flag TIF_SINGLESTEP
will copy to child process.
Then GDB detach it, child process and parent process will be hanged.

So I make a patch that do a single step before detach.  Then TIF_SINGLESTEP
of child process in old Linux kernel will be cleared before detach.
Child process in new Linux kernel will not be affected by this single step.

The patch was tested and pass regression in new linux
kernel (3.13.6-200.fc20.x86_64) and old Linux kernel (2.6.32-38-server).

Please help me review it.

Thanks,
Hui

2014-04-03  Hui Zhu  <hui@codesourcery.com>

	* linux-nat.c (linux_child_follow_fork): do a single step before
	detach.

--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -442,6 +442,26 @@ holding the child stopped.  Try \"set de
  
  	  if (linux_nat_prepare_to_resume != NULL)
  	    linux_nat_prepare_to_resume (child_lp);
+
+	  /* When debug a inferior in the architecture that support
+	     hardware single step and the Linux kernel without commit
+	     6580807da14c423f0d0a708108e6df6ebc8bc83d, the vfork child
+	     process will starts with TIF_SINGLESTEP/X86_EFLAGS_TF bits
+	     if the parent process has it.
+	     So let child process do a single step under GDB control
+	     before detach it to remove this flags.  */
+
+	  if (!gdbarch_software_single_step_p (target_thread_architecture
+						   (child_lp->ptid)))
+	    {
+	      int status;
+
+	      if (ptrace (PTRACE_SINGLESTEP, child_pid, 0, 0) < 0)
+		perror_with_name (_("Couldn't do single step"));
+	      if (my_waitpid (child_pid, &status, 0) < 0)
+		perror_with_name (_("Couldn't wait vfork process"));
+	    }
+
  	  ptrace (PTRACE_DETACH, child_pid, 0, 0);
  
  	  do_cleanups (old_chain);

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-07-05  6:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-03  8:12 [PATCH] Fix gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (sw) (timeout) with Linux 2.6.32 and older version Hui Zhu
2014-05-28 19:19 ` Pedro Alves
2014-06-04  8:43   ` Hui Zhu
2014-06-04 16:11     ` Pedro Alves
2014-06-05  7:48   ` Hui Zhu
2014-06-05  8:43     ` Pedro Alves
2014-06-08 11:16       ` Hui Zhu
2014-06-09 13:58         ` [pushed] Fix a bunch of fork related regressions. (was: Re: [PATCH] Fix gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (sw) (timeout) with Linux 2.6.32 and older version) Pedro Alves
2014-07-03 16:24         ` [PATCH] Fix gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (sw) (timeout) with Linux 2.6.32 and older version Hui Zhu
2014-07-04 17:51           ` [PATCH] Handle signals sent to a fork/vfork child before it has a chance to first run (Re: [PATCH] Fix gdb.base/watch-vfork.exp: Watchpoint triggers after vfork (sw) (timeout) with Linux 2.6.32 and older version) Pedro Alves
2014-07-05  6:08             ` Hui Zhu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).