63 lines · cpp
1//===-- Watchpoint.cpp ------------------------------------------*- C++ -*-===//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 "Watchpoint.h"10#include "DAP.h"11#include "Protocol/ProtocolTypes.h"12#include "lldb/API/SBTarget.h"13#include "lldb/lldb-enumerations.h"14#include "llvm/ADT/StringExtras.h"15#include "llvm/ADT/StringRef.h"16#include <cstdint>17#include <string>18 19namespace lldb_dap {20Watchpoint::Watchpoint(DAP &d, const protocol::DataBreakpoint &breakpoint)21 : BreakpointBase(d, breakpoint.condition, breakpoint.hitCondition) {22 llvm::StringRef dataId = breakpoint.dataId;23 auto [addr_str, size_str] = dataId.split('/');24 llvm::to_integer(addr_str, m_addr, 16);25 llvm::to_integer(size_str, m_size);26 m_options.SetWatchpointTypeRead(breakpoint.accessType !=27 protocol::eDataBreakpointAccessTypeWrite);28 if (breakpoint.accessType != protocol::eDataBreakpointAccessTypeRead)29 m_options.SetWatchpointTypeWrite(lldb::eWatchpointWriteTypeOnModify);30}31 32void Watchpoint::SetCondition() { m_wp.SetCondition(m_condition.c_str()); }33 34void Watchpoint::SetHitCondition() {35 uint64_t hitCount = 0;36 if (llvm::to_integer(m_hit_condition, hitCount))37 m_wp.SetIgnoreCount(hitCount - 1);38}39 40protocol::Breakpoint Watchpoint::ToProtocolBreakpoint() {41 protocol::Breakpoint breakpoint;42 if (!m_error.IsValid() || m_error.Fail()) {43 breakpoint.verified = false;44 if (m_error.Fail())45 breakpoint.message = m_error.GetCString();46 } else {47 breakpoint.verified = true;48 breakpoint.id = m_wp.GetID();49 }50 51 return breakpoint;52}53 54void Watchpoint::SetWatchpoint() {55 m_wp = m_dap.target.WatchpointCreateByAddress(m_addr, m_size, m_options,56 m_error);57 if (!m_condition.empty())58 SetCondition();59 if (!m_hit_condition.empty())60 SetHitCondition();61}62} // namespace lldb_dap63