Skip to contentSkip to conversation

target-arm: implement architectural breakpoints

PATCH New Peter Maydell 1 participant 3 messages Sep 12, 2014

lore
Share & tools
lore
#0 lore raw

cover target-arm: implement architectural breakpoints

Implement support for the ARM architecturally mandated hardware breakpoints, for ARMv8 and ARMv7. Tested that hardware bps work for both v7 and v8 kernels (including v8 compat userspace in a 32 bit kernel).

There are a few odd subfeatures which we don't implement (yet):
* address-mismatch breakpoints which fire if the PC is anything other than the specified value
* address-mismatch breakpoints with zero byte-address-select, which fire for every single instruction execution
* unlinked context match breakpoints, which fire for every instruction executed with a particular value of CONTEXTIDR/VMID

These aren't used by Linux's ptrace support, and I wasn't sure of the best way to implement them, so for now they just produce a LOG_UNIMP warning if the guest tries to use them.

This patchset sits on target-arm.next (ie after the watchpoint code).

Peter Maydell (2):
target-arm: Implement setting guest breakpoints
target-arm: Implement handling of breakpoint firing

 target-arm/cpu.c       |   1 +
 target-arm/cpu.h       |   1 +
 target-arm/helper.c    | 126 ++++++++++++++++++++++++++++++++++++++++++++++++-
 target-arm/internals.h |  15 ++++++
 target-arm/machine.c   |   1 +
 target-arm/op_helper.c |  75 +++++++++++++++++++++++------
 6 files changed, 202 insertions(+), 17 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 target-arm: Implement setting guest breakpoints

This patch adds support for setting guest breakpoints based on values the guest writes to the DBGBVR and DBGBCR registers. (It doesn't include the code to handle when these breakpoints fire, so has no guest-visible effect.)

---
 target-arm/cpu.c       |   1 +
 target-arm/cpu.h       |   1 +
 target-arm/helper.c    | 126 ++++++++++++++++++++++++++++++++++++++++++++++++-
 target-arm/internals.h |   9 ++++
 target-arm/machine.c   |   1 +
 5 files changed, 136 insertions(+), 2 deletions(-)
target-arm/cpu.c +1 -0
index 7ea12bd..5b5531a 100644
@@ -185,6 +185,7 @@ static void arm_cpu_reset(CPUState *s)
     }
 #endif
 
+    hw_breakpoint_update_all(cpu);
     hw_watchpoint_update_all(cpu);
 }
 
target-arm/cpu.h +1 -0
index d1e1ccb..fa6ae0a 100644
@@ -323,6 +323,7 @@ typedef struct CPUARMState {
     int eabi;
 #endif
 
+    struct CPUBreakpoint *cpu_breakpoint[16];
     struct CPUWatchpoint *cpu_watchpoint[16];
 
     CPU_COMMON
target-arm/helper.c +124 -2

141 lines not on this page · raw message

target-arm/internals.h +9 -0
index 64751a0..b7e4822 100644
@@ -322,6 +322,15 @@ void hw_watchpoint_update(ARMCPU *cpu, int n);
  * suitable for use after migration or on reset.
  */
 void hw_watchpoint_update_all(ARMCPU *cpu);
+/* Update a QEMU breakpoint based on the information the guest has set in the
+ * DBGBCR<n>_EL1 and DBGBVR<n>_EL1 registers.
+ */
+void hw_breakpoint_update(ARMCPU *cpu, int n);
+/* Update the QEMU breakpoints for every guest breakpoint. This does a
+ * complete delete-and-reinstate of the QEMU breakpoint list and so is
+ * suitable for use after migration or on reset.
+ */
+void hw_breakpoint_update_all(ARMCPU *cpu);
 
 /* Callback function for when a watchpoint or breakpoint triggers. */
 void arm_debug_excp_handler(CPUState *cs);
target-arm/machine.c +1 -0
index 8dfe87c..ddb7d05 100644
@@ -214,6 +214,7 @@ static int cpu_post_load(void *opaque, int version_id)
         }
     }
 
+    hw_breakpoint_update_all(cpu);
     hw_watchpoint_update_all(cpu);
 
     return 0;
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/2 target-arm: Implement handling of breakpoint firing

In reply to Peter Maydell

Implement handling of breakpoint event firing to correctly inject the debug exception into the guest.

Since the breakpoint and watchpoint control register format is very similar we adjust wp_matches() to also handle breakpoints as well rather than using a separate function.

---
 target-arm/internals.h |  6 ++++
 target-arm/op_helper.c | 75 ++++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 66 insertions(+), 15 deletions(-)
target-arm/internals.h +6 -0
index b7e4822..986a7b1 100644
@@ -313,6 +313,12 @@ static inline uint32_t syn_watchpoint(int same_el, int cm, int wnr)
         | (cm << 8) | (wnr << 6) | 0x22;
 }
 
+static inline uint32_t syn_breakpoint(int same_el)
+{
+    return (EC_BREAKPOINT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
+        | ARM_EL_IL | 0x22;
+}
+
 /* Update a QEMU watchpoint based on the information the guest has set in the
  * DBGWCR<n>_EL1 and DBGWVR<n>_EL1 registers.
  */
target-arm/op_helper.c +60 -15

119 lines not on this page · raw message

Signature · 1 line
1.9.1