New event: EVENT_NEW (received from a new process)
diff --git a/ltrace.h b/ltrace.h
index 3a059f7..a5cad0d 100644
--- a/ltrace.h
+++ b/ltrace.h
@@ -11,7 +11,7 @@
/* BREAKPOINT_LENGTH is defined in "sysdep.h" */
#include "sysdep.h"
-#define MAX_LIBRARY 30
+#define MAX_LIBRARY 30
#if defined HAVE_LIBIBERTY || defined HAVE_LIBSUPC__
# define USE_DEMANGLE
@@ -207,17 +207,17 @@
EVENT_SYSRET,
EVENT_ARCH_SYSCALL,
EVENT_ARCH_SYSRET,
- EVENT_FORK,
- EVENT_CLONE, /* Like FORK, but parent and child share memory */
+ EVENT_CLONE,
EVENT_EXEC,
- EVENT_BREAKPOINT
- } thing;
+ EVENT_BREAKPOINT,
+ EVENT_NEW /* in this case, proc is NULL */
+ } type;
union {
- int ret_val; /* EVENT_EXIT */
+ int ret_val; /* EVENT_EXIT */
int signum; /* EVENT_SIGNAL, EVENT_EXIT_SIGNAL */
int sysnum; /* EVENT_SYSCALL, EVENT_SYSRET */
- void *brk_addr; /* EVENT_BREAKPOINT */
- int newpid; /* EVENT_FORK, EVENT_CLONE */
+ void *brk_addr; /* EVENT_BREAKPOINT */
+ int newpid; /* EVENT_CLONE, EVENT_NEW */
} e_un;
};
diff --git a/process_event.c b/process_event.c
index 18f2a0e..5346be0 100644
--- a/process_event.c
+++ b/process_event.c
@@ -27,10 +27,10 @@
static void process_arch_syscall(Event *event);
static void process_sysret(Event *event);
static void process_arch_sysret(Event *event);
-static void process_fork(Event *event);
static void process_clone(Event *event);
static void process_exec(Event *event);
static void process_breakpoint(Event *event);
+static void process_new(Event *event);
static void remove_proc(Process *proc);
static void callstack_push_syscall(Process *proc, int sysnum);
@@ -106,7 +106,7 @@
void
process_event(Event *event) {
- switch (event->thing) {
+ switch (event->type) {
case EVENT_NONE:
debug(1, "event: none");
return;
@@ -150,10 +150,6 @@
event->e_un.sysnum);
process_arch_sysret(event);
return;
- case EVENT_FORK:
- debug(1, "event: fork (%u)", event->e_un.newpid);
- process_fork(event);
- return;
case EVENT_CLONE:
debug(1, "event: clone (%u)", event->e_un.newpid);
process_clone(event);
@@ -166,6 +162,10 @@
debug(1, "event: breakpoint");
process_breakpoint(event);
return;
+ case EVENT_NEW:
+ debug(1, "event: new process");
+ process_new(event);
+ return;
default:
fprintf(stderr, "Error! unknown event?\n");
exit(1);
@@ -241,17 +241,16 @@
}
static void
-process_fork(Event * event) {
- output_line(event->proc, "--- fork() = %u ---",
+process_clone(Event * event) {
+ output_line(event->proc, "--- clone() = %u ---",
event->e_un.newpid);
continue_process(event->proc->pid);
}
static void
-process_clone(Event * event) {
- output_line(event->proc, "--- clone() = %u ---",
+process_new(Event * event) {
+ output_line(NULL, "--- new child = %u ---",
event->e_un.newpid);
- abort();
}
static void
diff --git a/sysdeps/linux-gnu/events.c b/sysdeps/linux-gnu/events.c
index 85276d7..dfb8284 100644
--- a/sysdeps/linux-gnu/events.c
+++ b/sysdeps/linux-gnu/events.c
@@ -36,7 +36,7 @@
exit(0);
} else if (errno == EINTR) {
debug(1, "wait received EINTR ?");
- event.thing = EVENT_NONE;
+ event.type = EVENT_NONE;
return &event;
}
perror("wait");
@@ -44,9 +44,7 @@
}
event.proc = pid2proc(pid);
if (!event.proc) {
- output_line(NULL, "event from wrong pid %u ?!?\n", pid);
-// exit(1);
- event.thing = EVENT_NONE;
+ event.type = EVENT_NEW;
return &event;
}
get_arch_dep(event.proc);
@@ -54,7 +52,7 @@
debug(3, "event from pid %u", pid);
if (event.proc->breakpoints_enabled == -1) {
enable_all_breakpoints(event.proc);
- event.thing = EVENT_NONE;
+ event.type = EVENT_NONE;
trace_set_options(event.proc, event.proc->pid);
continue_process(event.proc->pid);
return &event;
@@ -65,50 +63,49 @@
}
switch (syscall_p(event.proc, status, &tmp)) {
case 1:
- event.thing = EVENT_SYSCALL;
+ event.type = EVENT_SYSCALL;
event.e_un.sysnum = tmp;
return &event;
case 2:
- event.thing = EVENT_SYSRET;
+ event.type = EVENT_SYSRET;
event.e_un.sysnum = tmp;
return &event;
case 3:
- event.thing = EVENT_ARCH_SYSCALL;
+ event.type = EVENT_ARCH_SYSCALL;
event.e_un.sysnum = tmp;
return &event;
case 4:
- event.thing = EVENT_ARCH_SYSRET;
+ event.type = EVENT_ARCH_SYSRET;
event.e_un.sysnum = tmp;
return &event;
case -1:
- event.thing = EVENT_NONE;
+ event.type = EVENT_NONE;
continue_process(event.proc->pid);
return &event;
}
if (WIFSTOPPED(status) && ((status>>16 == PTRACE_EVENT_FORK) || (status>>16 == PTRACE_EVENT_VFORK) || (status>>16 == PTRACE_EVENT_CLONE))) {
unsigned long data;
ptrace(PTRACE_GETEVENTMSG, pid, NULL, &data);
- event.thing = EVENT_FORK;
+ event.type = EVENT_CLONE;
event.e_un.newpid = data;
return &event;
}
- /* TODO: check for EVENT_CLONE */
if (WIFSTOPPED(status) && (status>>16 == PTRACE_EVENT_EXEC)) {
- event.thing = EVENT_EXEC;
+ event.type = EVENT_EXEC;
return &event;
}
if (WIFEXITED(status)) {
- event.thing = EVENT_EXIT;
+ event.type = EVENT_EXIT;
event.e_un.ret_val = WEXITSTATUS(status);
return &event;
}
if (WIFSIGNALED(status)) {
- event.thing = EVENT_EXIT_SIGNAL;
+ event.type = EVENT_EXIT_SIGNAL;
event.e_un.signum = WTERMSIG(status);
return &event;
}
if (!WIFSTOPPED(status)) {
- event.thing = EVENT_NONE;
+ event.type = EVENT_NONE;
return &event;
}
@@ -134,7 +131,7 @@
if (stop_signal != (SIGTRAP | event.proc->tracesysgood)
&& stop_signal != SIGTRAP) {
- event.thing = EVENT_SIGNAL;
+ event.type = EVENT_SIGNAL;
event.e_un.signum = stop_signal;
return &event;
}
@@ -142,7 +139,7 @@
if (was_exec(event.proc, status)) {
pid_t saved_pid;
- event.thing = EVENT_NONE;
+ event.type = EVENT_NONE;
event.e_un.signum = WSTOPSIG(status);
debug(1, "Placing breakpoints for the new program");
event.proc->mask_32bit = 0;
@@ -157,7 +154,7 @@
return &event;
}
- event.thing = EVENT_BREAKPOINT;
+ event.type = EVENT_BREAKPOINT;
if (!event.proc->instruction_pointer) {
event.proc->instruction_pointer =
get_instruction_pointer(event.proc);