diff options
-rw-r--r-- | common.h | 3 | ||||
-rw-r--r-- | sctrace.c | 25 |
2 files changed, 24 insertions, 4 deletions
@@ -70,7 +70,8 @@ enum state { ForkChild, VforkChild, ForkParent, - VforkParent + VforkParent, + Exec }; struct process { @@ -68,6 +68,14 @@ handle_syscall(struct process *proc) proc->state = Normal; break; + case Exec: + if (ptrace(PTRACE_SYSCALL, proc->pid, NULL, 0)) + eprintf("ptrace PTRACE_SYSCALL %ju NULL 0", (uintmax_t)proc->pid); + if (ptrace(PTRACE_SYSCALL, proc->pid, NULL, 0)) + eprintf("ptrace PTRACE_SYSCALL %ju NULL 0", (uintmax_t)proc->pid); + proc->state = Normal; + break; + case VforkParent: if (ptrace(PTRACE_SYSCALL, proc->pid, NULL, 0)) eprintf("ptrace PTRACE_SYSCALL %ju NULL 0", (uintmax_t)proc->pid); @@ -92,11 +100,10 @@ main(int argc, char **argv) FILE *outfp = stderr; const char *num = NULL; int status, exit_value = 0, trace_event, with_argv0 = 0; - unsigned long int trace_options = PTRACE_O_EXITKILL | PTRACE_O_TRACESYSGOOD; + unsigned long int trace_options = PTRACE_O_EXITKILL | PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXEC; struct process *proc, *proc2; unsigned long int event; - /* TODO add support for exec after vfork */ /* TODO add option to trace threads (-t) */ /* TODO add option to trace signals (-s) */ ARGBEGIN { @@ -198,7 +205,7 @@ have_outfp: proc2 = proc->continue_on_exit; remove_process(proc); if (proc2) { - tprintf(proc2, "Process continue do to exit of vfork child\n"); + tprintf(proc2, "Process continues due to exit of vfork child\n"); handle_syscall(proc2); } @@ -234,6 +241,18 @@ have_outfp: handle_syscall(proc2); break; + case PTRACE_EVENT_EXEC: + proc->state = Exec; + handle_syscall(proc); + proc2 = proc->continue_on_exit; + if (proc2) { + proc->continue_on_exit = NULL; + proc2->vfork_waiting_on = NULL; + tprintf(proc2, "Process continues due to exec(2) of vfork child\n"); + handle_syscall(proc2); + } + break; + default: goto print_signal; } |