Add MKTRACE

This commit is contained in:
Arun Thomas 2011-09-07 17:52:48 +02:00
parent 35d86581e5
commit 8a0901c4cb
8 changed files with 39 additions and 4 deletions

View file

@ -81,6 +81,10 @@ CPPFLAGS+= -DUSE_UPDATE
CPPFLAGS+= -DUSE_STATECTL CPPFLAGS+= -DUSE_STATECTL
.endif .endif
.if ${USE_TRACE} != "no"
CPPFLAGS+= -DUSE_TRACE
.endif
# These come last, so the profiling buffer is at the end of the data segment # These come last, so the profiling buffer is at the end of the data segment
SRCS+= profile.c do_sprofile.c SRCS+= profile.c do_sprofile.c

View file

@ -20,7 +20,6 @@
#define USE_EXEC 1 /* update process after execute */ #define USE_EXEC 1 /* update process after execute */
#define USE_CLEAR 1 /* clean up after process exit */ #define USE_CLEAR 1 /* clean up after process exit */
#define USE_EXIT 1 /* a system process wants to exit */ #define USE_EXIT 1 /* a system process wants to exit */
#define USE_TRACE 1 /* process information and tracing */
#define USE_GETKSIG 1 /* retrieve pending kernel signals */ #define USE_GETKSIG 1 /* retrieve pending kernel signals */
#define USE_ENDKSIG 1 /* finish pending kernel signals */ #define USE_ENDKSIG 1 /* finish pending kernel signals */
#define USE_KILL 1 /* send a signal to a process */ #define USE_KILL 1 /* send a signal to a process */

View file

@ -3,7 +3,7 @@
# Makefile for Process Manager (PM) # Makefile for Process Manager (PM)
PROG= pm PROG= pm
SRCS= main.c forkexit.c break.c exec.c time.c alarm.c \ SRCS= main.c forkexit.c break.c exec.c time.c alarm.c \
signal.c utility.c table.c trace.c getset.c misc.c \ signal.c utility.c table.c getset.c misc.c \
profile.c dma.c schedule.c profile.c dma.c schedule.c
.if ${USE_MCONTEXT} != "no" .if ${USE_MCONTEXT} != "no"
@ -11,6 +11,11 @@ SRCS+= mcontext.c
CPPFLAGS+= -DUSE_MCONTEXT CPPFLAGS+= -DUSE_MCONTEXT
.endif .endif
.if ${USE_TRACE} != "no"
SRCS+= trace.c
CPPFLAGS+= -DUSE_TRACE
.endif
DPADD+= ${LIBSYS} ${LIBTIMERS} DPADD+= ${LIBSYS} ${LIBTIMERS}
LDADD+= -lsys -ltimers LDADD+= -lsys -ltimers

View file

@ -177,12 +177,14 @@ vir_bytes pc;
/* Cause a signal if this process is traced. /* Cause a signal if this process is traced.
* Do this before making the process runnable again! * Do this before making the process runnable again!
*/ */
#if USE_TRACE
if (rmp->mp_tracer != NO_TRACER && !(rmp->mp_trace_flags & TO_NOEXEC)) if (rmp->mp_tracer != NO_TRACER && !(rmp->mp_trace_flags & TO_NOEXEC))
{ {
sn = (rmp->mp_trace_flags & TO_ALTEXEC) ? SIGSTOP : SIGTRAP; sn = (rmp->mp_trace_flags & TO_ALTEXEC) ? SIGSTOP : SIGTRAP;
check_sig(rmp->mp_pid, sn, FALSE /* ksig */); check_sig(rmp->mp_pid, sn, FALSE /* ksig */);
} }
#endif /* USE_TRACE */
new_sp= (char *)rmp->mp_frame_addr; new_sp= (char *)rmp->mp_frame_addr;
r= sys_exec(rmp->mp_endpoint, new_sp, rmp->mp_name, pc); r= sys_exec(rmp->mp_endpoint, new_sp, rmp->mp_name, pc);

