1 | //===-- SourceBreakpoint.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_SOURCEBREAKPOINT_H |
10 | #define LLDB_TOOLS_LLDB_DAP_SOURCEBREAKPOINT_H |
11 | |
12 | #include "Breakpoint.h" |
13 | #include "DAPForward.h" |
14 | #include "Protocol/ProtocolTypes.h" |
15 | #include "lldb/API/SBError.h" |
16 | #include "llvm/ADT/StringRef.h" |
17 | #include "llvm/Support/Error.h" |
18 | #include <cstdint> |
19 | #include <string> |
20 | #include <vector> |
21 | |
22 | namespace lldb_dap { |
23 | |
24 | class SourceBreakpoint : public Breakpoint { |
25 | public: |
26 | SourceBreakpoint(DAP &d, const protocol::SourceBreakpoint &breakpoint); |
27 | |
28 | // Set this breakpoint in LLDB as a new breakpoint |
29 | llvm::Error SetBreakpoint(const protocol::Source &source); |
30 | void UpdateBreakpoint(const SourceBreakpoint &request_bp); |
31 | |
32 | void SetLogMessage(); |
33 | // Format \param text and return formatted text in \param formatted. |
34 | // \return any formatting failures. |
35 | lldb::SBError FormatLogText(llvm::StringRef text, std::string &formatted); |
36 | lldb::SBError AppendLogMessagePart(llvm::StringRef part, bool is_expr); |
37 | void NotifyLogMessageError(llvm::StringRef error); |
38 | |
39 | static bool BreakpointHitCallback(void *baton, lldb::SBProcess &process, |
40 | lldb::SBThread &thread, |
41 | lldb::SBBreakpointLocation &location); |
42 | |
43 | inline bool operator<(const SourceBreakpoint &rhs) { |
44 | if (m_line == rhs.m_line) |
45 | return m_column < rhs.m_column; |
46 | return m_line < rhs.m_line; |
47 | } |
48 | |
49 | uint32_t GetLine() const { return m_line; } |
50 | uint32_t GetColumn() const { return m_column; } |
51 | |
52 | protected: |
53 | // logMessage part can be either a raw text or an expression. |
54 | struct LogMessagePart { |
55 | LogMessagePart(llvm::StringRef text, bool is_expr) |
56 | : text(text), is_expr(is_expr) {} |
57 | std::string text; |
58 | bool is_expr; |
59 | }; |
60 | // If this attribute exists and is non-empty, the backend must not 'break' |
61 | // (stop) but log the message instead. Expressions within {} are |
62 | // interpolated. |
63 | std::string m_log_message; |
64 | std::vector<LogMessagePart> m_log_message_parts; |
65 | |
66 | uint32_t m_line; ///< The source line of the breakpoint or logpoint |
67 | uint32_t m_column; ///< An optional source column of the breakpoint |
68 | }; |
69 | |
70 | } // namespace lldb_dap |
71 | |
72 | #endif |
73 | |