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-exception |
6 | // |
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 | |
19 | namespace lldb_dap { |
20 | Watchpoint::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(Separator: '/'); |
24 | llvm::to_integer(S: addr_str, Num&: m_addr, Base: 16); |
25 | llvm::to_integer(S: size_str, Num&: 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 | |
32 | void Watchpoint::SetCondition() { m_wp.SetCondition(m_condition.c_str()); } |
33 | |
34 | void Watchpoint::SetHitCondition() { |
35 | uint64_t hitCount = 0; |
36 | if (llvm::to_integer(S: m_hit_condition, Num&: hitCount)) |
37 | m_wp.SetIgnoreCount(hitCount - 1); |
38 | } |
39 | |
40 | protocol::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 | } |
49 | |
50 | return breakpoint; |
51 | } |
52 | |
53 | void Watchpoint::SetWatchpoint() { |
54 | m_wp = m_dap.target.WatchpointCreateByAddress(addr: m_addr, size: m_size, options: m_options, |
55 | error&: m_error); |
56 | if (!m_condition.empty()) |
57 | SetCondition(); |
58 | if (!m_hit_condition.empty()) |
59 | SetHitCondition(); |
60 | } |
61 | } // namespace lldb_dap |
62 | |