better debugging support (-d option)
diff --git a/sysdeps/linux-gnu/breakpoint.c b/sysdeps/linux-gnu/breakpoint.c
index 5a56bd3..64b70e4 100644
--- a/sysdeps/linux-gnu/breakpoint.c
+++ b/sysdeps/linux-gnu/breakpoint.c
@@ -15,6 +15,11 @@
 extern void arch_enable_breakpoint(pid_t, Breakpoint *);
 void
 enable_breakpoint(pid_t pid, Breakpoint *sbp) {
+	if (sbp->libsym) {
+		debug(DEBUG_PROCESS, "enable_breakpoint: pid=%d, addr=%p, symbol=%s", pid, sbp->addr, sbp->libsym->name);
+	} else {
+		debug(DEBUG_PROCESS, "enable_breakpoint: pid=%d, addr=%p", pid, sbp->addr);
+	}
 	arch_enable_breakpoint(pid, sbp);
 }
 #else
@@ -22,7 +27,11 @@
 enable_breakpoint(pid_t pid, Breakpoint *sbp) {
 	unsigned int i, j;
 
-	debug(1, "enable_breakpoint(%d,%p)", pid, sbp->addr);
+	if (sbp->libsym) {
+		debug(DEBUG_PROCESS, "enable_breakpoint: pid=%d, addr=%p, symbol=%s", pid, sbp->addr, sbp->libsym->name);
+	} else {
+		debug(DEBUG_PROCESS, "enable_breakpoint: pid=%d, addr=%p", pid, sbp->addr);
+	}
 
 	for (i = 0; i < 1 + ((BREAKPOINT_LENGTH - 1) / sizeof(long)); i++) {
 		long a =
@@ -45,6 +54,11 @@
 extern void arch_disable_breakpoint(pid_t, const Breakpoint *sbp);
 void
 disable_breakpoint(pid_t pid, const Breakpoint *sbp) {
+	if (sbp->libsym) {
+		debug(DEBUG_PROCESS, "disable_breakpoint: pid=%d, addr=%p, symbol=%s", pid, sbp->addr, sbp->libsym->name);
+	} else {
+		debug(DEBUG_PROCESS, "disable_breakpoint: pid=%d, addr=%p", pid, sbp->addr);
+	}
 	arch_disable_breakpoint(pid, sbp);
 }
 #else
@@ -52,7 +66,11 @@
 disable_breakpoint(pid_t pid, const Breakpoint *sbp) {
 	unsigned int i, j;
 
-	debug(2, "disable_breakpoint(%d,%p)", pid, sbp->addr);
+	if (sbp->libsym) {
+		debug(DEBUG_PROCESS, "disable_breakpoint: pid=%d, addr=%p, symbol=%s", pid, sbp->addr, sbp->libsym->name);
+	} else {
+		debug(DEBUG_PROCESS, "disable_breakpoint: pid=%d, addr=%p", pid, sbp->addr);
+	}
 
 	for (i = 0; i < 1 + ((BREAKPOINT_LENGTH - 1) / sizeof(long)); i++) {
 		long a =
diff --git a/sysdeps/linux-gnu/events.c b/sysdeps/linux-gnu/events.c
index dfb8284..6dedcc9 100644
--- a/sysdeps/linux-gnu/events.c
+++ b/sysdeps/linux-gnu/events.c
@@ -25,17 +25,18 @@
 	int tmp;
 	int stop_signal;
 
+	debug(DEBUG_FUNCTION, "next_event()");
 	if (!list_of_processes) {
-		debug(1, "No more children");
+		debug(DEBUG_EVENT, "event: No more traced programs: exiting");
 		exit(0);
 	}
 	pid = wait(&status);
 	if (pid == -1) {
 		if (errno == ECHILD) {
-			debug(1, "No more children");
+			debug(DEBUG_EVENT, "event: No more traced programs: exiting");
 			exit(0);
 		} else if (errno == EINTR) {
-			debug(1, "wait received EINTR ?");
+			debug(DEBUG_EVENT, "event: none (wait received EINTR?)");
 			event.type = EVENT_NONE;
 			return &event;
 		}
@@ -45,6 +46,7 @@
 	event.proc = pid2proc(pid);
 	if (!event.proc) {
 		event.type = EVENT_NEW;
+		debug(DEBUG_EVENT, "event: NEW: pid=%d", pid);
 		return &event;
 	}
 	get_arch_dep(event.proc);
@@ -55,6 +57,7 @@
 		event.type = EVENT_NONE;
 		trace_set_options(event.proc, event.proc->pid);
 		continue_process(event.proc->pid);
+		debug(DEBUG_EVENT, "event: NONE: pid=%d (enabling breakpoints)", pid);
 		return &event;
 	}
 	if (opt_i) {
@@ -65,22 +68,27 @@
 		case 1:
 			event.type = EVENT_SYSCALL;
 			event.e_un.sysnum = tmp;
+			debug(DEBUG_EVENT, "event: SYSCALL: pid=%d, sysnum=%d", pid, tmp);
 			return &event;
 		case 2:
 			event.type = EVENT_SYSRET;
 			event.e_un.sysnum = tmp;
+			debug(DEBUG_EVENT, "event: SYSRET: pid=%d, sysnum=%d", pid, tmp);
 			return &event;
 		case 3:
 			event.type = EVENT_ARCH_SYSCALL;
 			event.e_un.sysnum = tmp;
+			debug(DEBUG_EVENT, "event: ARCH_SYSCALL: pid=%d, sysnum=%d", pid, tmp);
 			return &event;
 		case 4:
 			event.type = EVENT_ARCH_SYSRET;
 			event.e_un.sysnum = tmp;
+			debug(DEBUG_EVENT, "event: ARCH_SYSRET: pid=%d, sysnum=%d", pid, tmp);
 			return &event;
 		case -1:
 			event.type = EVENT_NONE;
 			continue_process(event.proc->pid);
+			debug(DEBUG_EVENT, "event: NONE: pid=%d (syscall_p returned -1)", pid);
 			return &event;
 	}
 	if (WIFSTOPPED(status) && ((status>>16 == PTRACE_EVENT_FORK) || (status>>16 == PTRACE_EVENT_VFORK) || (status>>16 == PTRACE_EVENT_CLONE))) {
@@ -88,24 +96,29 @@
 		ptrace(PTRACE_GETEVENTMSG, pid, NULL, &data);
 		event.type = EVENT_CLONE;
 		event.e_un.newpid = data;
+		debug(DEBUG_EVENT, "event: CLONE: pid=%d, newpid=%d", pid, (int)data);
 		return &event;
 	}
 	if (WIFSTOPPED(status) && (status>>16 == PTRACE_EVENT_EXEC)) {
 		event.type = EVENT_EXEC;
+		debug(DEBUG_EVENT, "event: EXEC: pid=%d", pid);
 		return &event;
 	}
 	if (WIFEXITED(status)) {
 		event.type = EVENT_EXIT;
 		event.e_un.ret_val = WEXITSTATUS(status);
+		debug(DEBUG_EVENT, "event: EXIT: pid=%d, status=%d", pid, event.e_un.ret_val);
 		return &event;
 	}
 	if (WIFSIGNALED(status)) {
 		event.type = EVENT_EXIT_SIGNAL;
 		event.e_un.signum = WTERMSIG(status);
+		debug(DEBUG_EVENT, "event: EXIT_SIGNAL: pid=%d, signum=%d", pid, event.e_un.signum);
 		return &event;
 	}
 	if (!WIFSTOPPED(status)) {
 		event.type = EVENT_NONE;
+		debug(DEBUG_EVENT, "event: NONE: pid=%d (wait error?)", pid);
 		return &event;
 	}
 
@@ -133,6 +146,7 @@
 	    && stop_signal != SIGTRAP) {
 		event.type = EVENT_SIGNAL;
 		event.e_un.signum = stop_signal;
+		debug(DEBUG_EVENT, "event: SIGNAL: pid=%d, signum=%d", pid, stop_signal);
 		return &event;
 	}
 
@@ -151,6 +165,7 @@
 		breakpoints_init(event.proc);
 		event.proc->pid = saved_pid;
 		continue_process(event.proc->pid);
+		debug(DEBUG_EVENT, "event: NONE: pid=%d (was_exec; placed breakpoints)", pid);
 		return &event;
 	}
 
@@ -161,5 +176,6 @@
 	}
 	event.e_un.brk_addr =
 	    event.proc->instruction_pointer - DECR_PC_AFTER_BREAK;
+	debug(DEBUG_EVENT, "event: BREAKPOINT: pid=%d, addr=%p", pid, event.e_un.brk_addr);
 	return &event;
 }
