[Lldb-commits] [lldb] r151333 - in /lldb/trunk/tools/debugserver/source/MacOSX/arm: DNBArchImpl.cpp DNBArchImpl.h

Johnny Chen johnny.chen at apple.com
Thu Feb 23 17:50:42 PST 2012


Author: johnny
Date: Thu Feb 23 19:50:42 2012
New Revision: 151333

URL: http://llvm.org/viewvc/llvm-project?rev=151333&view=rev
Log:
Add a class method HasWatchpointOccurred() to inspect the "method of debug entry" field
of the DSCR to check whether it was because of watchpoint occurred.

Modified:
    lldb/trunk/tools/debugserver/source/MacOSX/arm/DNBArchImpl.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/arm/DNBArchImpl.h

Modified: lldb/trunk/tools/debugserver/source/MacOSX/arm/DNBArchImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/arm/DNBArchImpl.cpp?rev=151333&r1=151332&r2=151333&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/arm/DNBArchImpl.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/arm/DNBArchImpl.cpp Thu Feb 23 19:50:42 2012
@@ -56,6 +56,10 @@
 #define WCR_LOAD                ((uint32_t)(1u << 3))
 #define WCR_STORE               ((uint32_t)(1u << 4))
 
+// Definitions for the Debug Status and Control Register fields:
+// [5:2] => Method of debug entry
+#define WATCHPOINT_OCCURRED     ((uint32_t)(2u))
+
 //#define DNB_ARCH_MACH_ARM_DEBUG_SW_STEP 1
 
 static const uint8_t g_arm_breakpoint_opcode[] = { 0xFE, 0xDE, 0xFF, 0xE7 };
@@ -342,6 +346,13 @@
             SetSingleStepSoftwareBreakpoints();
         }
     }
+
+    // Reset the method of debug entry field of the DSCR, if necessary, before we resume.
+    if (HasWatchpointOccurred())
+    {
+        ClearWatchpointOccurred();
+        DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchMachARM::ThreadWillResume() ClearWatchpointOccurred() called");
+    }
 }
 
 bool
@@ -461,6 +472,8 @@
                 //
                 // Check whether this corresponds to a watchpoint hit event.
                 // If yes, set the exc_sub_code to the data break address.
+                if (!HasWatchpointOccurred())
+                    break;
                 nub_addr_t addr = 0;
                 uint32_t hw_index = GetHardwareWatchpointHit(addr);
                 if (hw_index != INVALID_NUB_HW_INDEX)
@@ -2405,7 +2418,7 @@
         if (hw_index < num_hw_points)
         {
             m_state.dbg.__wcr[hw_index] = 0;
-            DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchMachARM::ClearHardwareWatchpoint( %u ) - WVR%u = 0x%8.8x  WCR%u = 0x%8.8x",
+            DNBLogThreadedIf(LOG_WATCHPOINTS, "DNBArchMachARM::DisableHardwareWatchpoint( %u ) - WVR%u = 0x%8.8x  WCR%u = 0x%8.8x",
                     hw_index,
                     hw_index,
                     m_state.dbg.__wvr[hw_index],
@@ -2435,7 +2448,7 @@
     Valid_Global_Debug_State = true;
 }
 
-// Iterate through the debug status register; return the index of the first hit.
+// Iterate through the debug registers; return the index of the first hit.
 uint32_t
 DNBArchMachARM::GetHardwareWatchpointHit(nub_addr_t &addr)
 {
@@ -2475,7 +2488,7 @@
     // See also IsWatchpointHit().
     uint32_t register_DBGDSCR;
     asm("mrc p14, 0, %0, c0, c1, 0" : "=r" (register_DBGDSCR));
-    if (bits(register_DBGDSCR, 5, 2) == 0x2)
+    if (bits(register_DBGDSCR, 5, 2) == WATCHPOINT_OCCURRED)
     {
         uint32_t mask = ~(0xF << 2);
         register_DBGDSCR &= mask;
@@ -2484,6 +2497,20 @@
     return;
 }
 
+// NotifyException() calls this to double check that a watchpoint has occurred
+// by inspecting the bits[5:2] field of the Debug Status and Control Register
+// (DSCR).
+// 
+// b0010 = a watchpoint occurred
+bool
+DNBArchMachARM::HasWatchpointOccurred()
+{
+    // See also IsWatchpointHit().
+    uint32_t register_DBGDSCR;
+    asm("mrc p14, 0, %0, c0, c1, 0" : "=r" (register_DBGDSCR));
+    return (bits(register_DBGDSCR, 5, 2) == WATCHPOINT_OCCURRED);
+}
+
 // FIXME: IsWatchpointHit() currently returns the first enabled watchpoint,
 //        instead of finding the watchpoint that actually triggered.
 bool
@@ -2492,7 +2519,7 @@
     // Watchpoint Control Registers, bitfield definitions
     // ...
     // Bits    Value    Description
-    // [0]	   0        Watchpoint disabled
+    // [0]     0        Watchpoint disabled
     //         1        Watchpoint enabled.
     return (debug_state.__wcr[hw_index] & 1u);
 }

Modified: lldb/trunk/tools/debugserver/source/MacOSX/arm/DNBArchImpl.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/arm/DNBArchImpl.h?rev=151333&r1=151332&r2=151333&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/arm/DNBArchImpl.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/arm/DNBArchImpl.h Thu Feb 23 19:50:42 2012
@@ -238,6 +238,7 @@
 
     // Helper functions for watchpoint implementaions.
     static void ClearWatchpointOccurred();
+    static bool HasWatchpointOccurred();
     static bool IsWatchpointHit(const DBG &debug_state, uint32_t hw_index);
     static nub_addr_t GetWatchAddress(const DBG &debug_state, uint32_t hw_index);
 





More information about the lldb-commits mailing list