1 | //===-- SetInstructionBreakpointsRequestHandler.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 instruction breakpoints. Typically, instruction |
16 | /// breakpoints would be set from a disassembly window. To clear all instruction |
17 | /// breakpoints, specify an empty array. When an instruction breakpoint is hit, |
18 | /// a stopped event (with reason instruction breakpoint) is generated. Clients |
19 | /// should only call this request if the corresponding capability |
20 | /// supportsInstructionBreakpoints is true. |
21 | llvm::Expected<protocol::SetInstructionBreakpointsResponseBody> |
22 | SetInstructionBreakpointsRequestHandler::Run( |
23 | const protocol::SetInstructionBreakpointsArguments &args) const { |
24 | std::vector<protocol::Breakpoint> response_breakpoints; |
25 | |
26 | // Disable any instruction breakpoints that aren't in this request. |
27 | // There is no call to remove instruction breakpoints other than calling this |
28 | // function with a smaller or empty "breakpoints" list. |
29 | llvm::DenseSet<lldb::addr_t> seen( |
30 | llvm::from_range, llvm::make_first_range(c&: dap.instruction_breakpoints)); |
31 | |
32 | for (const auto &bp : args.breakpoints) { |
33 | // Read instruction breakpoint request. |
34 | InstructionBreakpoint inst_bp(dap, bp); |
35 | const auto [iv, inserted] = dap.instruction_breakpoints.try_emplace( |
36 | Key: inst_bp.GetInstructionAddressReference(), Args&: dap, Args: bp); |
37 | if (inserted) |
38 | iv->second.SetBreakpoint(); |
39 | else |
40 | iv->second.UpdateBreakpoint(request_bp: inst_bp); |
41 | response_breakpoints.push_back(x: iv->second.ToProtocolBreakpoint()); |
42 | seen.erase(V: inst_bp.GetInstructionAddressReference()); |
43 | } |
44 | |
45 | for (const auto &addr : seen) { |
46 | auto inst_bp = dap.instruction_breakpoints.find(Val: addr); |
47 | if (inst_bp == dap.instruction_breakpoints.end()) |
48 | continue; |
49 | dap.target.BreakpointDelete(break_id: inst_bp->second.GetID()); |
50 | dap.instruction_breakpoints.erase(Val: addr); |
51 | } |
52 | |
53 | return protocol::SetInstructionBreakpointsResponseBody{ |
54 | .breakpoints: std::move(response_breakpoints)}; |
55 | } |
56 | |
57 | } // namespace lldb_dap |
58 |