[Lldb-commits] [lldb] Make breakpoint stop reason more accurate for function breakpoints (PR #130841)

via lldb-commits lldb-commits at lists.llvm.org
Sat Mar 15 23:19:16 PDT 2025


================
@@ -392,9 +391,59 @@ struct DAP {
 
   void SetThreadFormat(llvm::StringRef format);
 
-  InstructionBreakpoint *GetInstructionBreakpoint(const lldb::break_id_t bp_id);
+  template <typename BreakpointType>
+  BreakpointType *GetBreakpointFromStopReason(lldb::SBThread &thread) {
+    // Check to see if have hit the <BreakpointType> breakpoint and change the
+    // reason accordingly, but only do so if all breakpoints that were
+    // hit are of <BreakpointType>.
+    const auto num = thread.GetStopReasonDataCount();
+    BreakpointType *bp = nullptr;
+    for (size_t i = 0; i < num; i += 2) {
+      lldb::break_id_t bp_id = thread.GetStopReasonDataAtIndex(i);
+      // If any breakpoint is not the <BreakpointType>, then stop and
+      // report this as a normal breakpoint
+      bp = GetBreakpoint<BreakpointType>(bp_id);
+      if (bp == nullptr)
+        return nullptr;
+    }
+    return bp;
+  }
+
+  template <typename BreakpointType>
+  BreakpointType *GetBreakpoint(const lldb::break_id_t bp_id);
+
+  template <>
+  FunctionBreakpoint *
+  GetBreakpoint<FunctionBreakpoint>(const lldb::break_id_t bp_id) {
+    for (auto &bp : function_breakpoints) {
----------------
satyajanga wrote:


updated to use std:find_if

the types for the collections are different,  so further templatization is challenging. Let me know if I am mis-undersanding. 
exception_breakpoints ->   std::optional<std::vector<ExceptionBreakpoint>> 
function_breakpoints -> llvm::StringMap<FunctionBreakpoint> 
instruction_breakpoints -> llvm::DenseMap<lldb::addr_t, InstructionBreakpoint>

I am open to changing. just didn't see a way to control the return collection type for template function that returns the collections. 



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


More information about the lldb-commits mailing list