Don't write to inferior_ptid in tracectf.c
[deliverable/binutils-gdb.git] / gdbserver / win32-low.cc
index d5555a78fd2a6be84d806deb8816cdbf73e2b917..a11cc740925a13edb7c2e689998cd215fc32abfa 100644 (file)
@@ -88,6 +88,9 @@ static int soft_interrupt_requested = 0;
    by suspending all the threads.  */
 static int faked_breakpoint = 0;
 
+/* True if current_process_handle needs to be closed.  */
+static bool open_process_used = false;
+
 #ifdef __x86_64__
 bool wow64_process = false;
 #endif
@@ -383,6 +386,7 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)
 
   soft_interrupt_requested = 0;
   faked_breakpoint = 0;
+  open_process_used = true;
 
   memset (&current_event, 0, sizeof (current_event));
 
@@ -859,8 +863,11 @@ windows_nat::handle_output_debug_string (struct target_waitstatus *ourstatus)
 static void
 win32_clear_inferiors (void)
 {
-  if (current_process_handle != NULL)
-    CloseHandle (current_process_handle);
+  if (open_process_used)
+    {
+      CloseHandle (current_process_handle);
+      open_process_used = false;
+    }
 
   for_each_thread (delete_thread_info);
   siginfo_er.ExceptionCode = 0;
@@ -1414,69 +1421,39 @@ get_child_debug_event (DWORD *continue_status,
       goto gotevent;
     }
 
-#ifndef _WIN32_WCE
   attaching = 0;
-#else
-  if (attaching)
-    {
-      /* WinCE doesn't set an initial breakpoint automatically.  To
-        stop the inferior, we flush all currently pending debug
-        events -- the thread list and the dll list are always
-        reported immediatelly without delay, then, we suspend all
-        threads and pretend we saw a trap at the current PC of the
-        main thread.
-
-        Contrary to desktop Windows, Windows CE *does* report the dll
-        names on LOAD_DLL_DEBUG_EVENTs resulting from a
-        DebugActiveProcess call.  This limits the way we can detect
-        if all the dlls have already been reported.  If we get a real
-        debug event before leaving attaching, the worst that will
-        happen is the user will see a spurious breakpoint.  */
-
-      current_event.dwDebugEventCode = 0;
-      if (!wait_for_debug_event (&current_event, 0))
-       {
-         OUTMSG2(("no attach events left\n"));
-         fake_breakpoint_event ();
-         attaching = 0;
-       }
-      else
-       OUTMSG2(("got attach event\n"));
-    }
-  else
-#endif
-    {
-      gdb::optional<pending_stop> stop = fetch_pending_stop (debug_threads);
-      if (stop.has_value ())
-       {
-         *ourstatus = stop->status;
-         current_event = stop->event;
-         ptid = debug_event_ptid (&current_event);
-         current_thread = find_thread_ptid (ptid);
-         return 1;
-       }
+  {
+    gdb::optional<pending_stop> stop = fetch_pending_stop (debug_threads);
+    if (stop.has_value ())
+      {
+       *ourstatus = stop->status;
+       current_event = stop->event;
+       ptid = debug_event_ptid (&current_event);
+       current_thread = find_thread_ptid (ptid);
+       return 1;
+      }
 
-      /* Keep the wait time low enough for comfortable remote
-        interruption, but high enough so gdbserver doesn't become a
-        bottleneck.  */
-      if (!wait_for_debug_event (&current_event, 250))
-        {
-         DWORD e  = GetLastError();
+    /* Keep the wait time low enough for comfortable remote
+       interruption, but high enough so gdbserver doesn't become a
+       bottleneck.  */
+    if (!wait_for_debug_event (&current_event, 250))
+      {
+       DWORD e  = GetLastError();
 
-         if (e == ERROR_PIPE_NOT_CONNECTED)
-           {
-             /* This will happen if the loader fails to succesfully
-                load the application, e.g., if the main executable
-                tries to pull in a non-existing export from a
-                DLL.  */
-             ourstatus->kind = TARGET_WAITKIND_EXITED;
-             ourstatus->value.integer = 1;
-             return 1;
-           }
+       if (e == ERROR_PIPE_NOT_CONNECTED)
+         {
+           /* This will happen if the loader fails to succesfully
+              load the application, e.g., if the main executable
+              tries to pull in a non-existing export from a
+              DLL.  */
+           ourstatus->kind = TARGET_WAITKIND_EXITED;
+           ourstatus->value.integer = 1;
+           return 1;
+         }
 
-         return 0;
-        }
-    }
+       return 0;
+      }
+  }
 
  gotevent:
 
@@ -1513,6 +1490,12 @@ get_child_debug_event (DWORD *continue_status,
                (unsigned) current_event.dwThreadId));
       CloseHandle (current_event.u.CreateProcessInfo.hFile);
 
+      if (open_process_used)
+       {
+         CloseHandle (current_process_handle);
+         open_process_used = false;
+       }
+
       current_process_handle = current_event.u.CreateProcessInfo.hProcess;
       main_thread_id = current_event.dwThreadId;
 
@@ -1521,19 +1504,6 @@ get_child_debug_event (DWORD *continue_status,
                        main_thread_id,
                        current_event.u.CreateProcessInfo.hThread,
                        current_event.u.CreateProcessInfo.lpThreadLocalBase);
-
-#ifdef _WIN32_WCE
-      if (!attaching)
-       {
-         /* Windows CE doesn't set the initial breakpoint
-            automatically like the desktop versions of Windows do.
-            We add it explicitly here.  It will be removed as soon as
-            it is hit.  */
-         set_breakpoint_at ((CORE_ADDR) (long) current_event.u
-                            .CreateProcessInfo.lpStartAddress,
-                            auto_delete_breakpoint);
-       }
-#endif
       break;
 
     case EXIT_PROCESS_DEBUG_EVENT:
@@ -1560,8 +1530,6 @@ get_child_debug_event (DWORD *continue_status,
          }
       }
       child_continue (DBG_CONTINUE, desired_stop_thread_id);
-      CloseHandle (current_process_handle);
-      current_process_handle = NULL;
       break;
 
     case LOAD_DLL_DEBUG_EVENT:
This page took 0.02587 seconds and 4 git commands to generate.