Fix -Wuh and -Wnhu options so that they work.
[deliverable/binutils-gdb.git] / gdb / win32-nat.c
index 04d8a9eff43c84d0cc240e6c16d94be67a978197..fa19797a6b001e4ff66921be3e0aaa0929ba51e3 100644 (file)
 #include <sys/param.h>
 #include <unistd.h>
 
+/* The ui's event loop. */
+extern int (*ui_loop_hook) PARAMS ((int signo));
+
+/* If we're not using the old Cygwin header file set, define the
+   following which never should have been in the generic Win32 API
+   headers in the first place since they were our own invention... */
+#ifndef _GNU_H_WINDOWS_H
+#define FLAG_TRACE_BIT 0x100
+#define CONTEXT_DEBUGGER (CONTEXT_FULL | CONTEXT_FLOATING_POINT)
+#endif
+
 /* The string sent by cygwin when it processes a signal.
    FIXME: This should be in a cygwin include file. */
 #define CYGWIN_SIGNAL_STRING "cygwin: signal"
@@ -64,7 +75,8 @@
 extern struct target_ops child_ops;
 
 static void child_stop PARAMS ((void));
-static int child_thread_alive PARAMS ((int));
+static int win32_child_thread_alive PARAMS ((int));
+void child_kill_inferior PARAMS ((void));
 
 static int last_sig = 0;       /* Set if a signal was received from the
                                   debugged process */
@@ -302,7 +314,7 @@ child_store_inferior_registers (int r)
    of error; store status through argument pointer OURSTATUS.  */
 
 static int
