| 1 | //===-- SetFunctionBreakpointsRequestHandler.cpp --------------------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "DAP.h" |
| 10 | #include "EventHelper.h" |
| 11 | #include "RequestHandler.h" |
| 12 | |
| 13 | namespace lldb_dap { |
| 14 | |
| 15 | /// Replaces all existing function breakpoints with new function breakpoints. |
| 16 | /// To clear all function breakpoints, specify an empty array. |
| 17 | /// When a function breakpoint is hit, a stopped event (with reason function |
| 18 | /// breakpoint) is generated. Clients should only call this request if the |
| 19 | /// corresponding capability supportsFunctionBreakpoints is true. |
| 20 | llvm::Expected<protocol::SetFunctionBreakpointsResponseBody> |
| 21 | SetFunctionBreakpointsRequestHandler::Run( |
| 22 | const protocol::SetFunctionBreakpointsArguments &args) const { |
| 23 | std::vector<protocol::Breakpoint> response_breakpoints; |
| 24 | |
| 25 | // Disable any function breakpoints that aren't in this request. |
| 26 | // There is no call to remove function breakpoints other than calling this |
| 27 | // function with a smaller or empty "breakpoints" list. |
| 28 | const auto name_iter = dap.function_breakpoints.keys(); |
| 29 | llvm::DenseSet<llvm::StringRef> seen(name_iter.begin(), name_iter.end()); |
| 30 | for (const auto &fb : args.breakpoints) { |
| 31 | FunctionBreakpoint fn_bp(dap, fb); |
| 32 | const auto [it, inserted] = |
| 33 | dap.function_breakpoints.try_emplace(Key: fn_bp.GetFunctionName(), Args&: dap, Args: fb); |
| 34 | if (inserted) |
| 35 | it->second.SetBreakpoint(); |
| 36 | else |
| 37 | it->second.UpdateBreakpoint(request_bp: fn_bp); |
| 38 | |
| 39 | response_breakpoints.push_back(x: it->second.ToProtocolBreakpoint()); |
| 40 | seen.erase(V: fn_bp.GetFunctionName()); |
| 41 | } |
| 42 | |
| 43 | // Remove any breakpoints that are no longer in our list |
| 44 | for (const auto &name : seen) { |
| 45 | auto fn_bp = dap.function_breakpoints.find(Key: name); |
| 46 | if (fn_bp == dap.function_breakpoints.end()) |
| 47 | continue; |
| 48 | dap.target.BreakpointDelete(break_id: fn_bp->second.GetID()); |
| 49 | dap.function_breakpoints.erase(Key: name); |
| 50 | } |
| 51 | |
| 52 | return protocol::SetFunctionBreakpointsResponseBody{ |
| 53 | .breakpoints: std::move(response_breakpoints)}; |
| 54 | } |
| 55 | |
| 56 | } // namespace lldb_dap |
| 57 |