View file

@ -123,9 +123,11 @@ PUBLIC int do_fork()
tell_vfs(rmc, &m); tell_vfs(rmc, &m);
#if USE_TRACE
/* Tell the tracer, if any, about the new child */ /* Tell the tracer, if any, about the new child */
if (rmc->mp_tracer != NO_TRACER) if (rmc->mp_tracer != NO_TRACER)
sig_proc(rmc, SIGSTOP, TRUE /*trace*/, FALSE /* ksig */); sig_proc(rmc, SIGSTOP, TRUE /*trace*/, FALSE /* ksig */);
#endif /* USE_TRACE */
/* Do not reply until VFS is ready to process the fork /* Do not reply until VFS is ready to process the fork
* request * request
@ -210,9 +212,11 @@ PUBLIC int do_srv_fork()
tell_vfs(rmc, &m); tell_vfs(rmc, &m);
#if USE_TRACE
/* Tell the tracer, if any, about the new child */ /* Tell the tracer, if any, about the new child */
if (rmc->mp_tracer != NO_TRACER) if (rmc->mp_tracer != NO_TRACER)
sig_proc(rmc, SIGSTOP, TRUE /*trace*/, FALSE /* ksig */); sig_proc(rmc, SIGSTOP, TRUE /*trace*/, FALSE /* ksig */);
#endif /* USE_TRACE */
/* Wakeup the newly created process */ /* Wakeup the newly created process */
setreply(rmc-mproc, OK); setreply(rmc-mproc, OK);
@ -345,10 +349,12 @@ int dump_core; /* flag indicating whether to dump core */
/* If the process has children, disinherit them. INIT is the new parent. */ /* If the process has children, disinherit them. INIT is the new parent. */
for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) { for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) {
if (!(rmp->mp_flags & IN_USE)) continue; if (!(rmp->mp_flags & IN_USE)) continue;
#if USE_TRACE
if (rmp->mp_tracer == proc_nr) { if (rmp->mp_tracer == proc_nr) {
/* This child's tracer died. Do something sensible. */ /* This child's tracer died. Do something sensible. */
tracer_died(rmp); tracer_died(rmp);
} }
#endif /* USE_TRACE */
if (rmp->mp_parent == proc_nr) { if (rmp->mp_parent == proc_nr) {
/* 'rmp' now points to a child to be disinherited. */ /* 'rmp' now points to a child to be disinherited. */
rmp->mp_parent = INIT_PROC_NR; rmp->mp_parent = INIT_PROC_NR;
@ -409,12 +415,14 @@ int dump_core; /* flag indicating whether to dump core */
panic("exit_restart: vm_exit failed: %d", r); panic("exit_restart: vm_exit failed: %d", r);
} }
#if USE_TRACE
if (rmp->mp_flags & TRACE_EXIT) if (rmp->mp_flags & TRACE_EXIT)
{ {
/* Wake up the tracer, completing the ptrace(T_EXIT) call */ /* Wake up the tracer, completing the ptrace(T_EXIT) call */
mproc[rmp->mp_tracer].mp_reply.reply_trace = 0; mproc[rmp->mp_tracer].mp_reply.reply_trace = 0;
setreply(rmp->mp_tracer, OK); setreply(rmp->mp_tracer, OK);
} }
#endif /* USE_TRACE */
/* Clean up if the parent has collected the exit status */ /* Clean up if the parent has collected the exit status */
if (rmp->mp_flags & TOLD_PARENT) if (rmp->mp_flags & TOLD_PARENT)
@ -460,6 +468,7 @@ PUBLIC int do_waitpid()
children++; /* this child is acceptable */ children++; /* this child is acceptable */
#if USE_TRACE
if (rp->mp_tracer == who_p) { if (rp->mp_tracer == who_p) {
if (rp->mp_flags & TRACE_ZOMBIE) { if (rp->mp_flags & TRACE_ZOMBIE) {
/* Traced child meets the pid test and has exited. */ /* Traced child meets the pid test and has exited. */
@ -482,6 +491,7 @@ PUBLIC int do_waitpid()
} }
} }
} }
#endif /* USE_TRACE */
if (rp->mp_parent == who_p) { if (rp->mp_parent == who_p) {
if (rp->mp_flags & ZOMBIE) { if (rp->mp_flags & ZOMBIE) {
@ -549,6 +559,7 @@ struct mproc *rmp;
/* See if we have to notify a tracer process first. */ /* See if we have to notify a tracer process first. */
if (rmp->mp_tracer != NO_TRACER && rmp->mp_tracer != rmp->mp_parent) { if (rmp->mp_tracer != NO_TRACER && rmp->mp_tracer != rmp->mp_parent) {
#if USE_TRACE
rmp->mp_flags |= TRACE_ZOMBIE; rmp->mp_flags |= TRACE_ZOMBIE;
t_mp = &mproc[rmp->mp_tracer]; t_mp = &mproc[rmp->mp_tracer];
@ -558,6 +569,7 @@ struct mproc *rmp;
return; return;
tell_tracer(rmp); tell_tracer(rmp);
#endif /* USE_TRACE */
} }
else { else {
rmp->mp_flags |= ZOMBIE; rmp->mp_flags |= ZOMBIE;
@ -632,6 +644,7 @@ register struct mproc *child; /* tells which process is exiting */
child->mp_flags |= TOLD_PARENT; /* avoid informing parent twice */ child->mp_flags |= TOLD_PARENT; /* avoid informing parent twice */
} }
#if USE_TRACE
/*===========================================================================* /*===========================================================================*
* tell_tracer * * tell_tracer *
*===========================================================================*/ *===========================================================================*/
@ -689,6 +702,7 @@ struct mproc *child; /* process being traced */
check_parent(child, TRUE /*try_cleanup*/); check_parent(child, TRUE /*try_cleanup*/);
} }
} }
#endif /* USE_TRACE */
/*===========================================================================* /*===========================================================================*
* cleanup * * cleanup *

View file

@ -100,6 +100,10 @@ _PROTOTYPE( int do_times, (void) );
/* trace.c */ /* trace.c */
_PROTOTYPE( int do_trace, (void) ); _PROTOTYPE( int do_trace, (void) );
_PROTOTYPE( void stop_proc, (struct mproc *rmp, int sig_nr) ); _PROTOTYPE( void stop_proc, (struct mproc *rmp, int sig_nr) );
#if ! USE_TRACE
#define do_trace no_sys
#define stop_proc no_sys
#endif
/* utility.c */ /* utility.c */
_PROTOTYPE( pid_t get_free_pid, (void) ); _PROTOTYPE( pid_t get_free_pid, (void) );

