1 | //===-- BreakpointBase.h ----------------------------------------*- 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 | #ifndef LLDB_TOOLS_LLDB_DAP_BREAKPOINTBASE_H |
10 | #define LLDB_TOOLS_LLDB_DAP_BREAKPOINTBASE_H |
11 | |
12 | #include "DAPForward.h" |
13 | #include "Protocol/ProtocolTypes.h" |
14 | #include <optional> |
15 | #include <string> |
16 | |
17 | namespace lldb_dap { |
18 | |
19 | class BreakpointBase { |
20 | public: |
21 | explicit BreakpointBase(DAP &d) : m_dap(d) {} |
22 | BreakpointBase(DAP &d, const std::optional<std::string> &condition, |
23 | const std::optional<std::string> &hit_condition); |
24 | virtual ~BreakpointBase() = default; |
25 | |
26 | virtual void SetCondition() = 0; |
27 | virtual void SetHitCondition() = 0; |
28 | virtual protocol::Breakpoint ToProtocolBreakpoint() = 0; |
29 | |
30 | void UpdateBreakpoint(const BreakpointBase &request_bp); |
31 | |
32 | /// Breakpoints in LLDB can have names added to them which are kind of like |
33 | /// labels or categories. All breakpoints that are set through DAP get sent |
34 | /// through the various DAP set*Breakpoint packets, and these breakpoints will |
35 | /// be labeled with this name so if breakpoint update events come in for |
36 | /// breakpoints that the client doesn't know about, like if a breakpoint is |
37 | /// set manually using the debugger console, we won't report any updates on |
38 | /// them and confused the client. This label gets added by all of the |
39 | /// breakpoint classes after they set breakpoints to mark a breakpoint as a |
40 | /// DAP breakpoint. We can later check a lldb::SBBreakpoint object that comes |
41 | /// in via LLDB breakpoint changed events and check the breakpoint by calling |
42 | /// "bool lldb::SBBreakpoint::MatchesName(const char *)" to check if a |
43 | /// breakpoint in one of the DAP breakpoints that we should report changes |
44 | /// for. |
45 | static constexpr const char *kDAPBreakpointLabel = "dap" ; |
46 | |
47 | protected: |
48 | /// Associated DAP session. |
49 | DAP &m_dap; |
50 | |
51 | /// An optional expression for conditional breakpoints. |
52 | std::string m_condition; |
53 | |
54 | /// An optional expression that controls how many hits of the breakpoint are |
55 | /// ignored. The backend is expected to interpret the expression as needed |
56 | std::string m_hit_condition; |
57 | }; |
58 | |
59 | } // namespace lldb_dap |
60 | |
61 | #endif |
62 | |