57 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "DAP.h"10#include "EventHelper.h"11#include "RequestHandler.h"12 13namespace 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 function18/// breakpoint) is generated. Clients should only call this request if the19/// corresponding capability supportsFunctionBreakpoints is true.20llvm::Expected<protocol::SetFunctionBreakpointsResponseBody>21SetFunctionBreakpointsRequestHandler::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 this27 // 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(fn_bp.GetFunctionName(), dap, fb);34 if (inserted)35 it->second.SetBreakpoint();36 else37 it->second.UpdateBreakpoint(fn_bp);38 39 response_breakpoints.push_back(it->second.ToProtocolBreakpoint());40 seen.erase(fn_bp.GetFunctionName());41 }42 43 // Remove any breakpoints that are no longer in our list44 for (const auto &name : seen) {45 auto fn_bp = dap.function_breakpoints.find(name);46 if (fn_bp == dap.function_breakpoints.end())47 continue;48 dap.target.BreakpointDelete(fn_bp->second.GetID());49 dap.function_breakpoints.erase(name);50 }51 52 return protocol::SetFunctionBreakpointsResponseBody{53 std::move(response_breakpoints)};54}55 56} // namespace lldb_dap57