View file

@ -332,6 +332,7 @@ int ksig; /* non-zero means signal comes from kernel */
panic(""); panic("");
} }
#if USE_TRACE
if (trace == TRUE && rmp->mp_tracer != NO_TRACER && signo != SIGKILL) { if (trace == TRUE && rmp->mp_tracer != NO_TRACER && signo != SIGKILL) {
/* Signal should be passed to the debugger first. /* Signal should be passed to the debugger first.
* This happens before any checks on block/ignore masks; otherwise, * This happens before any checks on block/ignore masks; otherwise,
@ -345,6 +346,7 @@ int ksig; /* non-zero means signal comes from kernel */
return; return;
} }
#endif
if (rmp->mp_flags & VFS_CALL) { if (rmp->mp_flags & VFS_CALL) {
(void) sigaddset(&rmp->mp_sigpending, signo); (void) sigaddset(&rmp->mp_sigpending, signo);
@ -414,6 +416,7 @@ int ksig; /* non-zero means signal comes from kernel */
return; return;
} }
#if USE_TRACE
if ((rmp->mp_flags & STOPPED) && signo != SIGKILL) { if ((rmp->mp_flags & STOPPED) && signo != SIGKILL) {
/* If the process is stopped for a debugger, do not deliver any signals /* If the process is stopped for a debugger, do not deliver any signals
* (except SIGKILL) in order not to confuse the debugger. The signals * (except SIGKILL) in order not to confuse the debugger. The signals
@ -424,6 +427,7 @@ int ksig; /* non-zero means signal comes from kernel */
(void) sigaddset(&rmp->mp_ksigpending, signo); (void) sigaddset(&rmp->mp_ksigpending, signo);
return; return;
} }
#endif /* USE_TRACE */
if (!badignore && sigismember(&rmp->mp_catch, signo)) { if (!badignore && sigismember(&rmp->mp_catch, signo)) {
/* Signal is caught. First interrupt the process's current call, if /* Signal is caught. First interrupt the process's current call, if
* applicable. This may involve a roundtrip to VFS, in which case we'll * applicable. This may involve a roundtrip to VFS, in which case we'll
@ -604,8 +608,10 @@ struct mproc *rmp;
if (rmp->mp_flags & (VFS_CALL | EXITING)) return; if (rmp->mp_flags & (VFS_CALL | EXITING)) return;
if (rmp->mp_flags & TRACE_EXIT) { if (rmp->mp_flags & TRACE_EXIT) {
#if USE_TRACE
/* Tracer requested exit with specific exit value */ /* Tracer requested exit with specific exit value */
exit_proc(rmp, rmp->mp_exitstatus, FALSE /*dump_core*/); exit_proc(rmp, rmp->mp_exitstatus, FALSE /*dump_core*/);
#endif /* USE_TRACE */
} }
else if (rmp->mp_flags & PM_SIG_PENDING) { else if (rmp->mp_flags & PM_SIG_PENDING) {
/* We saved signal(s) for after finishing a VFS call. Deal with this. /* We saved signal(s) for after finishing a VFS call. Deal with this.

View file

@ -760,7 +760,7 @@ _MKVARS.yes= \
#MINIX-specific vars #MINIX-specific vars
_MKVARS.yes+= \ _MKVARS.yes+= \
MKWATCHDOG MKACPI MKAPIC MKMCONTEXT MKDEBUGREG MKSYSDEBUG \ MKWATCHDOG MKACPI MKAPIC MKMCONTEXT MKDEBUGREG MKSYSDEBUG \
MKLIVEUPDATE MKSTATECTL MKLIVEUPDATE MKSTATECTL MKTRACE
.for var in ${_MKVARS.yes} .for var in ${_MKVARS.yes}
${var}?= yes ${var}?= yes
.endfor .endfor
@ -829,6 +829,7 @@ MKDEBUGREG:= no
MKSYSDEBUG:= no MKSYSDEBUG:= no
MKLIVEUPDATE:= no MKLIVEUPDATE:= no
MKSTATECTL:= no MKSTATECTL:= no
MKTRACE:= no
.endif .endif
# #
@ -891,7 +892,7 @@ ${var}?= no
# #
.for var in USE_HESIOD USE_INET6 USE_KERBEROS USE_LDAP USE_PAM USE_YP \ .for var in USE_HESIOD USE_INET6 USE_KERBEROS USE_LDAP USE_PAM USE_YP \
USE_WATCHDOG USE_ACPI USE_APIC USE_MCONTEXT USE_DEBUGREG USE_SYSDEBUG \ USE_WATCHDOG USE_ACPI USE_APIC USE_MCONTEXT USE_DEBUGREG USE_SYSDEBUG \
USE_LIVEUPDATE USE_STATECTL USE_LIVEUPDATE USE_STATECTL USE_TRACE
.if (${${var:S/USE_/MK/}} == "no") .if (${${var:S/USE_/MK/}} == "no")
${var}:= no ${var}:= no
.else .else