51 lines · cpp
1//===-- SetDataBreakpointsRequestHandler.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 "Protocol/ProtocolRequests.h"12#include "RequestHandler.h"13#include "Watchpoint.h"14#include <set>15 16namespace lldb_dap {17 18/// Replaces all existing data breakpoints with new data breakpoints.19/// To clear all data breakpoints, specify an empty array.20/// When a data breakpoint is hit, a stopped event (with reason data breakpoint)21/// is generated. Clients should only call this request if the corresponding22/// capability supportsDataBreakpoints is true.23llvm::Expected<protocol::SetDataBreakpointsResponseBody>24SetDataBreakpointsRequestHandler::Run(25 const protocol::SetDataBreakpointsArguments &args) const {26 std::vector<protocol::Breakpoint> response_breakpoints;27 28 dap.target.DeleteAllWatchpoints();29 std::vector<Watchpoint> watchpoints;30 for (const auto &bp : args.breakpoints)31 watchpoints.emplace_back(dap, bp);32 33 // If two watchpoints start at the same address, the latter overwrite the34 // former. So, we only enable those at first-seen addresses when iterating35 // backward.36 std::set<lldb::addr_t> addresses;37 for (auto iter = watchpoints.rbegin(); iter != watchpoints.rend(); ++iter) {38 if (addresses.count(iter->GetAddress()) == 0) {39 iter->SetWatchpoint();40 addresses.insert(iter->GetAddress());41 }42 }43 for (auto wp : watchpoints)44 response_breakpoints.push_back(wp.ToProtocolBreakpoint());45 46 return protocol::SetDataBreakpointsResponseBody{47 std::move(response_breakpoints)};48}49 50} // namespace lldb_dap51