[24/34] Add backpointer from windows_thread_info to windows_process_info

Message ID 20240507234233.371123-25-pedro@palves.net
State New
Headers
Series Windows non-stop mode |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Pedro Alves May 7, 2024, 11:42 p.m. UTC
  The next patch will move some duplicated code in gdb and gdbserver to
gdb/nat/windows-nat.c, where it would be convenient to get at the
Windows process info of a given Windows thread info, from within a
windows_thread_info method.

I first thought of passing down the windows_process_info pointer as
argument to the windows_thread_info method, but that looked a bit odd.
I think it looks better to just add a back pointer, so that's what
this patch does.  The following patch will then add a use of it.

I suspect this will help moving more duplicated code to
gdb/nat/windows-nat.c in the future, too.

Change-Id: I47fc0d3323be5b6f6fcfe912b768051a41910666
---
 gdb/nat/windows-nat.h  | 10 ++++++++--
 gdb/windows-nat.c      |  2 +-
 gdbserver/win32-low.cc |  2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)
  

Comments

Tom Tromey May 8, 2024, 3:28 p.m. UTC | #1
>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:

Pedro> The next patch will move some duplicated code in gdb and gdbserver to
Pedro> gdb/nat/windows-nat.c, where it would be convenient to get at the
Pedro> Windows process info of a given Windows thread info, from within a
Pedro> windows_thread_info method.

Pedro> I first thought of passing down the windows_process_info pointer as
Pedro> argument to the windows_thread_info method, but that looked a bit odd.
Pedro> I think it looks better to just add a back pointer, so that's what
Pedro> this patch does.  The following patch will then add a use of it.

Pedro> I suspect this will help moving more duplicated code to
Pedro> gdb/nat/windows-nat.c in the future, too.

I generally dislike back-pointers but on the whole this seems fine to me.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
index 86ad8d02e3c..26b1eaea95a 100644
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -42,13 +42,16 @@  struct pending_stop
   target_waitstatus status;
 };
 
+struct windows_process_info;
 
 /* Thread information structure used to track extra information about
    each thread.  */
 struct windows_thread_info
 {
-  windows_thread_info (DWORD tid_, HANDLE h_, CORE_ADDR tlb)
-    : tid (tid_),
+  windows_thread_info (windows_process_info *proc_,
+		       DWORD tid_, HANDLE h_, CORE_ADDR tlb)
+    : proc (proc_),
+      tid (tid_),
       h (h_),
       thread_local_base (tlb)
   {
@@ -67,6 +70,9 @@  struct windows_thread_info
      the next call.  */
   const char *thread_name ();
 
+  /* The process this thread belongs to.  */
+  windows_process_info *proc;
+
   /* The Win32 thread identifier.  */
   DWORD tid;
 
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 510820d862d..0e77614b4f4 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -612,7 +612,7 @@  windows_nat_target::add_thread (ptid_t ptid, HANDLE h, void *tlb,
   if (windows_process.wow64_process)
     base += 0x2000;
 #endif
-  th = new windows_thread_info (ptid.lwp (), h, base);
+  th = new windows_thread_info (&windows_process, ptid.lwp (), h, base);
   windows_process.thread_list.emplace_back (th);
 
   /* Add this new thread to the list of threads.
diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc
index 55600910ffe..985c6a0a0ed 100644
--- a/gdbserver/win32-low.cc
+++ b/gdbserver/win32-low.cc
@@ -167,7 +167,7 @@  child_add_thread (DWORD pid, DWORD tid, HANDLE h, void *tlb)
   if (windows_process.wow64_process)
     base += 2 * 4096; /* page size = 4096 */
 #endif
-  th = new windows_thread_info (tid, h, base);
+  th = new windows_thread_info (&windows_process, tid, h, base);
 
   add_thread (ptid, th);