xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Core/DebuggerEvents.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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:
ProgressEventData(uint64_t progress_id,std::string title,std::string details,uint64_t completed,uint64_t total,bool debugger_specific)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 
GetID()42   uint64_t GetID() const { return m_id; }
IsFinite()43   bool IsFinite() const { return m_total != Progress::kNonDeterministicTotal; }
GetCompleted()44   uint64_t GetCompleted() const { return m_completed; }
GetTotal()45   uint64_t GetTotal() const { return m_total; }
GetMessage()46   std::string GetMessage() const {
47     std::string message = m_title;
48     if (!m_details.empty()) {
49       message.append(": ");
50       message.append(m_details);
51     }
52     return message;
53   }
GetTitle()54   const std::string &GetTitle() const { return m_title; }
GetDetails()55   const std::string &GetDetails() const { return m_details; }
IsDebuggerSpecific()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:
DiagnosticEventData(lldb::Severity severity,std::string message,bool debugger_specific)79   DiagnosticEventData(lldb::Severity severity, std::string message,
80                       bool debugger_specific)
81       : m_message(std::move(message)), m_severity(severity),
82         m_debugger_specific(debugger_specific) {}
83   ~DiagnosticEventData() override = default;
84 
GetMessage()85   const std::string &GetMessage() const { return m_message; }
IsDebuggerSpecific()86   bool IsDebuggerSpecific() const { return m_debugger_specific; }
GetSeverity()87   lldb::Severity GetSeverity() const { return m_severity; }
88 
89   llvm::StringRef GetPrefix() const;
90 
91   void Dump(Stream *s) const override;
92 
93   static llvm::StringRef GetFlavorString();
94   llvm::StringRef GetFlavor() const override;
95 
96   static const DiagnosticEventData *
97   GetEventDataFromEvent(const Event *event_ptr);
98 
99   static StructuredData::DictionarySP
100   GetAsStructuredData(const Event *event_ptr);
101 
102 protected:
103   std::string m_message;
104   lldb::Severity m_severity;
105   const bool m_debugger_specific;
106 
107   DiagnosticEventData(const DiagnosticEventData &) = delete;
108   const DiagnosticEventData &operator=(const DiagnosticEventData &) = delete;
109 };
110 
111 class SymbolChangeEventData : public EventData {
112 public:
SymbolChangeEventData(lldb::DebuggerWP debugger_wp,ModuleSpec module_spec)113   SymbolChangeEventData(lldb::DebuggerWP debugger_wp, ModuleSpec module_spec)
114       : m_debugger_wp(debugger_wp), m_module_spec(std::move(module_spec)) {}
115 
116   static llvm::StringRef GetFlavorString();
117   llvm::StringRef GetFlavor() const override;
118 
119   static const SymbolChangeEventData *
120   GetEventDataFromEvent(const Event *event_ptr);
121 
122   void DoOnRemoval(Event *event_ptr) override;
123 
124 private:
125   lldb::DebuggerWP m_debugger_wp;
126   ModuleSpec m_module_spec;
127 
128   SymbolChangeEventData(const SymbolChangeEventData &) = delete;
129   const SymbolChangeEventData &
130   operator=(const SymbolChangeEventData &) = delete;
131 };
132 
133 } // namespace lldb_private
134 
135 #endif // LLDB_CORE_DEBUGGER_EVENTS_H
136