From patchwork Wed Sep 3 11:42:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 2637 Received: (qmail 3694 invoked by alias); 3 Sep 2014 11:42:44 -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 3675 invoked by uid 89); 3 Sep 2014 11:42:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 03 Sep 2014 11:42:38 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s83BgbJi023112 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 3 Sep 2014 07:42:37 -0400 Received: from blade.nx (ovpn-116-48.ams2.redhat.com [10.36.116.48]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s83BgaPp008167 for ; Wed, 3 Sep 2014 07:42:36 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 9C7A82640E1 for ; Wed, 3 Sep 2014 12:42:35 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Subject: [OB PATCH] x86 debug address register clarifications Date: Wed, 3 Sep 2014 12:42:35 +0100 Message-Id: <1409744555-21096-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes Hi all, The loop macro ALL_DEBUG_REGISTERS does not iterate over the status or control registers, so its name is misleading. This commit renames it as ALL_DEBUG_ADDRESS_REGISTERS and updates all uses. This commit also updates its loop conditions to an equivalent but better form, and makes two functions use it that had previously hardwired the loop. A comment on a related field in the x86_debug_reg_state structure is also updated to reflect that the field refers specifically to address registers only. Pushed as obvious. Thanks, Gary --- gdb/ChangeLog: * nat/x86-dregs.h (ALL_DEBUG_REGISTERS): Renamed as... (ALL_DEBUG_ADDRESS_REGISTERS): New macro. All uses updated. Loop conditions changed to equivalent form. (struct x86_debug_reg_state): Updated dr_ref_count comment. * x86-linux-nat.c (x86_linux_prepare_to_resume): Use ALL_DEBUG_ADDRESS_REGISTERS. gdb/gdbserver/ChangeLog: * linux-x86-low.c (x86_linux_prepare_to_resume): Use ALL_DEBUG_ADDRESS_REGISTERS. --- gdb/ChangeLog | 9 +++++++++ gdb/gdbserver/ChangeLog | 5 +++++ gdb/gdbserver/linux-x86-low.c | 2 +- gdb/gdbserver/x86-low.c | 2 +- gdb/nat/x86-dregs.c | 12 ++++++------ gdb/nat/x86-dregs.h | 7 ++++--- gdb/x86-linux-nat.c | 2 +- 7 files changed, 27 insertions(+), 12 deletions(-) diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c index 6b73886..a66f61e 100644 --- a/gdb/gdbserver/linux-x86-low.c +++ b/gdb/gdbserver/linux-x86-low.c @@ -787,7 +787,7 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp) x86_linux_dr_set (ptid, DR_CONTROL, 0); - for (i = DR_FIRSTADDR; i <= DR_LASTADDR; i++) + ALL_DEBUG_ADDRESS_REGISTERS (i) if (state->dr_ref_count[i] > 0) { x86_linux_dr_set (ptid, i, state->dr_mirror[i]); diff --git a/gdb/gdbserver/x86-low.c b/gdb/gdbserver/x86-low.c index aaa110e..b48a15d 100644 --- a/gdb/gdbserver/x86-low.c +++ b/gdb/gdbserver/x86-low.c @@ -28,7 +28,7 @@ x86_low_init_dregs (struct x86_debug_reg_state *state) { int i; - ALL_DEBUG_REGISTERS (i) + ALL_DEBUG_ADDRESS_REGISTERS (i) { state->dr_mirror[i] = 0; state->dr_ref_count[i] = 0; diff --git a/gdb/nat/x86-dregs.c b/gdb/nat/x86-dregs.c index 5381c77..fbb2426 100644 --- a/gdb/nat/x86-dregs.c +++ b/gdb/nat/x86-dregs.c @@ -205,7 +205,7 @@ x86_show_dr (struct x86_debug_reg_state *state, debug_printf ("\tCONTROL (DR7): %s STATUS (DR6): %s\n", phex (state->dr_control_mirror, 8), phex (state->dr_status_mirror, 8)); - ALL_DEBUG_REGISTERS (i) + ALL_DEBUG_ADDRESS_REGISTERS (i) { debug_printf ("\ \tDR%d: addr=0x%s, ref.count=%d DR%d: addr=0x%s, ref.count=%d\n", @@ -291,7 +291,7 @@ x86_insert_aligned_watchpoint (struct x86_debug_reg_state *state, /* First, look for an occupied debug register with the same address and the same RW and LEN definitions. If we find one, we can reuse it for this watchpoint as well (and save a register). */ - ALL_DEBUG_REGISTERS (i) + ALL_DEBUG_ADDRESS_REGISTERS (i) { if (!X86_DR_VACANT (state, i) && state->dr_mirror[i] == addr @@ -303,7 +303,7 @@ x86_insert_aligned_watchpoint (struct x86_debug_reg_state *state, } /* Next, look for a vacant debug register. */ - ALL_DEBUG_REGISTERS (i) + ALL_DEBUG_ADDRESS_REGISTERS (i) { if (X86_DR_VACANT (state, i)) break; @@ -346,7 +346,7 @@ x86_remove_aligned_watchpoint (struct x86_debug_reg_state *state, int i, retval = -1; int all_vacant = 1; - ALL_DEBUG_REGISTERS (i) + ALL_DEBUG_ADDRESS_REGISTERS (i) { if (!X86_DR_VACANT (state, i) && state->dr_mirror[i] == addr @@ -461,7 +461,7 @@ x86_update_inferior_debug_regs (struct x86_debug_reg_state *state, { int i; - ALL_DEBUG_REGISTERS (i) + ALL_DEBUG_ADDRESS_REGISTERS (i) { if (X86_DR_VACANT (new_state, i) != X86_DR_VACANT (state, i)) x86_dr_low_set_addr (new_state, i); @@ -620,7 +620,7 @@ x86_dr_stopped_data_address (struct x86_debug_reg_state *state, registers. */ status = x86_dr_low_get_status (); - ALL_DEBUG_REGISTERS (i) + ALL_DEBUG_ADDRESS_REGISTERS (i) { if (!X86_DR_WATCH_HIT (status, i)) continue; diff --git a/gdb/nat/x86-dregs.h b/gdb/nat/x86-dregs.h index fb179a5..aebcbce 100644 --- a/gdb/nat/x86-dregs.h +++ b/gdb/nat/x86-dregs.h @@ -85,12 +85,13 @@ struct x86_debug_reg_state CORE_ADDR dr_mirror[DR_NADDR]; unsigned dr_status_mirror, dr_control_mirror; - /* Reference counts for each debug register. */ + /* Reference counts for each debug address register. */ int dr_ref_count[DR_NADDR]; }; -/* A macro to loop over all debug registers. */ -#define ALL_DEBUG_REGISTERS(i) for (i = 0; i < DR_NADDR; i++) +/* A macro to loop over all debug address registers. */ +#define ALL_DEBUG_ADDRESS_REGISTERS(i) \ + for (i = DR_FIRSTADDR; i <= DR_LASTADDR; i++) /* Insert a watchpoint to watch a memory region which starts at address ADDR and whose length is LEN bytes. Watch memory accesses diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c index 5340dfe..0d070dd 100644 --- a/gdb/x86-linux-nat.c +++ b/gdb/x86-linux-nat.c @@ -195,7 +195,7 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp) results in EINVAL. */ x86_linux_dr_set (lwp->ptid, DR_CONTROL, 0); - for (i = DR_FIRSTADDR; i <= DR_LASTADDR; i++) + ALL_DEBUG_ADDRESS_REGISTERS (i) if (state->dr_ref_count[i] > 0) { x86_linux_dr_set (lwp->ptid, i, state->dr_mirror[i]);