1//===-- DebuggerEvents.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#include "lldb/Core/ModuleSpec.h" 10#include "lldb/Utility/Event.h" 11#include "lldb/Utility/StructuredData.h" 12 13#include <string> 14 15#ifndef LLDB_CORE_DEBUGGER_EVENTS_H 16#define LLDB_CORE_DEBUGGER_EVENTS_H 17 18namespace lldb_private { 19class Stream; 20 21class ProgressEventData : public EventData { 22public: 23 ProgressEventData(uint64_t progress_id, std::string title, 24 std::string details, uint64_t completed, uint64_t total, 25 bool debugger_specific) 26 : m_title(std::move(title)), m_details(std::move(details)), 27 m_id(progress_id), m_completed(completed), m_total(total), 28 m_debugger_specific(debugger_specific) {} 29 30 static llvm::StringRef GetFlavorString(); 31 32 llvm::StringRef GetFlavor() const override; 33 34 void Dump(Stream *s) const override; 35 36 static const ProgressEventData *GetEventDataFromEvent(const Event *event_ptr); 37 38 static StructuredData::DictionarySP 39 GetAsStructuredData(const Event *event_ptr); 40 41 uint64_t GetID() const { return m_id; } 42 bool IsFinite() const { return m_total != UINT64_MAX; } 43 uint64_t GetCompleted() const { return m_completed; } 44 uint64_t GetTotal() const { return m_total; } 45 std::string GetMessage() const { 46 std::string message = m_title; 47 if (!m_details.empty()) { 48 message.append(": "); 49 message.append(m_details); 50 } 51 return message; 52 } 53 const std::string &GetTitle() const { return m_title; } 54 const std::string &GetDetails() const { return m_details; } 55 bool IsDebuggerSpecific() const { return m_debugger_specific; } 56 57private: 58 /// The title of this progress event. The value is expected to remain stable 59 /// for a given progress ID. 60 std::string m_title; 61 62 /// Details associated with this progress event update. The value is expected 63 /// to change between progress events. 64 std::string m_details; 65 66 /// Unique ID used to associate progress events. 67 const uint64_t m_id; 68 69 uint64_t m_completed; 70 const uint64_t m_total; 71 const bool m_debugger_specific; 72 ProgressEventData(const ProgressEventData &) = delete; 73 const ProgressEventData &operator=(const ProgressEventData &) = delete; 74}; 75 76class DiagnosticEventData : public EventData { 77public: 78 enum class Type { 79 Info, 80 Warning, 81 Error, 82 }; 83 DiagnosticEventData(Type type, std::string message, bool debugger_specific) 84 : m_message(std::move(message)), m_type(type), 85 m_debugger_specific(debugger_specific) {} 86 ~DiagnosticEventData() override = default; 87 88 const std::string &GetMessage() const { return m_message; } 89 bool IsDebuggerSpecific() const { return m_debugger_specific; } 90 Type GetType() const { return m_type; } 91 92 llvm::StringRef GetPrefix() const; 93 94 void Dump(Stream *s) const override; 95 96 static llvm::StringRef GetFlavorString(); 97 llvm::StringRef GetFlavor() const override; 98 99 static const DiagnosticEventData * 100 GetEventDataFromEvent(const Event *event_ptr); 101 102 static StructuredData::DictionarySP 103 GetAsStructuredData(const Event *event_ptr); 104 105protected: 106 std::string m_message; 107 Type m_type; 108 const bool m_debugger_specific; 109 110 DiagnosticEventData(const DiagnosticEventData &) = delete; 111 const DiagnosticEventData &operator=(const DiagnosticEventData &) = delete; 112}; 113 114class SymbolChangeEventData : public EventData { 115public: 116 SymbolChangeEventData(lldb::DebuggerWP debugger_wp, ModuleSpec module_spec) 117 : m_debugger_wp(debugger_wp), m_module_spec(std::move(module_spec)) {} 118 119 static llvm::StringRef GetFlavorString(); 120 llvm::StringRef GetFlavor() const override; 121 122 static const SymbolChangeEventData * 123 GetEventDataFromEvent(const Event *event_ptr); 124 125 void DoOnRemoval(Event *event_ptr) override; 126 127private: 128 lldb::DebuggerWP m_debugger_wp; 129 ModuleSpec m_module_spec; 130 131 SymbolChangeEventData(const SymbolChangeEventData &) = delete; 132 const SymbolChangeEventData & 133 operator=(const SymbolChangeEventData &) = delete; 134}; 135 136} // namespace lldb_private 137 138#endif // LLDB_CORE_DEBUGGER_EVENTS_H 139