This is the mail archive of the gdb-patches@sourceware.org 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]

Re: [RFA] windows: do not crash if inferior


On Wed, Jan 20, 2010 at 07:12:12PM +0000, Pedro Alves wrote:
>On Wednesday 20 January 2010 17:37:46, Christopher Faylor wrote:
>
>> Actually, how about something like this instead?  I used the same wording as fork-child.c
>> after seeing Pedro's note.
>
>> +      if (!windows_initialization_done)
>> +	error (_("During startup program exited with code 0x%x."), (unsigned int) current_event.u.ExitProcess.dwExitCode);
>
>I think you should call target_mourn_inferior before
>throwing, to unpush the target_ops, clear inferior_ptid
>and delete any thread the OS had already reported, and
>maybe other things.  You'll also want to call
>target_terminal_ours.

Yes, that should have been obvious to me since I was trying to duplicate
fork-child.c and it does exactly what you suggested.  So the new patch
is below.

I don't have an easy way to test this.  Can the OP confirm/deny that this
works as intended?

cgf

2010-01-21  Christopher Faylor  <me+gdb@cgf.cx>

	* windows-nat.c (windows_initialization_done): New variable.
	(get_windows_debug_event): Issue error when process dies before
	completely initializing.
	(do_initial_windows_stuff): Set flag to indicate when we are done with
	the initial steps of attaching to the child.


Index: windows-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/windows-nat.c,v
retrieving revision 1.196.4.1
diff -u -p -r1.196.4.1 windows-nat.c
--- windows-nat.c	30 Sep 2009 07:40:10 -0000	1.196.4.1
+++ windows-nat.c	21 Jan 2010 17:54:58 -0000
@@ -123,6 +128,8 @@ enum
 static uintptr_t dr[8];
 static int debug_registers_changed;
 static int debug_registers_used;
+
+static int windows_initialization_done;
 #define DR6_CLEAR_VALUE 0xffff0ff0
 
 /* The string sent by cygwin when it processes a signal.
@@ -1399,11 +1407,19 @@ get_windows_debug_event (struct target_o
 		     (unsigned) current_event.dwProcessId,
 		     (unsigned) current_event.dwThreadId,
 		     "EXIT_PROCESS_DEBUG_EVENT"));
-      if (saw_create != 1)
-	break;
-      ourstatus->kind = TARGET_WAITKIND_EXITED;
-      ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
-      retval = main_thread_id;
+      if (!windows_initialization_done)
+	{
+	  target_terminal_ours ();
+	  target_mourn_inferior ();
+	  error (_("During startup program exited with code 0x%x."),
+		 (unsigned int) current_event.u.ExitProcess.dwExitCode);
+	}
+      else if (saw_create == 1)
+	{
+	  ourstatus->kind = TARGET_WAITKIND_EXITED;
+	  ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
+	  retval = main_thread_id;
+	}
       break;
 
     case LOAD_DLL_DEBUG_EVENT:
@@ -1597,6 +1613,7 @@ do_initial_windows_stuff (struct target_
   terminal_init_inferior_with_pgrp (pid);
   target_terminal_inferior ();
 
+  windows_initialization_done = 0;
   inf->stop_soon = STOP_QUIETLY;
   while (1)
     {
@@ -1609,6 +1626,7 @@ do_initial_windows_stuff (struct target_
 	break;
     }
 
+  windows_initialization_done = 1;
   inf->stop_soon = NO_STOP_QUIETLY;
   stop_after_trap = 0;
   return;


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