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/Utility/ConstString.h"
10 #include "lldb/Utility/Event.h"
11 
12 #include <string>
13 
14 #ifndef LLDB_CORE_DEBUGGER_EVENTS_H
15 #define LLDB_CORE_DEBUGGER_EVENTS_H
16 
17 namespace lldb_private {
18 class Stream;
19 
20 class ProgressEventData : public EventData {
21 public:
22   ProgressEventData(uint64_t progress_id, const std::string &message,
23                     uint64_t completed, uint64_t total, bool debugger_specific)
24       : m_message(message), m_id(progress_id), m_completed(completed),
25         m_total(total), m_debugger_specific(debugger_specific) {}
26 
27   static ConstString GetFlavorString();
28 
29   ConstString GetFlavor() const override;
30 
31   void Dump(Stream *s) const override;
32 
33   static const ProgressEventData *GetEventDataFromEvent(const Event *event_ptr);
34   uint64_t GetID() const { return m_id; }
35   bool IsFinite() const { return m_total != UINT64_MAX; }
36   uint64_t GetCompleted() const { return m_completed; }
37   uint64_t GetTotal() const { return m_total; }
38   const std::string &GetMessage() const { return m_message; }
39   bool IsDebuggerSpecific() const { return m_debugger_specific; }
40 
41 private:
42   std::string m_message;
43   const uint64_t m_id;
44   uint64_t m_completed;
45   const uint64_t m_total;
46   const bool m_debugger_specific;
47   ProgressEventData(const ProgressEventData &) = delete;
48   const ProgressEventData &operator=(const ProgressEventData &) = delete;
49 };
50 
51 class DiagnosticEventData : public EventData {
52 public:
53   enum class Type {
54     Warning,
55     Error,
56   };
57   DiagnosticEventData(Type type, std::string message, bool debugger_specific)
58       : m_message(std::move(message)), m_type(type),
59         m_debugger_specific(debugger_specific) {}
60   ~DiagnosticEventData() override = default;
61 
62   const std::string &GetMessage() const { return m_message; }
63   bool IsDebuggerSpecific() const { return m_debugger_specific; }
64   Type GetType() const { return m_type; }
65 
66   llvm::StringRef GetPrefix() const;
67 
68   void Dump(Stream *s) const override;
69 
70   static ConstString GetFlavorString();
71   ConstString GetFlavor() const override;
72 
73   static const DiagnosticEventData *
74   GetEventDataFromEvent(const Event *event_ptr);
75 
76 protected:
77   std::string m_message;
78   Type m_type;
79   const bool m_debugger_specific;
80 
81   DiagnosticEventData(const DiagnosticEventData &) = delete;
82   const DiagnosticEventData &operator=(const DiagnosticEventData &) = delete;
83 };
84 
85 } // namespace lldb_private
86 
87 #endif // LLDB_CORE_DEBUGGER_EVENTS_H
88