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