Do the target-waiting within do_initial_child_stuff on Windows.
authorPedro Alves <palves@redhat.com>
Thu, 12 Dec 2013 16:12:30 +0000 (11:12 -0500)
committerJoel Brobecker <brobecker@adacore.com>
Fri, 13 Dec 2013 15:42:08 +0000 (16:42 +0100)
This is a preparatory patch that achieves two goals:

  . Makes the initial event handling more similar to GDB's;
  . Opens the door for implementing post-inititial-handling
    operations.

At the moment, this is only done on Windows, where the
post-initial-handling is going to be needed (in the context of
Windows 2012). And because we're close to creating the gdb 7.7
branch, making that change for all platforms is a little more
risk that we'd like. So the change is currently implemented
on Windows.

gdb/gdbserver/ChangeLog:

        * target.c (mywait): Set OURSTATUS->KIND to TARGET_WAITKIND_STOPPED
        if equal to TARGET_WAITKIND_LOADED.
        * win32-low.c (cached_status): New static global.
        (win32_wait): Add declaration.
        (do_initial_child_stuff): Flush all initial pending debug events
        up to the initial breakpoint.
        (win32_wait): If CACHED_STATUS was set, return that instead
        of doing a real wait.  Remove the code resuming the execution
        of the inferior after receiving a TARGET_WAITKIND_LOADED event
        during the initial phase.  Also remove the code changing
        OURSTATUS->KIND from TARGET_WAITKIND_LOADED to
        TARGET_WAITKIND_STOPPED.

gdb/gdbserver/ChangeLog
gdb/gdbserver/target.c
gdb/gdbserver/win32-low.c

index 26d305e01e149512d92da477914d43ca7e89f221..9f8eb9ef378dec5006725fbb7b483a3dc21f5a7c 100644 (file)
@@ -1,3 +1,18 @@
+2013-12-13  Pedro Alves  <palves@redhat.com>
+
+       * target.c (mywait): Set OURSTATUS->KIND to TARGET_WAITKIND_STOPPED
+       if equal to TARGET_WAITKIND_LOADED.
+       * win32-low.c (cached_status): New static global.
+       (win32_wait): Add declaration.
+       (do_initial_child_stuff): Flush all initial pending debug events
+       up to the initial breakpoint.
+       (win32_wait): If CACHED_STATUS was set, return that instead
+       of doing a real wait.  Remove the code resuming the execution
+       of the inferior after receiving a TARGET_WAITKIND_LOADED event
+       during the initial phase.  Also remove the code changing
+       OURSTATUS->KIND from TARGET_WAITKIND_LOADED to
+       TARGET_WAITKIND_STOPPED.
+
 2013-12-11  Yao Qi  <yao@codesourcery.com>
 
        * notif.c (handle_notif_ack): Return 0 if no notification
index d4a2a98721a9bfa2ee2cc092c66d3fe32ea21e52..d2299334f9fe6dcf7fee37af1005e10eaf3406de 100644 (file)
@@ -82,6 +82,11 @@ mywait (ptid_t ptid, struct target_waitstatus *ourstatus, int options,
 
   ret = (*the_target->wait) (ptid, ourstatus, options);
 
+  /* We don't expose _LOADED events to gdbserver core.  See the
+     `dlls_changed' global.  */
+  if (ourstatus->kind == TARGET_WAITKIND_LOADED)
+    ourstatus->kind = TARGET_WAITKIND_STOPPED;
+
   /* If GDB is connected through TCP/serial, then GDBserver will most
      probably be running on its own terminal/console, so it's nice to
      print there why is GDBserver exiting.  If however, GDB is
index 979eedd5f8056246662196ff7e6f35dbd724b2f8..a4c9e77a0fd7004bb0ed58c7ec593c25fa223b9f 100644 (file)
@@ -80,6 +80,11 @@ static enum gdb_signal last_sig = GDB_SIGNAL_0;
 /* The current debug event from WaitForDebugEvent.  */
 static DEBUG_EVENT current_event;
 
+/* A status that hasn't been reported to the core yet, and so
+   win32_wait should return it next, instead of fetching the next
+   debug event off the win32 API.  */
+static struct target_waitstatus cached_status;
+
 /* Non zero if an interrupt request is to be satisfied by suspending
    all threads.  */
 static int soft_interrupt_requested = 0;
@@ -97,6 +102,8 @@ typedef BOOL (WINAPI *winapi_DebugSetProcessKillOnExit) (BOOL KillOnExit);
 typedef BOOL (WINAPI *winapi_DebugBreakProcess) (HANDLE);
 typedef BOOL (WINAPI *winapi_GenerateConsoleCtrlEvent) (DWORD, DWORD);
 
+static ptid_t win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus,
+                         int options);
 static void win32_resume (struct thread_resume *resume_info, size_t n);
 
 /* Get the thread ID from the current selected inferior (the current
@@ -336,6 +343,34 @@ do_initial_child_stuff (HANDLE proch, DWORD pid, int attached)
 
   if (the_low_target.initial_stuff != NULL)
     (*the_low_target.initial_stuff) ();
+
+  cached_status.kind = TARGET_WAITKIND_IGNORE;
+
+  /* Flush all currently pending debug events (thread and dll list) up
+     to the initial breakpoint.  */
+  while (1)
+    {
+      struct target_waitstatus status;
+
+      win32_wait (minus_one_ptid, &status, 0);
+
+      /* Note win32_wait doesn't return thread events.  */
+      if (status.kind != TARGET_WAITKIND_LOADED)
+       {
+         cached_status = status;
+         break;
+       }
+
+      {
+       struct thread_resume resume;
+
+       resume.thread = minus_one_ptid;
+       resume.kind = resume_continue;
+       resume.sig = 0;
+
+       win32_resume (&resume, 1);
+      }
+    }
 }
 
 /* Resume all artificially suspended threads if we are continuing
@@ -1593,6 +1628,17 @@ win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus, int options)
 {
   struct regcache *regcache;
 
+  if (cached_status.kind != TARGET_WAITKIND_IGNORE)
+    {
+      /* The core always does a wait after creating the inferior, and
+        do_initial_child_stuff already ran the inferior to the
+        initial breakpoint (or an exit, if creating the process
+        fails).  Report it now.  */
+      *ourstatus = cached_status;
+      cached_status.kind = TARGET_WAITKIND_IGNORE;
+      return debug_event_ptid (&current_event);
+    }
+
   while (1)
     {
       if (!get_child_debug_event (ourstatus))
@@ -1612,21 +1658,6 @@ win32_wait (ptid_t ptid, struct target_waitstatus *ourstatus, int options)
 
          regcache = get_thread_regcache (current_inferior, 1);
          child_fetch_inferior_registers (regcache, -1);
-
-         if (ourstatus->kind == TARGET_WAITKIND_LOADED
-             && !server_waiting)
-           {
-             /* When gdb connects, we want to be stopped at the
-                initial breakpoint, not in some dll load event.  */
-             child_continue (DBG_CONTINUE, -1);
-             break;
-           }
-
-         /* We don't expose _LOADED events to gdbserver core.  See
-            the `dlls_changed' global.  */
-         if (ourstatus->kind == TARGET_WAITKIND_LOADED)
-           ourstatus->kind = TARGET_WAITKIND_STOPPED;
-
          return debug_event_ptid (&current_event);
        default:
          OUTMSG (("Ignoring unknown internal event, %d\n", ourstatus->kind));
This page took 0.031914 seconds and 4 git commands to generate.