All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <dan@debian.org>
To: linux-kernel@vger.kernel.org, torvalds@transmeta.com
Subject: Ptrace updates: event tracing for vfork finish and process exit [4/5]
Date: Thu, 6 Feb 2003 17:42:54 -0500	[thread overview]
Message-ID: <20030206224254.GD22762@nevyn.them.org> (raw)
In-Reply-To: <20030206223924.GA22688@nevyn.them.org>

This patch adds two new event hooks to ptrace:

  PTRACE_EVENT_EXIT, which triggers in do_exit().  This is useful to quickly
  find out where a program is making an exit syscall from, etc. - it
  triggers before the mm is released, so we can still get backtraces et
  cetera.

  PTRACE_EVENT_VFORK_DONE triggers in do_fork() after the vfork completion,
  i.e. when the child is done with the mm.  This is a safe way to figure out
  when we can re-insert breakpoints in the parent without the child hitting
  them.  It's the only safe way, in fact.

# --------------------------------------------
# 03/02/06	drow@nevyn.them.org	1.960
# Add PTRACE_O_TRACEVFORKDONE and PTRACE_O_TRACEEXIT facilities.
# --------------------------------------------

diff -Nru a/include/linux/ptrace.h b/include/linux/ptrace.h
--- a/include/linux/ptrace.h	Thu Feb  6 16:57:29 2003
+++ b/include/linux/ptrace.h	Thu Feb  6 16:57:29 2003
@@ -35,12 +35,16 @@
 #define PTRACE_O_TRACEVFORK	0x00000004
 #define PTRACE_O_TRACECLONE	0x00000008
 #define PTRACE_O_TRACEEXEC	0x00000010
+#define PTRACE_O_TRACEVFORKDONE	0x00000020
+#define PTRACE_O_TRACEEXIT	0x00000040
 
 /* Wait extended result codes for the above trace options.  */
 #define PTRACE_EVENT_FORK	1
 #define PTRACE_EVENT_VFORK	2
 #define PTRACE_EVENT_CLONE	3
 #define PTRACE_EVENT_EXEC	4
+#define PTRACE_EVENT_VFORK_DONE	5
+#define PTRACE_EVENT_EXIT	6
 
 #include <asm/ptrace.h>
 #include <linux/sched.h>
diff -Nru a/include/linux/sched.h b/include/linux/sched.h
--- a/include/linux/sched.h	Thu Feb  6 16:57:29 2003
+++ b/include/linux/sched.h	Thu Feb  6 16:57:29 2003
@@ -441,6 +441,8 @@
 #define PT_TRACE_VFORK	0x00000020
 #define PT_TRACE_CLONE	0x00000040
 #define PT_TRACE_EXEC	0x00000080
+#define PT_TRACE_VFORK_DONE	0x00000100
+#define PT_TRACE_EXIT	0x00000200
 
 #if CONFIG_SMP
 extern void set_cpus_allowed(task_t *p, unsigned long new_mask);
diff -Nru a/kernel/exit.c b/kernel/exit.c
--- a/kernel/exit.c	Thu Feb  6 16:57:29 2003
+++ b/kernel/exit.c	Thu Feb  6 16:57:29 2003
@@ -653,6 +653,9 @@
 
 	profile_exit_task(tsk);
  
+	if (unlikely(current->ptrace & PT_TRACE_EXIT))
+		ptrace_notify((PTRACE_EVENT_EXIT << 8) | SIGTRAP);
+
 fake_volatile:
 	acct_process(code);
 	__exit_mm(tsk);
diff -Nru a/kernel/fork.c b/kernel/fork.c
--- a/kernel/fork.c	Thu Feb  6 16:57:29 2003
+++ b/kernel/fork.c	Thu Feb  6 16:57:29 2003
@@ -1046,9 +1046,11 @@
 			ptrace_notify ((trace << 8) | SIGTRAP);
 		}
 
-		if (clone_flags & CLONE_VFORK)
+		if (clone_flags & CLONE_VFORK) {
 			wait_for_completion(&vfork);
-		else
+			if (unlikely (current->ptrace & PT_TRACE_VFORK_DONE))
+				ptrace_notify ((PTRACE_EVENT_VFORK_DONE << 8) | SIGTRAP);
+		} else
 			/*
 			 * Let the child process run first, to avoid most of the
 			 * COW overhead when the child exec()s afterwards.
diff -Nru a/kernel/ptrace.c b/kernel/ptrace.c
--- a/kernel/ptrace.c	Thu Feb  6 16:57:29 2003
+++ b/kernel/ptrace.c	Thu Feb  6 16:57:29 2003
@@ -277,9 +277,20 @@
 	else
 		child->ptrace &= ~PT_TRACE_EXEC;
 
+	if (data & PTRACE_O_TRACEVFORKDONE)
+		child->ptrace |= PT_TRACE_VFORK_DONE;
+	else
+		child->ptrace &= ~PT_TRACE_VFORK_DONE;
+
+	if (data & PTRACE_O_TRACEEXIT)
+		child->ptrace |= PT_TRACE_EXIT;
+	else
+		child->ptrace &= ~PT_TRACE_EXIT;
+
 	if ((data & (PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEFORK
 		    | PTRACE_O_TRACEVFORK | PTRACE_O_TRACECLONE
-		    | PTRACE_O_TRACEEXEC))
+		    | PTRACE_O_TRACEEXEC | PTRACE_O_TRACEEXIT
+		    | PTRACE_O_TRACEVFORKDONE))
 	    != data)
 		return -EINVAL;
 

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

  parent reply	other threads:[~2003-02-06 22:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-06 22:39 Ptrace updates [0/5] Daniel Jacobowitz
2003-02-06 22:40 ` Ptrace updates: has_stopped_jobs [1/5] Daniel Jacobowitz
2003-02-06 22:41 ` Ptrace updates: PTRACE_GETSIGINFO [2/5] Daniel Jacobowitz
2003-02-06 22:42 ` Ptrace updates: CLONE_PTRACE should use force_sig_specific [3/5] Daniel Jacobowitz
2003-02-06 22:42 ` Daniel Jacobowitz [this message]
2003-02-06 22:43 ` Ptrace updates: Prevent zombies when debugging LinuxThreads apps [5/5] Daniel Jacobowitz

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=20030206224254.GD22762@nevyn.them.org \
    --to=dan@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.