From patchwork Mon Jun 25 18:55:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Brobecker X-Patchwork-Id: 28032 Received: (qmail 5192 invoked by alias); 25 Jun 2018 18:55:53 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 5075 invoked by uid 89); 25 Jun 2018 18:55:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=supplies, th X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 25 Jun 2018 18:55:50 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 526C6560D1 for ; Mon, 25 Jun 2018 14:55:49 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id zFtXC2NkWgXS for ; Mon, 25 Jun 2018 14:55:49 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 4156D560DE for ; Mon, 25 Jun 2018 14:55:49 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4233) id 404BF454; Mon, 25 Jun 2018 14:55:49 -0400 (EDT) From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [PATCH 1/2] Minor reorganization of fetch_registers/store_registers in windows-nat.c Date: Mon, 25 Jun 2018 14:55:46 -0400 Message-Id: <1529952947-48942-2-git-send-email-brobecker@adacore.com> In-Reply-To: <1529952947-48942-1-git-send-email-brobecker@adacore.com> References: <1529952947-48942-1-git-send-email-brobecker@adacore.com> This patch is a small reorganizational patch that splits do_windows_fetch_inferior_registers into two parts: (a) One part that first reloads the thread's context when needed, and then decides based on the given register number whether one register needs to be fetched or all of them. This part is moved to windows_nat_target::fetch_registers. (b) The rest of the code, which actually fetches the register value and supplies it to the regcache. A similar treatment is applied to do_windows_store_inferior_registers. This change is preparation work for changing the way we calculate the location of a given register in the thread context structure, and should be a no op. gdb/ChangeLog: * windows-nat.c (do_windows_fetch_inferior_registers): Rename to windows_fetch_one_register, and only handle the case of fetching one register. Move the code that reloads the context and iterates over all registers if R is negative to... (windows_nat_target::fetch_registers): ... here. (do_windows_store_inferior_registers): Rename to windows_store_one_register, and only handle the case of storing one register. Move the code that handles the case where r is negative to... (windows_nat_target::store_registers) ... here. Tested on x86-windows and x86_64-windows using AdaCore's testsuite. --- gdb/windows-nat.c | 115 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 50 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 620e25c..c51ef8f 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -528,14 +528,59 @@ windows_delete_thread (const ptid_t &ptid, DWORD exit_code) } } +/* Fetches register number R from the given windows_thread_info, + and supplies its value to the given regcache. + + This function assumes that R is either null or positive. A failed + assertion is raised if that is not true. + + This function assumes that TH->RELOAD_CONTEXT is not set, meaning + that the windows_thread_info has an up-to-date context. A failed + assertion is raised if that assumption is violated. */ + static void -do_windows_fetch_inferior_registers (struct regcache *regcache, - windows_thread_info *th, int r) +windows_fetch_one_register (struct regcache *regcache, + windows_thread_info *th, int r) { + gdb_assert (r >= 0); + gdb_assert (!th->reload_context); + char *context_offset = ((char *) &th->context) + mappings[r]; struct gdbarch *gdbarch = regcache->arch (); struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); - long l; + + if (r == I387_FISEG_REGNUM (tdep)) + { + long l = *((long *) context_offset) & 0xffff; + regcache->raw_supply (r, (char *) &l); + } + else if (r == I387_FOP_REGNUM (tdep)) + { + long l = (*((long *) context_offset) >> 16) & ((1 << 11) - 1); + regcache->raw_supply (r, (char *) &l); + } + else if (segment_register_p (r)) + { + /* GDB treats segment registers as 32bit registers, but they are + in fact only 16 bits long. Make sure we do not read extra + bits from our source buffer. */ + long l = *((long *) context_offset) & 0xffff; + regcache->raw_supply (r, (char *) &l); + } + else + regcache->raw_supply (r, context_offset); +} + +void +windows_nat_target::fetch_registers (struct regcache *regcache, int r) +{ + DWORD pid = ptid_get_tid (regcache->ptid ()); + windows_thread_info *th = thread_rec (pid, TRUE); + + /* Check if TH exists. Windows sometimes uses a non-existent + thread id in its events. */ + if (th == NULL) + return; if (th->reload_context) { @@ -571,56 +616,20 @@ do_windows_fetch_inferior_registers (struct regcache *regcache, th->reload_context = 0; } - if (r == I387_FISEG_REGNUM (tdep)) - { - l = *((long *) context_offset) & 0xffff; - regcache->raw_supply (r, (char *) &l); - } - else if (r == I387_FOP_REGNUM (tdep)) - { - l = (*((long *) context_offset) >> 16) & ((1 << 11) - 1); - regcache->raw_supply (r, (char *) &l); - } - else if (segment_register_p (r)) - { - /* GDB treats segment registers as 32bit registers, but they are - in fact only 16 bits long. Make sure we do not read extra - bits from our source buffer. */ - l = *((long *) context_offset) & 0xffff; - regcache->raw_supply (r, (char *) &l); - } - else if (r >= 0) - regcache->raw_supply (r, context_offset); + if (r < 0) + for (r = 0; r < gdbarch_num_regs (regcache->arch()); r++) + windows_fetch_one_register (regcache, th, r); else - { - for (r = 0; r < gdbarch_num_regs (gdbarch); r++) - do_windows_fetch_inferior_registers (regcache, th, r); - } -} - -void -windows_nat_target::fetch_registers (struct regcache *regcache, int r) -{ - DWORD pid = ptid_get_tid (regcache->ptid ()); - windows_thread_info *th = thread_rec (pid, TRUE); - - /* Check if TH exists. Windows sometimes uses a non-existent - thread id in its events. */ - if (th != NULL) - do_windows_fetch_inferior_registers (regcache, th, r); + windows_fetch_one_register (regcache, th, r); } static void -do_windows_store_inferior_registers (const struct regcache *regcache, - windows_thread_info *th, int r) +windows_store_one_register (const struct regcache *regcache, + windows_thread_info *th, int r) { - if (r >= 0) - regcache->raw_collect (r, ((char *) &th->context) + mappings[r]); - else - { - for (r = 0; r < gdbarch_num_regs (regcache->arch ()); r++) - do_windows_store_inferior_registers (regcache, th, r); - } + gdb_assert (r >= 0); + + regcache->raw_collect (r, ((char *) &th->context) + mappings[r]); } /* Store a new register value into the context of the thread tied to @@ -634,8 +643,14 @@ windows_nat_target::store_registers (struct regcache *regcache, int r) /* Check if TH exists. Windows sometimes uses a non-existent thread id in its events. */ - if (th != NULL) - do_windows_store_inferior_registers (regcache, th, r); + if (th == NULL) + return; + + if (r < 0) + for (r = 0; r < gdbarch_num_regs (regcache->arch ()); r++) + windows_store_one_register (regcache, th, r); + else + windows_store_one_register (regcache, th, r); } /* Encapsulate the information required in a call to