[Lldb-commits] [lldb] r364780 - [lldb] [Process/NetBSD] Fix segfault when handling watchpoint

Michal Gorny via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 1 08:11:10 PDT 2019


Author: mgorny
Date: Mon Jul  1 08:11:10 2019
New Revision: 364780

URL: http://llvm.org/viewvc/llvm-project?rev=364780&view=rev
Log:
[lldb] [Process/NetBSD] Fix segfault when handling watchpoint

Fix the watchpoint/breakpoint code to search for matching thread entry
in m_threads explicitly rather than assuming that it will be present
at specified index.  The previous code segfault since it wrongly assumed
that the index will match LWP ID which was incorrect even for a single
thread (where index was 0 and LWP ID was 1).

While fixing that off-by-one error would help for this specific task,
I believe it is better to be explicit in what we are searching for.

Differential Revision: https://reviews.llvm.org/D63791

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

Modified: lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp?rev=364780&r1=364779&r2=364780&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp Mon Jul  1 08:11:10 2019
@@ -238,12 +238,25 @@ void NativeProcessNetBSD::MonitorSIGTRAP
     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 @@ void NativeProcessNetBSD::MonitorSIGTRAP
     }
 
     // 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 "




More information about the lldb-commits mailing list