[binutils-gdb] Windows gdb: Simplify windows_nat_target::wait

Pedro Alves via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=db040a86c8118c80fc02c41096944c6c0faa51ae

commit db040a86c8118c80fc02c41096944c6c0faa51ae
Author: Pedro Alves <[email protected]>
Date:   Thu May 11 13:16:09 2023 +0100

    Windows gdb: Simplify windows_nat_target::wait
    
    The logic in windows_nat_target::wait, where we decide what to do
    depending on the result from get_windows_debug_event is harder to
    grasp than it looks.
    
    It is not easy to tell what should happen when in async mode
    get_windows_debug_event returns that there's no event to process.
    
    And then, if get_windows_debug_event returns null_ptid /
    TARGET_WAITKIND_SPURIOUS, then we need to issue a ContinueDebugEvent.
    
    There's also this comment in windows_nat_target::wait, which we're not
    really implementing today:
    
    ~~~~
      /* We loop when we get a non-standard exception rather than return
         with a SPURIOUS because resume can try and step or modify things,
         which needs a current_thread->h.  But some of these exceptions mark
         the birth or death of threads, which mean that the current thread
         isn't necessarily what you think it is.  */
    ~~~~
    
    This patch changes things a bit so that the code is more obvious:
    
     - look at the status kind, instead of ptid_t.
    
     - add an explicit early return case for no-event.
    
     - add an explicit case for TARGET_WAITKIND_SPURIOUS.
    
     - with those, we no longer need to handle the case of find_thread not
       finding a thread, so we can drop one indentation level.
    
    Approved-By: Tom Tromey <[email protected]>
    Change-Id: I76c41762e1f893a7ff23465856ccf6a44af1f0e7
    commit-id:aff7fc4a

Diff:
---
 gdb/windows-nat.c | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 2dd372ae7b2..30b07221b62 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -1139,7 +1139,10 @@ windows_nat_target::get_windows_debug_event
     }
 
   if (thread_id == 0)
-    return null_ptid;
+    {
+      ourstatus->set_ignore ();
+      return null_ptid;
+    }
   return ptid_t (windows_process->current_event.dwProcessId, thread_id, 0);
 }
 
@@ -1160,25 +1163,33 @@ windows_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
     {
       ptid_t result = get_windows_debug_event (pid, ourstatus, options);
 
-      if (result != null_ptid)
+      if ((options & TARGET_WNOHANG) != 0
+	  && ourstatus->kind () == TARGET_WAITKIND_IGNORE)
+	return result;
+
+      if (ourstatus->kind () == TARGET_WAITKIND_SPURIOUS)
+	{
+	  CHECK (windows_continue (DBG_CONTINUE,
+				   windows_process->desired_stop_thread_id, 0));
+	}
+      else if (ourstatus->kind () != TARGET_WAITKIND_IGNORE)
 	{
 	  if (ourstatus->kind () != TARGET_WAITKIND_EXITED
-	      && ourstatus->kind () !=  TARGET_WAITKIND_SIGNALLED)
+	      && ourstatus->kind () != TARGET_WAITKIND_SIGNALLED)
 	    {
 	      windows_thread_info *th = windows_process->find_thread (result);
 
-	      if (th != nullptr)
+	      th->stopped_at_software_breakpoint = false;
+	      if (windows_process->current_event.dwDebugEventCode
+		  == EXCEPTION_DEBUG_EVENT
+		  && ((windows_process->current_event.u.Exception.ExceptionRecord.ExceptionCode
+		       == EXCEPTION_BREAKPOINT)
+		      || (windows_process->current_event.u.Exception.ExceptionRecord.ExceptionCode
+			  == STATUS_WX86_BREAKPOINT))
+		  && windows_process->windows_initialization_done)
 		{
-		  th->stopped_at_software_breakpoint = false;
-		  if (windows_process->current_event.dwDebugEventCode
-		      == EXCEPTION_DEBUG_EVENT
-		      && is_sw_breakpoint (&windows_process->current_event
-					   .u.Exception.ExceptionRecord)
-		      && windows_process->windows_initialization_done)
-		    {
-		      th->stopped_at_software_breakpoint = true;
-		      th->pc_adjusted = false;
-		    }
+		  th->stopped_at_software_breakpoint = true;
+		  th->pc_adjusted = false;
 		}
 	    }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.