This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[pushed] windows: Use ptid from regcache in register fetch/store
- From: Simon Marchi <simon dot marchi at ericsson dot com>
- To: <gdb-patches at sourceware dot org>
- Cc: Simon Marchi <simon dot marchi at ericsson dot com>
- Date: Tue, 21 Mar 2017 11:38:41 -0400
- Subject: [pushed] windows: Use ptid from regcache in register fetch/store
- Authentication-results: sourceware.org; auth=none
- Authentication-results: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=ericsson.com;
- References: <ac195899359bd96fffd646517cedfbb5@polymtl.ca>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
Use the ptid from the regcache so we don't depend on the current value
of the inferior_ptid global.
Also, change how the current thread is passed to sub-functions. The
windows_fetch_inferior_registers function sets current_thread then calls
do_windows_fetch_inferior_registers, which reads current_thread. This
very much looks like passing a parameter through a global variable. I
think it would be more straightforward to pass the thread as a
parameter.
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. Use
ptid from regcache instead of inferior_ptid.
(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. Use
ptid from regcache instead of inferior_ptid.
---
gdb/ChangeLog | 14 ++++++++++++++
gdb/windows-nat.c | 52 ++++++++++++++++++++++++++--------------------------
2 files changed, 40 insertions(+), 26 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 537e5beabc..aebfb75583 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,19 @@
2017-03-21 Simon Marchi <simon.marchi@ericsson.com>
+ * 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. Use
+ ptid from regcache instead of inferior_ptid.
+ (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. Use
+ ptid from regcache instead of inferior_ptid.
+
+2017-03-21 Simon Marchi <simon.marchi@ericsson.com>
+
* ser-mingw.c (ser_windows_raw): Remove reference to
struct serial::current_timeout.
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 9cc755f0d4..76313db989 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 *) ¤t_thread->context) + mappings[r];
+ char *context_offset = ((char *) &th->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 (¤t_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,38 +533,42 @@ 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);
- /* Check if current_thread exists. Windows sometimes uses a non-existent
+ DWORD pid = ptid_get_tid (regcache_get_ptid (regcache));
+ windows_thread_info *th = thread_rec (pid, TRUE);
+
+ /* Check if TH 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 *) ¤t_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);
}
}
-/* Store a new register value into the current thread context. */
+/* Store a new register value into the context of the thread tied to
+ REGCACHE. */
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);
- /* Check if current_thread exists. Windows sometimes uses a non-existent
+ DWORD pid = ptid_get_tid (regcache_get_ptid (regcache));
+ windows_thread_info *th = thread_rec (pid, TRUE);
+
+ /* Check if TH 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