Fix compilation
diff --git a/backend.h b/backend.h
index 68a9694..08306e1 100644
--- a/backend.h
+++ b/backend.h
@@ -22,6 +22,18 @@
 #define BACKEND_H
 
 #include "forward.h"
+#include <gelf.h>
+
+enum process_status {
+	ps_invalid,	/* Failure.  */
+	ps_stop,	/* Job-control stop.  */
+	ps_tracing_stop,
+	ps_sleeping,
+	ps_zombie,
+	ps_other,	/* Necessary other states can be added as needed.  */
+};
+
+typedef void *target_address_t;
 
 /*
  * This file contains documentation of back end interface.  Some of
@@ -52,13 +64,13 @@
 enum process_status process_status(pid_t pid);
 
 /* Wait for PID to be ready for tracing.  */
-void wait_for_proc(pid_t pid);
+int wait_for_proc(pid_t pid);
 
 /* Send a signal SIG to the task PID.  */
 int task_kill(pid_t pid, int sig);
 
 /* Called after PID is attached, but before it is continued.  */
-void trace_set_options(struct Process *proc, pid_t pid);
+void trace_set_options(struct Process *proc);
 
 /* Called after ltrace forks.  Should attach the newly created child,
  * in whose context this function is called.  */
@@ -80,7 +92,7 @@
  *
  * XXX note that the IP must fit into an arch pointer.  This prevents
  * us to use 32-bit ltrace to trace 64-bit process, even on arches
- * that would otherwise support this.  Below we have a definition of
+ * that would otherwise support this.  Above we have a definition of
  * target_address_t.  This should be converted to an integral type and
  * used for target addresses throughout.  */
 void *get_instruction_pointer(struct Process *proc);
@@ -169,10 +181,9 @@
 void *sym2addr(struct Process *proc, struct library_symbol *sym);
 
 /* Called at some point after we have attached to PROC.  This callback
- * should insert an introspection breakpoint for artificial symbol
- * named "" (empty string).  When this breakpoint is hit,
- * arch_check_dbg is called.  */
-int linkmap_init(struct Process *proc, struct ltelf *elf);
+ * should insert an introspection breakpoint for handling dynamic
+ * linker library loads.  */
+int linkmap_init(struct Process *proc, target_address_t dyn_addr);
 
 /* Called for breakpoints defined over an artificial symbol "".  This
  * can be used (like it is on Linux/GNU) to add more breakpoints
@@ -224,8 +235,6 @@
 int arch_process_clone(struct Process *retp, struct Process *proc);
 int arch_process_exec(struct Process *proc);
 
-typedef void *target_address_t;
-
 /* This should extract entry point address and interpreter (dynamic
  * linker) bias if possible.  Returns 0 if there were no errors, -1
  * otherwise.  Sets *ENTRYP and *INTERP_BIASP to non-zero values if
diff --git a/breakpoints.c b/breakpoints.c
index 2db8b0a..8dc09df 100644
--- a/breakpoints.c
+++ b/breakpoints.c
@@ -1,18 +1,21 @@
 #include "config.h"
 
-#include <stdlib.h>
-#include <string.h>
 #include <assert.h>
 #include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 #ifdef __powerpc__
 #include <sys/ptrace.h>
 #endif
 
-#include "breakpoint.h"
-#include "proc.h"
-#include "library.h"
 #include "backend.h"
+#include "breakpoint.h"
+#include "debug.h"
+#include "library.h"
+#include "ltrace-elf.h"
+#include "proc.h"
 
 #ifndef ARCH_HAVE_TRANSLATE_ADDRESS
 int
diff --git a/common.h b/common.h
index 1d45c05..f333f3f 100644
--- a/common.h
+++ b/common.h
@@ -76,15 +76,6 @@
 
 extern Dict * dict_opt_c;
 
-enum process_status {
-	ps_invalid,	/* Failure.  */
-	ps_stop,	/* Job-control stop.  */
-	ps_tracing_stop,
-	ps_sleeping,
-	ps_zombie,
-	ps_other,	/* Necessary other states can be added as needed.  */
-};
-
 /* Events  */
 extern Event * next_event(void);
 extern void handle_event(Event * event);
diff --git a/forward.h b/forward.h
index 286b239..e4233e5 100644
--- a/forward.h
+++ b/forward.h
@@ -1,14 +1,14 @@
 /* Important types defined in other header files are declared
    here.  */
-struct breakpoint;
 struct Event;
 struct Process;
 struct arg_type_info;
+struct breakpoint;
 struct expr_node;
+struct library;
 struct library_symbol;
 struct ltelf;
 struct param;
 struct param_enum;
 struct value;
 struct value_dict;
-struct library_symbol;
diff --git a/handle_event.c b/handle_event.c
index a06525f..c82d09e 100644
--- a/handle_event.c
+++ b/handle_event.c
@@ -36,9 +36,10 @@
 
 #include "backend.h"
 #include "breakpoint.h"
