xref: /openbsd-src/gnu/llvm/lldb/tools/lldb-vscode/BreakpointBase.h (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1061da546Spatrick //===-- BreakpointBase.h ----------------------------------------*- C++ -*-===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick 
9dda28197Spatrick #ifndef LLDB_TOOLS_LLDB_VSCODE_BREAKPOINTBASE_H
10dda28197Spatrick #define LLDB_TOOLS_LLDB_VSCODE_BREAKPOINTBASE_H
11061da546Spatrick 
12061da546Spatrick #include "JSONUtils.h"
13061da546Spatrick #include "lldb/API/SBBreakpoint.h"
14061da546Spatrick #include "llvm/Support/JSON.h"
15061da546Spatrick #include <string>
16*f6aab3d8Srobert #include <vector>
17061da546Spatrick 
18061da546Spatrick namespace lldb_vscode {
19061da546Spatrick 
20061da546Spatrick struct BreakpointBase {
21*f6aab3d8Srobert   // logMessage part can be either a raw text or an expression.
22*f6aab3d8Srobert   struct LogMessagePart {
LogMessagePartBreakpointBase::LogMessagePart23*f6aab3d8Srobert     LogMessagePart(llvm::StringRef text, bool is_expr)
24*f6aab3d8Srobert         : text(text), is_expr(is_expr) {}
25*f6aab3d8Srobert     std::string text;
26*f6aab3d8Srobert     bool is_expr;
27*f6aab3d8Srobert   };
28061da546Spatrick   // An optional expression for conditional breakpoints.
29061da546Spatrick   std::string condition;
30061da546Spatrick   // An optional expression that controls how many hits of the breakpoint are
31061da546Spatrick   // ignored. The backend is expected to interpret the expression as needed
32061da546Spatrick   std::string hitCondition;
33061da546Spatrick   // If this attribute exists and is non-empty, the backend must not 'break'
34061da546Spatrick   // (stop) but log the message instead. Expressions within {} are
35061da546Spatrick   // interpolated.
36061da546Spatrick   std::string logMessage;
37*f6aab3d8Srobert   std::vector<LogMessagePart> logMessageParts;
38061da546Spatrick   // The LLDB breakpoint associated wit this source breakpoint
39061da546Spatrick   lldb::SBBreakpoint bp;
40061da546Spatrick 
41061da546Spatrick   BreakpointBase() = default;
42061da546Spatrick   BreakpointBase(const llvm::json::Object &obj);
43061da546Spatrick 
44061da546Spatrick   void SetCondition();
45061da546Spatrick   void SetHitCondition();
46*f6aab3d8Srobert   void SetLogMessage();
47061da546Spatrick   void UpdateBreakpoint(const BreakpointBase &request_bp);
48*f6aab3d8Srobert 
49*f6aab3d8Srobert   // Format \param text and return formatted text in \param formatted.
50*f6aab3d8Srobert   // \return any formatting failures.
51*f6aab3d8Srobert   lldb::SBError FormatLogText(llvm::StringRef text, std::string &formatted);
52*f6aab3d8Srobert   lldb::SBError AppendLogMessagePart(llvm::StringRef part, bool is_expr);
53*f6aab3d8Srobert   void NotifyLogMessageError(llvm::StringRef error);
54*f6aab3d8Srobert 
55dda28197Spatrick   static const char *GetBreakpointLabel();
56*f6aab3d8Srobert   static bool BreakpointHitCallback(void *baton, lldb::SBProcess &process,
57*f6aab3d8Srobert                                     lldb::SBThread &thread,
58*f6aab3d8Srobert                                     lldb::SBBreakpointLocation &location);
59061da546Spatrick };
60061da546Spatrick 
61061da546Spatrick } // namespace lldb_vscode
62061da546Spatrick 
63061da546Spatrick #endif
64