-handle_load_dll (char *dummy)
+handle_load_dll (PTR dummy)
 {
   LOAD_DLL_DEBUG_INFO * event = &current_event.u.LoadDll;
   DWORD dll_name_ptr;
@@ -424,7 +436,7 @@ handle_load_dll (char *dummy)
      FIXME: Is this the real reason that we need the 0x1000 ? */
 
   printf_unfiltered ("%x:%s", event->lpBaseOfDll, dll_name);
-  symbol_file_add (dll_name, 0, (int) event->lpBaseOfDll + 0x1000, 0, 0, 0);
+  symbol_file_add (dll_name, 0, (int) event->lpBaseOfDll + 0x1000, 0, 0, 0, 0, 1);
   printf_unfiltered ("\n");
 
 out:
@@ -453,7 +465,9 @@ handle_output_debug_string (struct target_waitstatus *ourstatus)
     {
       char *p;
       /*last_sig = */strtol(s + sizeof(CYGWIN_SIGNAL_STRING) - 1, &p, 0);
-      if (gotasig = (ourstatus->value.sig = target_signal_from_host (last_sig)))
+      gotasig = target_signal_from_host (last_sig);
+      ourstatus->value.sig = gotasig;
+      if (gotasig)
        ourstatus->kind = TARGET_WAITKIND_STOPPED;
     }
 
@@ -530,9 +544,10 @@ child_continue (DWORD continue_status, int id)
 
   DEBUG_EVENTS (("ContinueDebugEvent (cpid=%d, ctid=%d, DBG_CONTINUE);\n",
                 current_event.dwProcessId, current_event.dwThreadId));
-  if (res = ContinueDebugEvent (current_event.dwProcessId,
-                               current_event.dwThreadId,
-                               continue_status))
+  res = ContinueDebugEvent (current_event.dwProcessId,
+                           current_event.dwThreadId,
+                           continue_status);
+  if (res)
     for (th = &thread_head; (th = th->next) != NULL; )
       if (((id == -1) || (id == th->id)) && th->suspend_count)
        {
@@ -556,98 +571,111 @@ child_wait (int pid, struct target_waitstatus *ourstatus)
   while (1)
     {
       DWORD continue_status;
-      BOOL t = WaitForDebugEvent (&current_event, INFINITE);
+      BOOL debug_event = WaitForDebugEvent (&current_event, 20);
       char *p;
       thread_info *th;
       int sig;
 
-      event_count++;
-
-      continue_status = DBG_CONTINUE;
-
-      switch (current_event.dwDebugEventCode)
+      if (debug_event)
        {
-       case CREATE_THREAD_DEBUG_EVENT:
-         DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%x code=%s)\n",
-                       current_event.dwProcessId, current_event.dwThreadId,
-                       "CREATE_THREAD_DEBUG_EVENT"));
-         /* Record the existence of this thread */
-         child_add_thread (current_event.dwThreadId,
-                           current_event.u.CreateThread.hThread);
-         if (info_verbose)
-             printf_unfiltered ("[New %s]\n",
-                              target_pid_to_str (current_event.dwThreadId));
-         break;
-
-       case EXIT_THREAD_DEBUG_EVENT:
-         DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
-                       current_event.dwProcessId, current_event.dwThreadId,
-                       "EXIT_THREAD_DEBUG_EVENT"));
-         child_delete_thread (current_event.dwThreadId);
-         break;
-
-       case CREATE_PROCESS_DEBUG_EVENT:
-         DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
-                       current_event.dwProcessId, current_event.dwThreadId,
-                       "CREATE_PROCESS_DEBUG_EVENT"));
-         current_process_handle = current_event.u.CreateProcessInfo.hProcess;
-
-         main_thread_id = inferior_pid = current_event.dwThreadId;
-         /* Add the main thread */
-         current_thread = child_add_thread (inferior_pid,
-                               current_event.u.CreateProcessInfo.hThread);
-         break;
-
-       case EXIT_PROCESS_DEBUG_EVENT:
-         DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
-                       current_event.dwProcessId, current_event.dwThreadId,
-                       "EXIT_PROCESS_DEBUG_EVENT"));
-         ourstatus->kind = TARGET_WAITKIND_EXITED;
-         ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
-         CloseHandle (current_process_handle);
-         return current_event.dwProcessId;
-         break;
-
-       case LOAD_DLL_DEBUG_EVENT:
-         DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
-                       current_event.dwProcessId, current_event.dwThreadId,
-                       "LOAD_DLL_DEBUG_EVENT"));
-          catch_errors (handle_load_dll, NULL, "", RETURN_MASK_ALL);
-         registers_changed();          /* mark all regs invalid */
-         break;
-
-       case UNLOAD_DLL_DEBUG_EVENT:
-         DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
-                       current_event.dwProcessId, current_event.dwThreadId,
-                       "UNLOAD_DLL_DEBUG_EVENT"));
-         break;        /* FIXME: don't know what to do here */
-
-       case EXCEPTION_DEBUG_EVENT:
-         DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
-                       current_event.dwProcessId, current_event.dwThreadId,
-                       "EXCEPTION_DEBUG_EVENT"));
-         if (handle_exception (ourstatus))
-           return current_event.dwThreadId;
-         continue_status = DBG_EXCEPTION_NOT_HANDLED;
-         break;
-
-       case OUTPUT_DEBUG_STRING_EVENT: /* message from the kernel */
-         DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
-                       current_event.dwProcessId, current_event.dwThreadId,
-                       "OUTPUT_DEBUG_STRING_EVENT"));
-         if (handle_output_debug_string (ourstatus))
-           return main_thread_id;
-         break;
-       default:
-         printf_unfiltered ("gdb: kernel event for pid=%d tid=%d\n",
-                            current_event.dwProcessId,
-                            current_event.dwThreadId);
-         printf_unfiltered ("                 unknown event code %d\n",
-                            current_event.dwDebugEventCode);
-         break;
+         event_count++;
+
+         continue_status = DBG_CONTINUE;
+
+         switch (current_event.dwDebugEventCode)
+           {
+           case CREATE_THREAD_DEBUG_EVENT:
+             DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%x code=%s)\n",
+                            current_event.dwProcessId, current_event.dwThreadId,
+                            "CREATE_THREAD_DEBUG_EVENT"));
+             /* Record the existence of this thread */
+             child_add_thread (current_event.dwThreadId,
+                               current_event.u.CreateThread.hThread);
+             if (info_verbose)
+               printf_unfiltered ("[New %s]\n",
+                                  target_pid_to_str (current_event.dwThreadId));
+             break;
+
+           case EXIT_THREAD_DEBUG_EVENT:
+             DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
+                            current_event.dwProcessId, current_event.dwThreadId,
+                            "EXIT_THREAD_DEBUG_EVENT"));
+             child_delete_thread (current_event.dwThreadId);
+             break;
+
+           case CREATE_PROCESS_DEBUG_EVENT:
+             DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
+                            current_event.dwProcessId, current_event.dwThreadId,
+                            "CREATE_PROCESS_DEBUG_EVENT"));
+             current_process_handle = current_event.u.CreateProcessInfo.hProcess;
+
+             main_thread_id = inferior_pid = current_event.dwThreadId;
+             /* Add the main thread */
+             current_thread = child_add_thread (inferior_pid,
+                                                current_event.u.CreateProcessInfo.hThread);
+             break;
+
+           case EXIT_PROCESS_DEBUG_EVENT:
+             DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
+                            current_event.dwProcessId, current_event.dwThreadId,
+                            "EXIT_PROCESS_DEBUG_EVENT"));
+             ourstatus->kind = TARGET_WAITKIND_EXITED;
+             ourstatus->value.integer = current_event.u.ExitProcess.dwExitCode;
+             CloseHandle (current_process_handle);
+             return current_event.dwProcessId;
+             break;
+
+           case LOAD_DLL_DEBUG_EVENT:
+             DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
+                            current_event.dwProcessId, current_event.dwThreadId,
+                            "LOAD_DLL_DEBUG_EVENT"));
+             catch_errors (handle_load_dll, NULL, "", RETURN_MASK_ALL);
+             registers_changed();          /* mark all regs invalid */
+             break;
+
+           case UNLOAD_DLL_DEBUG_EVENT:
+             DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
+                            current_event.dwProcessId, current_event.dwThreadId,
+                            "UNLOAD_DLL_DEBUG_EVENT"));
+             break;    /* FIXME: don't know what to do here */
+
+           case EXCEPTION_DEBUG_EVENT:
+             DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
+                            current_event.dwProcessId, current_event.dwThreadId,
+                            "EXCEPTION_DEBUG_EVENT"));
+             if (handle_exception (ourstatus))
+               return current_event.dwThreadId;
+             continue_status = DBG_EXCEPTION_NOT_HANDLED;
+             break;
+
+           case OUTPUT_DEBUG_STRING_EVENT: /* message from the kernel */
+             DEBUG_EVENTS (("gdb: kernel event for pid=%d tid=%d code=%s)\n",
+                            current_event.dwProcessId, current_event.dwThreadId,
+                            "OUTPUT_DEBUG_STRING_EVENT"));
+             if (handle_output_debug_string (ourstatus))
+               return main_thread_id;
+             break;
+           default:
+             printf_unfiltered ("gdb: kernel event for pid=%d tid=%d\n",
+                                current_event.dwProcessId,
+                                current_event.dwThreadId);
+             printf_unfiltered ("                 unknown event code %d\n",
+                                current_event.dwDebugEventCode);
+             break;
+           }
+
+         CHECK (child_continue (continue_status, -1));
        }
