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