[Lldb-commits] [lldb] [lldb][Windows] WoA HW Break and Watchpoint support in LLDB (PR #108072)

Omair Javaid via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 11 02:33:16 PDT 2024


================
@@ -491,24 +491,47 @@ NativeProcessWindows::OnDebugException(bool first_chance,
     return ExceptionResult::MaskException;
   }
   case DWORD(STATUS_BREAKPOINT):
-  case STATUS_WX86_BREAKPOINT:
-    if (FindSoftwareBreakpoint(record.GetExceptionAddress())) {
-      LLDB_LOG(log, "Hit non-loader breakpoint at address {0:x}.",
-               record.GetExceptionAddress());
-
-      StopThread(record.GetThreadID(), StopReason::eStopReasonBreakpoint);
-
-      if (NativeThreadWindows *stop_thread =
-              GetThreadByID(record.GetThreadID())) {
-        auto &register_context = stop_thread->GetRegisterContext();
+  case STATUS_WX86_BREAKPOINT: {
+    bool breakpoint_hit = false;
+    NativeThreadWindows *stop_thread = GetThreadByID(record.GetThreadID());
+
+    if (stop_thread) {
+      uint32_t hw_id = LLDB_INVALID_INDEX32;
+      auto &reg_ctx = stop_thread->GetRegisterContext();
+      reg_ctx.GetHardwareBreakHitIndex(hw_id, record.GetExceptionAddress());
+      if (hw_id != LLDB_INVALID_INDEX32) {
+        breakpoint_hit = true;
+        LLDB_LOG(log, "Hit hardware breakpoint at address {0:x}.",
+                 record.GetExceptionAddress());
+      } else if (FindSoftwareBreakpoint(record.GetExceptionAddress())) {
+        breakpoint_hit = true;
+        LLDB_LOG(log, "Hit non-loader breakpoint at address {0:x}.",
+                 record.GetExceptionAddress());
         uint32_t breakpoint_size = GetSoftwareBreakpointPCOffset();
         // The current PC is AFTER the BP opcode, on all architectures.
-        uint64_t pc = register_context.GetPC() - breakpoint_size;
-        register_context.SetPC(pc);
+        uint64_t pc = reg_ctx.GetPC() - breakpoint_size;
+        reg_ctx.SetPC(pc);
       }
 
-      SetState(eStateStopped, true);
-      return ExceptionResult::MaskException;
+      if (breakpoint_hit) {
+        StopThread(record.GetThreadID(), StopReason::eStopReasonBreakpoint);
+        SetState(eStateStopped, true);
+        return ExceptionResult::MaskException;
+      } else {
+        const std::vector<ULONG_PTR> &args = record.GetExceptionArguments();
+        if (args.size() >= 2) {
----------------
omjavaid wrote:

I believe you're referring to the call below:
reg_ctx.GetWatchpointHitIndex(hw_id, args[1]);
Generally, GetWatchpointHitIndex returns an error only if it fails to read the hardware breakpoint resource information via ReadHardwareDebugInfo. If the watchpoint hit detection is successful, the method returns the hw_watchpoint_id of the corresponding watchpoint. On failure to find watchpoint hit, it returns LLDB_INVALID_INDEX32.

https://github.com/llvm/llvm-project/pull/108072


More information about the lldb-commits mailing list