brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 48b2ba5 Raw
58 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "DAP.h"10#include "EventHelper.h"11#include "RequestHandler.h"12 13namespace lldb_dap {14 15/// Replaces all existing instruction breakpoints. Typically, instruction16/// breakpoints would be set from a disassembly window. To clear all instruction17/// breakpoints, specify an empty array. When an instruction breakpoint is hit,18/// a stopped event (with reason instruction breakpoint) is generated. Clients19/// should only call this request if the corresponding capability20/// supportsInstructionBreakpoints is true.21llvm::Expected<protocol::SetInstructionBreakpointsResponseBody>22SetInstructionBreakpointsRequestHandler::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 this28  // function with a smaller or empty "breakpoints" list.29  llvm::DenseSet<lldb::addr_t> seen(30      llvm::from_range, llvm::make_first_range(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        inst_bp.GetInstructionAddressReference(), dap, bp);37    if (inserted)38      iv->second.SetBreakpoint();39    else40      iv->second.UpdateBreakpoint(inst_bp);41    response_breakpoints.push_back(iv->second.ToProtocolBreakpoint());42    seen.erase(inst_bp.GetInstructionAddressReference());43  }44 45  for (const auto &addr : seen) {46    auto inst_bp = dap.instruction_breakpoints.find(addr);47    if (inst_bp == dap.instruction_breakpoints.end())48      continue;49    dap.target.BreakpointDelete(inst_bp->second.GetID());50    dap.instruction_breakpoints.erase(addr);51  }52 53  return protocol::SetInstructionBreakpointsResponseBody{54      std::move(response_breakpoints)};55}56 57} // namespace lldb_dap58