[Lldb-commits] [lldb] 5e65e79 - [lldb] Move ProgressEventData out of debugger and into its own file (NFC)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Mon Mar 14 09:24:35 PDT 2022
Author: Jonas Devlieghere
Date: 2022-03-14T09:24:17-07:00
New Revision: 5e65e79bace6127da493de1445161f1179e4e47f
URL: https://github.com/llvm/llvm-project/commit/5e65e79bace6127da493de1445161f1179e4e47f
DIFF: https://github.com/llvm/llvm-project/commit/5e65e79bace6127da493de1445161f1179e4e47f.diff
LOG: [lldb] Move ProgressEventData out of debugger and into its own file (NFC)
Move ProgressEventData out of debugger and into its own file. This is in
preparation of adding a few new type of event data for diagnostics.
Differential revision: https://reviews.llvm.org/D121506
Added:
lldb/include/lldb/Core/DebuggerEvents.h
lldb/source/Core/DebuggerEvents.cpp
Modified:
lldb/include/lldb/Core/Debugger.h
lldb/source/API/SBDebugger.cpp
lldb/source/Core/CMakeLists.txt
lldb/source/Core/Debugger.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/Debugger.h b/lldb/include/lldb/Core/Debugger.h
index dbdb1431f3d59..8fd22413d8181 100644
--- a/lldb/include/lldb/Core/Debugger.h
+++ b/lldb/include/lldb/Core/Debugger.h
@@ -57,6 +57,7 @@ class Process;
class Stream;
class SymbolContext;
class Target;
+class ProgressEventData;
namespace repro {
class DataRecorder;
@@ -84,39 +85,6 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
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 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
uint64_t completed, uint64_t total,
llvm::Optional<lldb::user_id_t> 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
index 0000000000000..749bcc86f3720
--- /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 <string>
+
+#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
index c3d1a9817c5e4..72b5f5742fa04 100644
--- 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 @@ const char *SBDebugger::GetProgressFromEvent(const lldb::SBEvent &event,
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
index c33aabddc7d1d..0efaab53f3132 100644
--- a/lldb/source/Core/CMakeLists.txt
+++ b/lldb/source/Core/CMakeLists.txt
@@ -27,6 +27,7 @@ add_lldb_library(lldbCore
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
index 57e7ca4588f3d..d59c1e0891050 100644
--- 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 @@ void Debugger::SetLoggingCallback(lldb::LogOutputCallback log_callback,
std::make_shared<StreamCallback>(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<const ProgressEventData *>(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 @@ static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id,
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 @@ lldb::thread_result_t Debugger::IOHandlerThread() {
}
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
index 0000000000000..e3af32e0eb175
--- /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<const ProgressEventData *>(event_ptr->GetData());
+ return nullptr;
+}
More information about the lldb-commits
mailing list