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-exception
6//
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 corresponding
22/// 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(args&: dap, args: bp);
32
33 // If two watchpoints start at the same address, the latter overwrite the
34 // former. So, we only enable those at first-seen addresses when iterating
35 // backward.
36 std::set<lldb::addr_t> addresses;
37 for (auto iter = watchpoints.rbegin(); iter != watchpoints.rend(); ++iter) {
38 if (addresses.count(x: iter->GetAddress()) == 0) {
39 iter->SetWatchpoint();
40 addresses.insert(x: iter->GetAddress());
41 }
42 }
43 for (auto wp : watchpoints)
44 response_breakpoints.push_back(x: wp.ToProtocolBreakpoint());
45
46 return protocol::SetDataBreakpointsResponseBody{
47 .breakpoints: std::move(response_breakpoints)};
48}
49
50} // namespace lldb_dap
51

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of lldb/tools/lldb-dap/Handler/SetDataBreakpointsRequestHandler.cpp