qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Andreas Färber" <afaerber@suse.de>, liguang <lig.fnst@cn.fujitsu.com>
Subject: [Qemu-devel] [PATCH 20/20] target-i386: Use switch in check_hw_breakpoints()
Date: Tue, 15 Jan 2013 10:27:38 +0100	[thread overview]
Message-ID: <1358242058-1404-21-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1358242058-1404-1-git-send-email-afaerber@suse.de>

From: liguang <lig.fnst@cn.fujitsu.com>

Replace an if statement using magic numbers for breakpoint type with a
more explicit switch statement. This is to aid readability.

Change the return type and force_dr6_update argument type to bool.

While at it, fix Coding Style issues (missing braces).

Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 target-i386/cpu.h         |    2 +-
 target-i386/helper.c      |   44 ++++++++++++++++++++++++++++++++------------
 target-i386/misc_helper.c |    2 +-
 3 Dateien geändert, 34 Zeilen hinzugefügt(+), 14 Zeilen entfernt(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 1e850a7..4e091cd 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1043,7 +1043,7 @@ static inline int hw_breakpoint_len(unsigned long dr7, int index)
 
 void hw_breakpoint_insert(CPUX86State *env, int index);
 void hw_breakpoint_remove(CPUX86State *env, int index);
-int check_hw_breakpoints(CPUX86State *env, int force_dr6_update);
+bool check_hw_breakpoints(CPUX86State *env, bool force_dr6_update);
 void breakpoint_handler(CPUX86State *env);
 
 /* will be suppressed */
diff --git a/target-i386/helper.c b/target-i386/helper.c
index a10b562..547c25e 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1017,26 +1017,45 @@ void hw_breakpoint_remove(CPUX86State *env, int index)
     }
 }
 
-int check_hw_breakpoints(CPUX86State *env, int force_dr6_update)
+bool check_hw_breakpoints(CPUX86State *env, bool force_dr6_update)
 {
     target_ulong dr6;
-    int reg, type;
-    int hit_enabled = 0;
+    int reg;
+    bool hit_enabled = false;
 
     dr6 = env->dr[6] & ~0xf;
     for (reg = 0; reg < DR7_MAX_BP; reg++) {
-        type = hw_breakpoint_type(env->dr[7], reg);
-        if ((type == 0 && env->dr[reg] == env->eip) ||
-            ((type & 1) && env->cpu_watchpoint[reg] &&
-             (env->cpu_watchpoint[reg]->flags & BP_WATCHPOINT_HIT))) {
+        bool bp_match = false;
+        bool wp_match = false;
+
+        switch (hw_breakpoint_type(env->dr[7], reg)) {
+        case DR7_TYPE_BP_INST:
+            if (env->dr[reg] == env->eip) {
+                bp_match = true;
+            }
+            break;
+        case DR7_TYPE_DATA_WR:
+        case DR7_TYPE_DATA_RW:
+            if (env->cpu_watchpoint[reg] &&
+                env->cpu_watchpoint[reg]->flags & BP_WATCHPOINT_HIT) {
+                wp_match = true;
+            }
+            break;
+        case DR7_TYPE_IO_RW:
+            break;
+        }
+        if (bp_match || wp_match) {
             dr6 |= 1 << reg;
             if (hw_breakpoint_enabled(env->dr[7], reg)) {
-                hit_enabled = 1;
+                hit_enabled = true;
             }
         }
     }
-    if (hit_enabled || force_dr6_update)
+
+    if (hit_enabled || force_dr6_update) {
         env->dr[6] = dr6;
+    }
+
     return hit_enabled;
 }
 
@@ -1047,16 +1066,17 @@ void breakpoint_handler(CPUX86State *env)
     if (env->watchpoint_hit) {
         if (env->watchpoint_hit->flags & BP_CPU) {
             env->watchpoint_hit = NULL;
-            if (check_hw_breakpoints(env, 0))
+            if (check_hw_breakpoints(env, false)) {
                 raise_exception(env, EXCP01_DB);
-            else
+            } else {
                 cpu_resume_from_signal(env, NULL);
+            }
         }
     } else {
         QTAILQ_FOREACH(bp, &env->breakpoints, entry)
             if (bp->pc == env->eip) {
                 if (bp->flags & BP_CPU) {
-                    check_hw_breakpoints(env, 1);
+                    check_hw_breakpoints(env, true);
                     raise_exception(env, EXCP01_DB);
                 }
                 break;
diff --git a/target-i386/misc_helper.c b/target-i386/misc_helper.c
index b3f4e4f..b6d5740 100644
--- a/target-i386/misc_helper.c
+++ b/target-i386/misc_helper.c
@@ -110,7 +110,7 @@ void helper_into(CPUX86State *env, int next_eip_addend)
 void helper_single_step(CPUX86State *env)
 {
 #ifndef CONFIG_USER_ONLY
-    check_hw_breakpoints(env, 1);
+    check_hw_breakpoints(env, true);
     env->dr[6] |= DR6_BS;
 #endif
     raise_exception(env, EXCP01_DB);
-- 
1.7.10.4

  parent reply	other threads:[~2013-01-15  9:40 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-15  9:27 [Qemu-devel] [PULL] QOM CPUState patch queue 2013-01-15 Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 01/20] cpu: Move nr_{cores, threads} fields to CPUState Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 02/20] target-mips: Clean up mips_cpu_map_tc() documentation Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 03/20] cpu: Move numa_node field to CPUState Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 04/20] cpu: Move cpu_index " Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 05/20] kvm: Pass CPUState to kvm_init_vcpu() Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 06/20] xen: Simplify halting of first CPU Andreas Färber
2013-01-15 11:03   ` Stefano Stabellini
2013-01-15 14:46     ` Andreas Färber
2013-01-15 15:44       ` Stefano Stabellini
2013-01-15  9:27 ` [Qemu-devel] [PATCH 07/20] exec: Return CPUState from qemu_get_cpu() Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 08/20] kvm: Add fake KVM constants to avoid #ifdefs on KVM-specific code Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 09/20] target-i386: Disable kvm_mmu by default Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 10/20] target-i386/cpu: Introduce FeatureWord typedefs Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 11/20] target-i386: kvm_check_features_against_host(): Use feature_word_info Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 12/20] target-i386/cpu.c: Add feature name array for ext4_features Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 13/20] target-i386: check/enforce: Check all feature words Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 14/20] target-i386: Move setting defaults out of cpu_x86_parse_featurestr() Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 15/20] target-i386: cpu_x86_register() consolidate freeing resources Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 16/20] target-i386: Move kvm_check_features_against_host() check to realize time Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 17/20] target-i386: Define DR7 bit field constants Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 18/20] target-i386: Introduce hw_{local, global}_breakpoint_enabled() Andreas Färber
2013-01-15  9:27 ` [Qemu-devel] [PATCH 19/20] target-i386: Avoid goto in hw_breakpoint_insert() Andreas Färber
2013-01-15  9:27 ` Andreas Färber [this message]
2013-01-16  1:18 ` [Qemu-devel] [PULL] QOM CPUState patch queue 2013-01-15 Anthony Liguori

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=1358242058-1404-21-git-send-email-afaerber@suse.de \
    --to=afaerber@suse.de \
    --cc=lig.fnst@cn.fujitsu.com \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).