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