+#include "common.h"
+#include "fetch.h"
 #include "library.h"
 #include "proc.h"
-#include "fetch.h"
 #include "value_dict.h"
 
 static void handle_signal(Event *event);
diff --git a/ltrace-elf.c b/ltrace-elf.c
index 7c62185..9b6cf6b 100644
--- a/ltrace-elf.c
+++ b/ltrace-elf.c
@@ -42,10 +42,13 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "proc.h"
-#include "library.h"
-#include "filter.h"
 #include "backend.h"
+#include "filter.h"
+#include "library.h"
+#include "ltrace-elf.h"
+#include "proc.h"
+#include "debug.h"
+#include "options.h"
 
 #ifdef PLT_REINITALISATION_BP
 extern char *PLTs_initialized_by_here;
diff --git a/output.c b/output.c
index 3151701..8bfe3f0 100644
--- a/output.c
+++ b/output.c
@@ -50,7 +50,7 @@
 Dict *dict_opt_c = NULL;
 
 static Process *current_proc = 0;
-static int current_depth = 0;
+static size_t current_depth = 0;
 static int current_column = 0;
 
 static void
diff --git a/proc.c b/proc.c
index d6937f0..b280df8 100644
--- a/proc.c
+++ b/proc.c
@@ -22,21 +22,24 @@
 
 #include "config.h"
 
+#include <sys/types.h>
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
 #if defined(HAVE_LIBUNWIND)
 #include <libunwind.h>
 #include <libunwind-ptrace.h>
 #endif /* defined(HAVE_LIBUNWIND) */
 
-#include <sys/types.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <assert.h>
-
-#include "breakpoint.h"
-#include "proc.h"
 #include "backend.h"
+#include "breakpoint.h"
+#include "debug.h"
+#include "fetch.h"
+#include "proc.h"
+#include "value_dict.h"
 
 #ifndef ARCH_HAVE_PROCESS_DATA
 int
@@ -259,7 +262,7 @@
 process_clone(struct Process *retp, struct Process *proc, pid_t pid)
 {
 	if (process_bare_init(retp, proc->filename, pid, 0) < 0) {
-	fail:
+	fail1:
 		fprintf(stderr, "failed to clone process %d->%d : %s\n",
 			proc->pid, pid, strerror(errno));
 		return -1;
@@ -290,7 +293,7 @@
 				free(lib);
 				lib = next;
 			}
-			goto fail;
+			goto fail1;
 		}
 
 		nlibp = &(*nlibp)->next;