diff --git a/sysdeps/linux-gnu/trace.c b/sysdeps/linux-gnu/trace.c
index cbda70b..65d561f 100644
--- a/sysdeps/linux-gnu/trace.c
+++ b/sysdeps/linux-gnu/trace.c
@@ -161,6 +161,7 @@
 
 void
 trace_me(void) {
+	debug(DEBUG_PROCESS, "trace_me: pid=%d\n", getpid());
 	if (ptrace(PTRACE_TRACEME, 0, 1, 0) < 0) {
 		perror("PTRACE_TRACEME");
 		exit(1);
@@ -169,6 +170,7 @@
 
 int
 trace_pid(pid_t pid) {
+	debug(DEBUG_PROCESS, "trace_pid: pid=%d\n", pid);
 	if (ptrace(PTRACE_ATTACH, pid, 1, 0) < 0) {
 		return -1;
 	}
@@ -190,6 +192,8 @@
 	if (proc->tracesysgood & 0x80)
 		return;
 
+	debug(DEBUG_PROCESS, "trace_set_options: pid=%d\n", pid);
+
 	long options = PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEFORK |
 		PTRACE_O_TRACEVFORK | PTRACE_O_TRACECLONE |
 		PTRACE_O_TRACEEXEC;
@@ -203,6 +207,7 @@
 
 void
 untrace_pid(pid_t pid) {
+	debug(DEBUG_PROCESS, "untrace_pid: pid=%d\n", pid);
 	ptrace(PTRACE_DETACH, pid, 1, 0);
 }
 
@@ -210,6 +215,8 @@
 continue_after_signal(pid_t pid, int signum) {
 	Process *proc;
 
+	debug(DEBUG_PROCESS, "continue_after_signal: pid=%d, signum=%d", pid, signum);
+
 	proc = pid2proc(pid);
 	if (proc && proc->breakpoint_being_enabled) {
 #if defined __sparc__  || defined __ia64___
@@ -226,6 +233,8 @@
 continue_process(pid_t pid) {
 	/* We always trace syscalls to control fork(), clone(), execve()... */
 
+	debug(DEBUG_PROCESS, "continue_process: pid=%d", pid);
+
 	ptrace(PTRACE_SYSCALL, pid, 0, 0);
 }
 
@@ -237,6 +246,7 @@
 
 void
 continue_after_breakpoint(Process *proc, Breakpoint *sbp) {
+	debug(DEBUG_PROCESS, "continue_after_breakpoint: pid=%d, addr=%p", proc->pid, sbp->addr);
 	if (sbp->enabled)
 		disable_breakpoint(proc->pid, sbp);
 	set_instruction_pointer(proc, sbp->addr);