================
@@ -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) {
----------------
Jlalond wrote:

Because we're duplicating code here three times, would it make more sense that 
the template controls which breakpoint collection to grab, and then we just 
have the following logic in every case?

So we'd make GetBreakpoint

```
template <typename BreakpointType>
BreakpointType *GetBreakpoint(const lldb::break_id_t bp_id) {
    for (auto &bp : GetBreakpoints<>) {
      if (bp.second.bp.GetID() == bp_id)
        return &bp.second;
    }
    return nullptr;
}
```

Where the new `GetBreakpoints` call just gets the correct collection?

https://github.com/llvm/llvm-project/pull/130841
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to