diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h --- a/lldb/include/lldb/Core/Debugger.h +++ b/lldb/include/lldb/Core/Debugger.h @@ -57,6 +57,7 @@ class Stream; class SymbolContext; class Target; +class ProgressEventData; namespace repro { class DataRecorder; @@ -84,39 +85,6 @@ Broadcaster &GetBroadcaster() { return m_broadcaster; } const Broadcaster &GetBroadcaster() const { return m_broadcaster; } - class ProgressEventData : public EventData { - - public: - ProgressEventData(uint64_t progress_id, const std::string &message, - uint64_t completed, uint64_t total, - bool debugger_specific) - : m_message(message), m_id(progress_id), m_completed(completed), - m_total(total), m_debugger_specific(debugger_specific) {} - - static ConstString GetFlavorString(); - - ConstString GetFlavor() const override; - - void Dump(Stream *s) const override; - - static const ProgressEventData * - GetEventDataFromEvent(const Event *event_ptr); - uint64_t GetID() const { return m_id; } - uint64_t GetCompleted() const { return m_completed; } - uint64_t GetTotal() const { return m_total; } - const std::string &GetMessage() const { return m_message; } - bool IsDebuggerSpecific() const { return m_debugger_specific; } - - private: - std::string m_message; - const uint64_t m_id; - uint64_t m_completed; - const uint64_t m_total; - const bool m_debugger_specific; - ProgressEventData(const ProgressEventData &) = delete; - const ProgressEventData &operator=(const ProgressEventData &) = delete; - }; - ~Debugger() override; static lldb::DebuggerSP @@ -445,7 +413,7 @@ uint64_t completed, uint64_t total, llvm::Optional debugger_id); - void PrintProgress(const Debugger::ProgressEventData &data); + void PrintProgress(const ProgressEventData &data); bool StartEventHandlerThread(); diff --git a/lldb/include/lldb/Core/DebuggerEvents.h b/lldb/include/lldb/Core/DebuggerEvents.h new file mode 100644 --- /dev/null +++ b/lldb/include/lldb/Core/DebuggerEvents.h @@ -0,0 +1,51 @@ +//===-- DebuggerEvents.h ----------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/Utility/ConstString.h" +#include "lldb/Utility/Event.h" + +#include + +#ifndef LLDB_CORE_DEBUGGER_EVENTS_H +#define LLDB_CORE_DEBUGGER_EVENTS_H + +namespace lldb_private { +class Stream; + +class ProgressEventData : public EventData { +public: + ProgressEventData(uint64_t progress_id, const std::string &message, + uint64_t completed, uint64_t total, bool debugger_specific) + : m_message(message), m_id(progress_id), m_completed(completed), + m_total(total), m_debugger_specific(debugger_specific) {} + + static ConstString GetFlavorString(); + + ConstString GetFlavor() const override; + + void Dump(Stream *s) const override; + + static const ProgressEventData *GetEventDataFromEvent(const Event *event_ptr); + uint64_t GetID() const { return m_id; } + uint64_t GetCompleted() const { return m_completed; } + uint64_t GetTotal() const { return m_total; } + const std::string &GetMessage() const { return m_message; } + bool IsDebuggerSpecific() const { return m_debugger_specific; } + +private: + std::string m_message; + const uint64_t m_id; + uint64_t m_completed; + const uint64_t m_total; + const bool m_debugger_specific; + ProgressEventData(const ProgressEventData &) = delete; + const ProgressEventData &operator=(const ProgressEventData &) = delete; +}; +} // namespace lldb_private + +#endif // LLDB_CORE_DEBUGGER_EVENTS_H diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -35,6 +35,7 @@ #include "lldb/API/SBTypeSynthetic.h" #include "lldb/Core/Debugger.h" +#include "lldb/Core/DebuggerEvents.h" #include "lldb/Core/PluginManager.h" #include "lldb/Core/Progress.h" #include "lldb/Core/StreamFile.h" @@ -152,8 +153,8 @@ uint64_t &total, bool &is_debugger_specific) { LLDB_INSTRUMENT_VA(event); - const Debugger::ProgressEventData *progress_data = - Debugger::ProgressEventData::GetEventDataFromEvent(event.get()); + const ProgressEventData *progress_data = + ProgressEventData::GetEventDataFromEvent(event.get()); if (progress_data == nullptr) return nullptr; progress_id = progress_data->GetID(); diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt --- a/lldb/source/Core/CMakeLists.txt +++ b/lldb/source/Core/CMakeLists.txt @@ -27,6 +27,7 @@ Communication.cpp DataFileCache.cpp Debugger.cpp + DebuggerEvents.cpp Declaration.cpp Disassembler.cpp DumpDataExtractor.cpp diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp --- a/lldb/source/Core/Debugger.cpp +++ b/lldb/source/Core/Debugger.cpp @@ -9,6 +9,7 @@ #include "lldb/Core/Debugger.h" #include "lldb/Breakpoint/Breakpoint.h" +#include "lldb/Core/DebuggerEvents.h" #include "lldb/Core/FormatEntity.h" #include "lldb/Core/Mangled.h" #include "lldb/Core/ModuleList.h" @@ -1284,36 +1285,6 @@ std::make_shared(log_callback, baton); } -ConstString Debugger::ProgressEventData::GetFlavorString() { - static ConstString g_flavor("Debugger::ProgressEventData"); - return g_flavor; -} - -ConstString Debugger::ProgressEventData::GetFlavor() const { - return Debugger::ProgressEventData::GetFlavorString(); -} - -void Debugger::ProgressEventData::Dump(Stream *s) const { - s->Printf(" id = %" PRIu64 ", message = \"%s\"", m_id, m_message.c_str()); - if (m_completed == 0 || m_completed == m_total) - s->Printf(", type = %s", m_completed == 0 ? "start" : "end"); - else - s->PutCString(", type = update"); - // If m_total is UINT64_MAX, there is no progress to report, just "start" - // and "end". If it isn't we will show the completed and total amounts. - if (m_total != UINT64_MAX) - s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total); -} - -const Debugger::ProgressEventData * -Debugger::ProgressEventData::GetEventDataFromEvent(const Event *event_ptr) { - if (event_ptr) - if (const EventData *event_data = event_ptr->GetData()) - if (event_data->GetFlavor() == ProgressEventData::GetFlavorString()) - return static_cast(event_ptr->GetData()); - return nullptr; -} - static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id, const std::string &message, uint64_t completed, uint64_t total, @@ -1322,9 +1293,9 @@ const uint32_t event_type = Debugger::eBroadcastBitProgress; if (!debugger.GetBroadcaster().EventTypeHasListeners(event_type)) return; - EventSP event_sp(new Event(event_type, new Debugger::ProgressEventData( - progress_id, message, completed, - total, is_debugger_specific))); + EventSP event_sp(new Event( + event_type, new ProgressEventData(progress_id, message, completed, total, + is_debugger_specific))); debugger.GetBroadcaster().BroadcastEvent(event_sp); } @@ -1752,8 +1723,7 @@ } void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) { - auto *data = - Debugger::ProgressEventData::GetEventDataFromEvent(event_sp.get()); + auto *data = ProgressEventData::GetEventDataFromEvent(event_sp.get()); if (!data) return; diff --git a/lldb/source/Core/DebuggerEvents.cpp b/lldb/source/Core/DebuggerEvents.cpp new file mode 100644 --- /dev/null +++ b/lldb/source/Core/DebuggerEvents.cpp @@ -0,0 +1,41 @@ +//===-- DebuggerEvents.cpp ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/Core/DebuggerEvents.h" + +using namespace lldb_private; + +ConstString ProgressEventData::GetFlavorString() { + static ConstString g_flavor("ProgressEventData"); + return g_flavor; +} + +ConstString ProgressEventData::GetFlavor() const { + return ProgressEventData::GetFlavorString(); +} + +void ProgressEventData::Dump(Stream *s) const { + s->Printf(" id = %" PRIu64 ", message = \"%s\"", m_id, m_message.c_str()); + if (m_completed == 0 || m_completed == m_total) + s->Printf(", type = %s", m_completed == 0 ? "start" : "end"); + else + s->PutCString(", type = update"); + // If m_total is UINT64_MAX, there is no progress to report, just "start" + // and "end". If it isn't we will show the completed and total amounts. + if (m_total != UINT64_MAX) + s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total); +} + +const ProgressEventData * +ProgressEventData::GetEventDataFromEvent(const Event *event_ptr) { + if (event_ptr) + if (const EventData *event_data = event_ptr->GetData()) + if (event_data->GetFlavor() == ProgressEventData::GetFlavorString()) + return static_cast(event_ptr->GetData()); + return nullptr; +}