This revision was automatically updated to reflect the committed changes.
Closed by commit rL364780: [lldb] [Process/NetBSD] Fix segfault when handling 
watchpoint (authored by mgorny, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63791?vs=206528&id=207319#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63791/new/

https://reviews.llvm.org/D63791

Files:
  lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp


Index: lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
===================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -238,12 +238,25 @@
     SetState(StateType::eStateStopped, true);
   } break;
   case TRAP_DBREG: {
+    // Find the thread.
+    NativeThreadNetBSD* thread = nullptr;
+    for (const auto &t : m_threads) {
+      if (t->GetID() == info.psi_lwpid) {
+        thread = static_cast<NativeThreadNetBSD *>(t.get());
+        break;
+      }
+    }
+    if (!thread) {
+      LLDB_LOG(log,
+               "thread not found in m_threads, pid = {0}, LWP = {1}",
+               GetID(), info.psi_lwpid);
+      break;
+    }
+
     // If a watchpoint was hit, report it
-    uint32_t wp_index;
-    Status error = static_cast<NativeThreadNetBSD 
&>(*m_threads[info.psi_lwpid])
-                       .GetRegisterContext()
-                       .GetWatchpointHitIndex(
-                           wp_index, (uintptr_t)info.psi_siginfo.si_addr);
+    uint32_t wp_index = LLDB_INVALID_INDEX32;
+    Status error = thread->GetRegisterContext().GetWatchpointHitIndex(
+        wp_index, (uintptr_t)info.psi_siginfo.si_addr);
     if (error.Fail())
       LLDB_LOG(log,
                "received error while checking for watchpoint hits, pid = "
@@ -258,11 +271,9 @@
     }
 
     // If a breakpoint was hit, report it
-    uint32_t bp_index;
-    error = static_cast<NativeThreadNetBSD &>(*m_threads[info.psi_lwpid])
-                .GetRegisterContext()
-                .GetHardwareBreakHitIndex(bp_index,
-                                           
(uintptr_t)info.psi_siginfo.si_addr);
+    uint32_t bp_index = LLDB_INVALID_INDEX32;
+    error = thread->GetRegisterContext().GetHardwareBreakHitIndex(
+        bp_index, (uintptr_t)info.psi_siginfo.si_addr);
     if (error.Fail())
       LLDB_LOG(log,
                "received error while checking for hardware "


Index: lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
===================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -238,12 +238,25 @@
     SetState(StateType::eStateStopped, true);
   } break;
   case TRAP_DBREG: {
+    // Find the thread.
+    NativeThreadNetBSD* thread = nullptr;
+    for (const auto &t : m_threads) {
+      if (t->GetID() == info.psi_lwpid) {
+        thread = static_cast<NativeThreadNetBSD *>(t.get());
+        break;
+      }
+    }
+    if (!thread) {
+      LLDB_LOG(log,
+               "thread not found in m_threads, pid = {0}, LWP = {1}",
+               GetID(), info.psi_lwpid);
+      break;
+    }
+
     // If a watchpoint was hit, report it
-    uint32_t wp_index;
-    Status error = static_cast<NativeThreadNetBSD &>(*m_threads[info.psi_lwpid])
-                       .GetRegisterContext()
-                       .GetWatchpointHitIndex(
-                           wp_index, (uintptr_t)info.psi_siginfo.si_addr);
+    uint32_t wp_index = LLDB_INVALID_INDEX32;
+    Status error = thread->GetRegisterContext().GetWatchpointHitIndex(
+        wp_index, (uintptr_t)info.psi_siginfo.si_addr);
     if (error.Fail())
       LLDB_LOG(log,
                "received error while checking for watchpoint hits, pid = "
@@ -258,11 +271,9 @@
     }
 
     // If a breakpoint was hit, report it
-    uint32_t bp_index;
-    error = static_cast<NativeThreadNetBSD &>(*m_threads[info.psi_lwpid])
-                .GetRegisterContext()
-                .GetHardwareBreakHitIndex(bp_index,
-                                           (uintptr_t)info.psi_siginfo.si_addr);
+    uint32_t bp_index = LLDB_INVALID_INDEX32;
+    error = thread->GetRegisterContext().GetHardwareBreakHitIndex(
+        bp_index, (uintptr_t)info.psi_siginfo.si_addr);
     if (error.Fail())
       LLDB_LOG(log,
                "received error while checking for hardware "
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to