From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 40741 invoked by alias); 18 Mar 2017 17:08:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 40713 invoked by uid 89); 18 Mar 2017 17:08:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=informed X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 18 Mar 2017 17:08:06 +0000 X-ASG-Debug-ID: 1489856884-0c856e65d51913dd0001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id nMQz6IokSSmh7fYY (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 18 Mar 2017 13:08:04 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (unknown [173.246.11.162]) by smtp.electronicbox.net (Postfix) with ESMTP id D5614440EEA; Sat, 18 Mar 2017 13:08:04 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: cable-11.246.173-162.electronicbox.net[173.246.11.162] X-Barracuda-Apparent-Source-IP: 173.246.11.162 X-Barracuda-RBL-IP: 173.246.11.162 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 3/3] windows: Use ptid from regcache in register fetch/store Date: Sat, 18 Mar 2017 17:08:00 -0000 X-ASG-Orig-Subj: [PATCH 3/3] windows: Use ptid from regcache in register fetch/store Message-Id: <20170318170801.22988-3-simon.marchi@polymtl.ca> In-Reply-To: <20170318170801.22988-1-simon.marchi@polymtl.ca> References: <20170318170801.22988-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1489856884 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 5346 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.37321 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-IsSubscribed: yes X-SW-Source: 2017-03/txt/msg00328.txt.bz2 From: Simon Marchi 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/windows-nat.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 9cc755f0d4..32a9ee62cf 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]; 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,25 +533,26 @@ 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); + DWORD pid = ptid_get_tid (regcache_get_ptid (regcache)); + windows_thread_info *th = thread_rec (pid, 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 *) ¤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); } } @@ -564,11 +561,13 @@ 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); + DWORD pid = ptid_get_tid (regcache_get_ptid (regcache)); + windows_thread_info *th = thread_rec (pid, 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.12.0