@@ -315,10 +318,10 @@
 	for (i = 0; i < retp->callstack_depth; ++i) {
 		struct fetch_context *ctx = retp->callstack[i].fetch_context;
 		if (ctx != NULL) {
-			struct fetch_context *nctx = fetch_arg_clone(p, ctx);
+			struct fetch_context *nctx = fetch_arg_clone(retp, ctx);
 			if (nctx == NULL) {
-				int j;
-			release1:
+				size_t j;
+			fail3:
 				for (j = 0; j < i; ++j) {
 					nctx = retp->callstack[i].fetch_context;
 					fetch_arg_done(nctx);
@@ -331,31 +334,30 @@
 
 		struct value_dict *args = retp->callstack[i].arguments;
 		if (args != NULL) {
-		fail3:
 			struct value_dict *nargs = malloc(sizeof(*nargs));
 			if (nargs == NULL
 			    || val_dict_clone(nargs, args) < 0) {
-
-				int j;
+				size_t j;
+			fail4:
 				for (j = 0; j < i; ++j) {
-					nargs = p->callstack[i].arguments;
+					nargs = retp->callstack[i].arguments;
 					val_dict_destroy(nargs);
 					free(nargs);
-					p->callstack[i].arguments = NULL;
+					retp->callstack[i].arguments = NULL;
 				}
 
 				/* Pretend that this round went well,
-				 * so that release1 frees I-th
+				 * so that fail3 frees I-th
 				 * fetch_context.  */
 				++i;
-				goto release1;
+				goto fail3;
 			}
 			retp->callstack[i].arguments = nargs;
 		}
 	}
 
 	if (arch_process_clone(retp, proc) < 0)
-		goto fail3;
+		goto fail4;
 
 	return 0;
 }
diff --git a/proc.h b/proc.h
index f530e5d..0dfa7db 100644
--- a/proc.h
+++ b/proc.h
@@ -107,7 +107,7 @@
 	unsigned int personality;
 	int tracesysgood;         /* signal indicating a PTRACE_SYSCALL trap */
 
-	int callstack_depth;
+	size_t callstack_depth;
 	struct callstack_element callstack[MAX_CALLDEPTH];
 
 	/* Linked list of libraries in backwards order of mapping.
diff --git a/sysdeps/linux-gnu/events.c b/sysdeps/linux-gnu/events.c
index 6e5eb60..d0c1e5c 100644
--- a/sysdeps/linux-gnu/events.c
+++ b/sysdeps/linux-gnu/events.c
@@ -22,20 +22,22 @@
 #include "config.h"
 
 #define	_GNU_SOURCE	1
-#include <stdlib.h>
+#include <sys/ptrace.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <assert.h>
 #include <errno.h>
 #include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
-#include <sys/ptrace.h>
-#include <assert.h>
 #include <unistd.h>
 
-#include "breakpoint.h"
-#include "proc.h"
 #include "backend.h"
+#include "breakpoint.h"
+#include "debug.h"
 #include "events.h"
+#include "proc.h"
 
 static Event event;
 
@@ -57,7 +59,7 @@
 	      event->proc->pid, event->type);
 	Event * ne = malloc(sizeof(*ne));
 	if (ne == NULL) {
-		perror("event will be missed: malloc");
+		fprintf(stderr, "event will be missed: %s\n", strerror(errno));
 		return;
 	}
 
diff --git a/sysdeps/linux-gnu/proc.c b/sysdeps/linux-gnu/proc.c
index 1550220..e7556f5 100644
--- a/sysdeps/linux-gnu/proc.c
+++ b/sysdeps/linux-gnu/proc.c
@@ -35,15 +35,18 @@
 #include <link.h>
 #include <signal.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
-#include "config.h"
-#include "breakpoint.h"
-#include "proc.h"
-#include "library.h"
 #include "backend.h"
+#include "breakpoint.h"
+#include "config.h"
+#include "debug.h"
 #include "events.h"
+#include "library.h"
+#include "ltrace-elf.h"
+#include "proc.h"
 
 /* /proc/pid doesn't exist just after the fork, and sometimes `ltrace'
  * couldn't open it to find the executable.  So it may be necessary to
@@ -113,7 +116,7 @@
 	char * line;
 	while ((line = find_line_starting(file, prefix, len)) != NULL) {
 		enum callback_status st = (*cb)(line, prefix, data);
-		free (line);
+		free(line);
 		if (st == CBS_STOP)
 			return;
 	}
diff --git a/sysdeps/linux-gnu/trace.c b/sysdeps/linux-gnu/trace.c
index 5924df1..3fc4df0 100644
--- a/sysdeps/linux-gnu/trace.c
+++ b/sysdeps/linux-gnu/trace.c
@@ -37,13 +37,15 @@
 # include <selinux/selinux.h>
 #endif
 
-#include "ptrace.h"
-#include "breakpoint.h"
-#include "proc.h"
 #include "linux-gnu/trace.h"
 #include "backend.h"
-#include "type.h"
+#include "breakpoint.h"
+#include "debug.h"
 #include "events.h"
+#include "options.h"
+#include "proc.h"
+#include "ptrace.h"
+#include "type.h"
 
 /* If the system headers did not provide the constants, hard-code the normal
    values.  */
@@ -673,8 +675,8 @@
 	struct Process *teb = self->task_enabling_breakpoint;
 	struct breakpoint *sbp = self->breakpoint_being_enabled;
 	fprintf(stderr, "%d couldn't continue when handling %s (%p) at %p\n",
-		teb->pid, sbp->libsym != NULL ? sbp->libsym->name : NULL,
-		sbp->addr, get_instruction_pointer(teb));
+		teb->pid, breakpoint_name(sbp),	sbp->addr,
+		get_instruction_pointer(teb));
 	delete_breakpoint(teb->leader, sbp->addr);
 }
 
diff --git a/sysdeps/linux-gnu/trace.h b/sysdeps/linux-gnu/trace.h
index 0f40709..88ac33d 100644
--- a/sysdeps/linux-gnu/trace.h
+++ b/sysdeps/linux-gnu/trace.h
@@ -21,6 +21,8 @@
 #ifndef _LTRACE_LINUX_TRACE_H_
 #define _LTRACE_LINUX_TRACE_H_
 
+#include "proc.h"
+
 /* This publishes some Linux-specific data structures used for process
  * handling.  */
 
diff --git a/sysdeps/linux-gnu/x86_64/trace.c b/sysdeps/linux-gnu/x86_64/trace.c
index 8e89ae7..bb4d67f 100644
--- a/sysdeps/linux-gnu/x86_64/trace.c
+++ b/sysdeps/linux-gnu/x86_64/trace.c
@@ -29,12 +29,14 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "common.h"
-#include "ptrace.h"
-#include "proc.h"
-#include "value.h"
+#include "backend.h"
+#include "debug.h"
 #include "expr.h"
+#include "fetch.h"
+#include "proc.h"
+#include "ptrace.h"
 #include "type.h"
+#include "value.h"
 
 #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR))
 # define PTRACE_PEEKUSER PTRACE_PEEKUSR