Fixed handling of debug events on thread/process exit.

diff --git a/server/process.c b/server/process.c
index 4e8062b..b105cc9 100644
--- a/server/process.c
+++ b/server/process.c
@@ -60,8 +60,6 @@
     process->next            = NULL;
     process->prev            = NULL;
     process->thread_list     = NULL;
-    process->debug_next      = NULL;
-    process->debug_prev      = NULL;
     process->debugger        = NULL;
     process->handles         = NULL;
     process->exit_code       = 0x103;  /* STILL_ACTIVE */
@@ -292,6 +290,21 @@
         kill_thread( process->thread_list, exit_code );
 }
 
+/* kill all processes being debugged by a given thread */
+void kill_debugged_processes( struct thread *debugger, int exit_code )
+{
+    for (;;)  /* restart from the beginning of the list every time */
+    {
+        struct process *process = first_process;
+        /* find the first process being debugged by 'debugger' and still running */
+        while (process && (process->debugger != debugger || !process->running_threads))
+            process = process->next;
+        if (!process) return;
+        process->debugger = NULL;
+        kill_process( process, exit_code );
+    }
+}
+
 /* get all information about a process */
 static void get_process_info( struct process *process, struct get_process_info_request *req )
 {