public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 1/2] Turn some windows-nat.c static functions into methods
Date: Thu,  7 Apr 2022 13:56:05 -0600	[thread overview]
Message-ID: <20220407195606.1847158-2-tromey@adacore.com> (raw)
In-Reply-To: <20220407195606.1847158-1-tromey@adacore.com>

This patch turns some windows-nat.c static functions into methods on
windows_nat_target.  This avoids having to reference the
windows_nat_target singleton in some more spots -- a minor code
cleanup.
---
 gdb/windows-nat.c | 47 ++++++++++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 19 deletions(-)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 646ddda7328..564eb867ff4 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -287,6 +287,13 @@ struct windows_nat_target final : public x86_nat_target<inf_child_target>
   int get_windows_debug_event (int pid, struct target_waitstatus *ourstatus);
 
   void do_initial_windows_stuff (DWORD pid, bool attaching);
+
+private:
+
+  windows_thread_info *add_thread (ptid_t ptid, HANDLE h, void *tlb,
+				   bool main_thread_p);
+  void delete_thread (ptid_t ptid, DWORD exit_code, bool main_thread_p);
+  DWORD fake_create_process ();
 };
 
 static windows_nat_target the_windows_nat_target;
@@ -358,8 +365,9 @@ windows_nat::windows_process_info::thread_rec
    MAIN_THREAD_P should be true if the thread to be added is
    the main thread, false otherwise.  */
 
-static windows_thread_info *
-windows_add_thread (ptid_t ptid, HANDLE h, void *tlb, bool main_thread_p)
+windows_thread_info *
+windows_nat_target::add_thread (ptid_t ptid, HANDLE h, void *tlb,
+				bool main_thread_p)
 {
   windows_thread_info *th;
 
@@ -384,9 +392,9 @@ windows_add_thread (ptid_t ptid, HANDLE h, void *tlb, bool main_thread_p)
      the main thread silently (in reality, this thread is really
      more of a process to the user than a thread).  */
   if (main_thread_p)
-    add_thread_silent (&the_windows_nat_target, ptid);
+    add_thread_silent (this, ptid);
   else
-    add_thread (&the_windows_nat_target, ptid);
+    ::add_thread (this, ptid);
 
   /* It's simplest to always set this and update the debug
      registers.  */
@@ -411,8 +419,9 @@ windows_init_thread_list (void)
    MAIN_THREAD_P should be true if the thread to be deleted is
    the main thread, false otherwise.  */
 
-static void
-windows_delete_thread (ptid_t ptid, DWORD exit_code, bool main_thread_p)
+void
+windows_nat_target::delete_thread (ptid_t ptid, DWORD exit_code,
+				   bool main_thread_p)
 {
   DWORD id;
 
@@ -434,7 +443,7 @@ windows_delete_thread (ptid_t ptid, DWORD exit_code, bool main_thread_p)
 		target_pid_to_str (ptid).c_str (),
 		(unsigned) exit_code);
 
-  delete_thread (find_thread_ptid (&the_windows_nat_target, ptid));
+  ::delete_thread (find_thread_ptid (&the_windows_nat_target, ptid));
 
   auto iter = std::find_if (thread_list.begin (), thread_list.end (),
 			    [=] (auto &th)
@@ -1215,8 +1224,8 @@ windows_continue (DWORD continue_status, int id, int killed)
 
 /* Called in pathological case where Windows fails to send a
    CREATE_PROCESS_DEBUG_EVENT after an attach.  */
-static DWORD
-fake_create_process (void)
+DWORD
+windows_nat_target::fake_create_process ()
 {
   windows_process.handle
     = OpenProcess (PROCESS_ALL_ACCESS, FALSE,
@@ -1229,7 +1238,7 @@ fake_create_process (void)
        (unsigned) GetLastError ());
       /*  We can not debug anything in that case.  */
     }
-  windows_add_thread (ptid_t (windows_process.current_event.dwProcessId, 0,
+  add_thread (ptid_t (windows_process.current_event.dwProcessId, 0,
 			      windows_process.current_event.dwThreadId),
 		      windows_process.current_event.u.CreateThread.hThread,
 		      windows_process.current_event.u.CreateThread.lpThreadLocalBase,
@@ -1479,7 +1488,7 @@ windows_nat_target::get_windows_debug_event (int pid,
 	}
       /* Record the existence of this thread.  */
       thread_id = current_event->dwThreadId;
-      windows_add_thread
+      add_thread
 	(ptid_t (current_event->dwProcessId, current_event->dwThreadId, 0),
 	 current_event->u.CreateThread.hThread,
 	 current_event->u.CreateThread.lpThreadLocalBase,
@@ -1492,10 +1501,10 @@ windows_nat_target::get_windows_debug_event (int pid,
 		    (unsigned) current_event->dwProcessId,
 		    (unsigned) current_event->dwThreadId,
 		    "EXIT_THREAD_DEBUG_EVENT");
-      windows_delete_thread (ptid_t (current_event->dwProcessId,
-				     current_event->dwThreadId, 0),
-			     current_event->u.ExitThread.dwExitCode,
-			     false /* main_thread_p */);
+      delete_thread (ptid_t (current_event->dwProcessId,
+			     current_event->dwThreadId, 0),
+		     current_event->u.ExitThread.dwExitCode,
+		     false /* main_thread_p */);
       break;
 
     case CREATE_PROCESS_DEBUG_EVENT:
@@ -1509,7 +1518,7 @@ windows_nat_target::get_windows_debug_event (int pid,
 
       windows_process.handle = current_event->u.CreateProcessInfo.hProcess;
       /* Add the main thread.  */
-      windows_add_thread
+      add_thread
 	(ptid_t (current_event->dwProcessId,
 		 current_event->dwThreadId, 0),
 	 current_event->u.CreateProcessInfo.hThread,
@@ -1532,9 +1541,9 @@ windows_nat_target::get_windows_debug_event (int pid,
 	}
       else if (saw_create == 1)
 	{
-	  windows_delete_thread (ptid_t (current_event->dwProcessId,
-					 current_event->dwThreadId, 0),
-				 0, true /* main_thread_p */);
+	  delete_thread (ptid_t (current_event->dwProcessId,
+				 current_event->dwThreadId, 0),
+			 0, true /* main_thread_p */);
 	  DWORD exit_status = current_event->u.ExitProcess.dwExitCode;
 	  /* If the exit status looks like a fatal exception, but we
 	     don't recognize the exception's code, make the original
-- 
2.34.1


  reply	other threads:[~2022-04-07 19:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-07 19:56 [PATCH 0/2] More Windows globals cleanups Tom Tromey
2022-04-07 19:56 ` Tom Tromey [this message]
2022-04-07 19:56 ` [PATCH 2/2] Use subclasses of windows_process_info Tom Tromey
2022-06-12 16:27   ` [PATCH] Fix Cygwin build after 20489cca Jon Turney
2022-11-02 14:39     ` Jon Turney
2022-06-12 16:28   ` [PATCH 2/2] Use subclasses of windows_process_info Jon Turney
2022-06-07 18:15 ` [PATCH 0/2] More Windows globals cleanups Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220407195606.1847158-2-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).