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 "llvm/ADT/StringRef.h" |
14 | |
15 | namespace lldb_dap { |
16 | |
17 | struct SourceBreakpoint : public Breakpoint { |
18 | // logMessage part can be either a raw text or an expression. |
19 | struct LogMessagePart { |
20 | LogMessagePart(llvm::StringRef text, bool is_expr) |
21 | : text(text), is_expr(is_expr) {} |
22 | std::string text; |
23 | bool is_expr; |
24 | }; |
25 | // If this attribute exists and is non-empty, the backend must not 'break' |
26 | // (stop) but log the message instead. Expressions within {} are |
27 | // interpolated. |
28 | std::string logMessage; |
29 | std::vector<LogMessagePart> logMessageParts; |
30 | |
31 | uint32_t line; ///< The source line of the breakpoint or logpoint |
32 | uint32_t column; ///< An optional source column of the breakpoint |
33 | |
34 | SourceBreakpoint() : Breakpoint(), line(0), column(0) {} |
35 | SourceBreakpoint(const llvm::json::Object &obj); |
36 | |
37 | // Set this breakpoint in LLDB as a new breakpoint |
38 | void SetBreakpoint(const llvm::StringRef source_path); |
39 | void UpdateBreakpoint(const SourceBreakpoint &request_bp); |
40 | |
41 | void SetLogMessage(); |
42 | // Format \param text and return formatted text in \param formatted. |
43 | // \return any formatting failures. |
44 | lldb::SBError FormatLogText(llvm::StringRef text, std::string &formatted); |
45 | lldb::SBError AppendLogMessagePart(llvm::StringRef part, bool is_expr); |
46 | void NotifyLogMessageError(llvm::StringRef error); |
47 | |
48 | static bool BreakpointHitCallback(void *baton, lldb::SBProcess &process, |
49 | lldb::SBThread &thread, |
50 | lldb::SBBreakpointLocation &location); |
51 | }; |
52 | |
53 | inline bool operator<(const SourceBreakpoint &lhs, |
54 | const SourceBreakpoint &rhs) { |
55 | if (lhs.line == rhs.line) |
56 | return lhs.column < rhs.column; |
57 | return lhs.line < rhs.line; |
58 | } |
59 | |
60 | } // namespace lldb_dap |
61 | |
62 | #endif |
63 | |