+      else
+       {
+         int detach = 0;
 
-      CHECK (child_continue (continue_status, -1));
+         if (ui_loop_hook != NULL)
+           detach = ui_loop_hook (0);
+
+         if (detach)
+           child_kill_inferior ();
+       }
     }
 }
 
@@ -1003,7 +1031,8 @@ child_close ()
 
 struct target_ops child_ops ;
 
-static void init_child_ops(void)
+static void 
+init_child_ops(void)
 {
   child_ops.to_shortname =   "child";
   child_ops.to_longname =   "Win32 child process";
@@ -1033,7 +1062,7 @@ static void init_child_ops(void)
   child_ops.to_mourn_inferior =   child_mourn_inferior;
   child_ops.to_can_run  =   child_can_run;
   child_ops.to_notice_signals =   0;
-  child_ops.to_thread_alive  =   child_thread_alive;
+  child_ops.to_thread_alive  =   win32_child_thread_alive;
   child_ops.to_stop  =   child_stop;
   child_ops.to_stratum =   process_stratum;
   child_ops.DONT_USE =   0;
@@ -1102,7 +1131,7 @@ _initialize_inftarg ()
    by "polling" it.  If WaitForSingleObject returns WAIT_OBJECT_0
    it means that the pid has died.  Otherwise it is assumed to be alive. */
 static int
-child_thread_alive (int pid)
+win32_child_thread_alive (int pid)
 {
   return WaitForSingleObject(thread_rec (pid, FALSE)->h, 0) == WAIT_OBJECT_0 ?
         FALSE : TRUE;
This page took 0.02687 seconds and 4 git commands to generate.