[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
This commit is contained in:
Jonas Devlieghere 2022-03-14 09:01:53 -07:00
parent 04b717c423
commit 5e65e79bac
No known key found for this signature in database
GPG Key ID: 49CC0BD90FDEED4D
6 changed files with 103 additions and 71 deletions

View File

@ -57,6 +57,7 @@ class Process;
class Stream;
class SymbolContext;
class Target;
class ProgressEventData;
namespace repro {
class DataRecorder;
@ -84,39 +85,6 @@ public:
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 @@ protected:
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();

View File

@ -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

View File

@ -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();

View File

@ -27,6 +27,7 @@ add_lldb_library(lldbCore
Communication.cpp
DataFileCache.cpp
Debugger.cpp
DebuggerEvents.cpp
Declaration.cpp
Disassembler.cpp
DumpDataExtractor.cpp

View File

@ -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;

View File

@ -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;
}