This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix gdb SEGV when main thread exits while program keeps running


2003-12-25  Christopher Faylor  <cgf@redhat.com>
 
 	* win32-nat.c (get_child_debug_event): Keep main thread id around even
 	after thread exits since Windows insists on continuing to report events
 	against it.
 
Index: win32-nat.c
===================================================================
RCS file: /cvs/uberbaum/gdb/win32-nat.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -p -w -r1.83 -r1.84
--- win32-nat.c	26 Oct 2003 15:03:41 -0000	1.83
+++ win32-nat.c	26 Dec 2003 00:39:04 -0000	1.84
@@ -76,8 +76,8 @@ enum
 	| CONTEXT_EXTENDED_REGISTERS
 
 static unsigned dr[8];
-static int debug_registers_changed = 0;
-static int debug_registers_used = 0;
+static int debug_registers_changed;
+static int debug_registers_used;
 
 /* The string sent by cygwin when it processes a signal.
    FIXME: This should be in a cygwin include file. */
@@ -1205,7 +1205,7 @@ get_child_debug_event (int pid, struct t
 {
   BOOL debug_event;
   DWORD continue_status, event_code;
-  thread_info *th = NULL;
+  thread_info *th;
   static thread_info dummy_thread_info;
   int retval = 0;
 
@@ -1219,6 +1219,7 @@ get_child_debug_event (int pid, struct t
 
   event_code = current_event.dwDebugEventCode;
   ourstatus->kind = TARGET_WAITKIND_SPURIOUS;
+  th = NULL;
 
   switch (event_code)
     {
@@ -1246,8 +1247,11 @@ get_child_debug_event (int pid, struct t
 		     "EXIT_THREAD_DEBUG_EVENT"));
       if (saw_create != 1)
 	break;
+      if (current_event.dwThreadId != main_thread_id)
+	{
       child_delete_thread (current_event.dwThreadId);
       th = &dummy_thread_info;
+	}
       break;
 
     case CREATE_PROCESS_DEBUG_EVENT:
@@ -1263,12 +1267,10 @@ get_child_debug_event (int pid, struct t
 	}
 
       current_process_handle = current_event.u.CreateProcessInfo.hProcess;
+      if (main_thread_id)
+	child_delete_thread (main_thread_id);
       main_thread_id = current_event.dwThreadId;
       /* Add the main thread */
-#if 0
-      th = child_add_thread (current_event.dwProcessId,
-			     current_event.u.CreateProcessInfo.hProcess);
-#endif
       th = child_add_thread (main_thread_id,
 			     current_event.u.CreateProcessInfo.hThread);
       retval = ourstatus->value.related_pid = current_event.dwThreadId;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]