Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH 1/7] windows: Don't use current_thread for register fetch/store
Date: Wed, 08 Mar 2017 16:42:00 -0000	[thread overview]
Message-ID: <20170308164140.7281-2-simon.marchi@ericsson.com> (raw)
In-Reply-To: <20170308164140.7281-1-simon.marchi@ericsson.com>

The windows_fetch_inferior_registers function sets current_thread then
calls do_windows_fetch_inferior_registers, which reads current_thread.
Instead of passing a parameter indirectly through a global variable,
this patch makes the code pass the thread as a parameter.

It will fit better with the following patches, which will pass a ptid to
the register fetch/store target methods.

I don't have access to a Windows development environment, so I couldn't
even build-test this.  Could somebody try it to make sure it doesn't
break everything?

gdb/ChangeLog:

	* windows-nat.c (do_windows_fetch_inferior_registers): Add
	windows_thread_info parameter and use it instead of
	current_thread.
	(windows_fetch_inferior_registers): Don't set current_thread,
	pass the thread to do_windows_fetch_inferior_registers.
	(do_windows_store_inferior_registers): Add windows_thread_info
	parameter and use it instead of current_thread.
	(windows_store_inferior_registers): Don't set current_thread,
	pass the thread to do_windows_store_inferior_registers.
---
 gdb/windows-nat.c | 41 +++++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 9cc755f0d4..a177b38ea3 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -460,18 +460,15 @@ windows_delete_thread (ptid_t ptid, DWORD exit_code)
 }
 
 static void
-do_windows_fetch_inferior_registers (struct regcache *regcache, int r)
+do_windows_fetch_inferior_registers (struct regcache *regcache,
+				     windows_thread_info *th, int r)
 {
   char *context_offset = ((char *) &current_thread->context) + mappings[r];
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
   long l;
 
-  if (!current_thread)
-    return;	/* Windows sometimes uses a non-existent thread id in its
-		   events.  */
-
-  if (current_thread->reload_context)
+  if (th->reload_context)
     {
 #ifdef __CYGWIN__
       if (have_saved_context)
@@ -480,14 +477,13 @@ do_windows_fetch_inferior_registers (struct regcache *regcache, int r)
 	     cygwin has informed us that we should consider the signal
 	     to have occurred at another location which is stored in
 	     "saved_context.  */
-	  memcpy (&current_thread->context, &saved_context,
+	  memcpy (&th->context, &saved_context,
 		  __COPY_CONTEXT_SIZE);
 	  have_saved_context = 0;
 	}
       else
 #endif
 	{
-	  windows_thread_info *th = current_thread;
 	  th->context.ContextFlags = CONTEXT_DEBUGGER_DR;
 	  CHECK (GetThreadContext (th->h, &th->context));
 	  /* Copy dr values from that thread.
@@ -503,7 +499,7 @@ do_windows_fetch_inferior_registers (struct regcache *regcache, int r)
 	      dr[7] = th->context.Dr7;
 	    }
 	}
-      current_thread->reload_context = 0;
+      th->reload_context = 0;
     }
 
   if (r == I387_FISEG_REGNUM (tdep))
@@ -529,7 +525,7 @@ do_windows_fetch_inferior_registers (struct regcache *regcache, int r)
   else
     {
       for (r = 0; r < gdbarch_num_regs (gdbarch); r++)
-	do_windows_fetch_inferior_registers (regcache, r);
+	do_windows_fetch_inferior_registers (regcache, th, r);
     }
 }
 
@@ -537,25 +533,25 @@ static void
 windows_fetch_inferior_registers (struct target_ops *ops,
 				  struct regcache *regcache, int r)
 {
-  current_thread = thread_rec (ptid_get_tid (inferior_ptid), TRUE);
+  windows_thread_info *th = thread_rec (ptid_get_tid (inferior_ptid), TRUE);
+
   /* Check if current_thread exists.  Windows sometimes uses a non-existent
      thread id in its events.  */
-  if (current_thread)
-    do_windows_fetch_inferior_registers (regcache, r);
+  if (th != NULL)
+    do_windows_fetch_inferior_registers (regcache, th, r);
 }
 
 static void
-do_windows_store_inferior_registers (const struct regcache *regcache, int r)
+do_windows_store_inferior_registers (const struct regcache *regcache,
+				     windows_thread_info *th, int r)
 {
-  if (!current_thread)
-    /* Windows sometimes uses a non-existent thread id in its events.  */;
-  else if (r >= 0)
+  if (r >= 0)
     regcache_raw_collect (regcache, r,
-			  ((char *) &current_thread->context) + mappings[r]);
+			  ((char *) &th->context) + mappings[r]);
   else
     {
       for (r = 0; r < gdbarch_num_regs (get_regcache_arch (regcache)); r++)
-	do_windows_store_inferior_registers (regcache, r);
+	do_windows_store_inferior_registers (regcache, th, r);
     }
 }
 
@@ -564,11 +560,12 @@ static void
 windows_store_inferior_registers (struct target_ops *ops,
 				  struct regcache *regcache, int r)
 {
-  current_thread = thread_rec (ptid_get_tid (inferior_ptid), TRUE);
+  windows_thread_info *th = thread_rec (ptid_get_tid (inferior_ptid), TRUE);
+
   /* Check if current_thread exists.  Windows sometimes uses a non-existent
      thread id in its events.  */
-  if (current_thread)
-    do_windows_store_inferior_registers (regcache, r);
+  if (th != NULL)
+    do_windows_store_inferior_registers (regcache, th, r);
 }
 
 /* Encapsulate the information required in a call to
-- 
2.11.0


  parent reply	other threads:[~2017-03-08 16:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-08 16:42 [PATCH 0/7] Pass ptid to target_ops register methods Simon Marchi
2017-03-08 16:42 ` [PATCH 2/7] Add overload of s390_inferior_tid with a parameter Simon Marchi
2017-03-08 16:42 ` [PATCH 7/7] Pass ptid to to_prepare_to_store Simon Marchi
2017-03-08 16:42 ` [PATCH 5/7] Pass ptid to target_fetch_registers Simon Marchi
2017-03-08 21:08   ` Simon Marchi
2017-03-08 16:42 ` [PATCH 3/7] Define and use typedefs for bsd_uthread_ops fields Simon Marchi
2017-03-08 16:42 ` Simon Marchi [this message]
2017-03-08 16:42 ` [PATCH 6/7] Pass ptid to target_store_registers Simon Marchi
2017-03-08 16:42 ` [PATCH 4/7] Pass down ptid in bsd_uthread_ops layer Simon Marchi
2017-03-08 17:03 ` [PATCH 0/7] Pass ptid to target_ops register methods Simon Marchi
2017-03-08 23:31 ` Pedro Alves
2017-03-10 16:06   ` Simon Marchi
2017-03-10 17:12     ` Ulrich Weigand
2017-03-10 17:51       ` Simon Marchi

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=20170308164140.7281-2-simon.marchi@ericsson.com \
    --to=simon.marchi@ericsson.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