forked from OSchip/llvm-project
[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:
parent
04b717c423
commit
5e65e79bac
|
@ -57,6 +57,7 @@ class Process;
|
||||||
class Stream;
|
class Stream;
|
||||||
class SymbolContext;
|
class SymbolContext;
|
||||||
class Target;
|
class Target;
|
||||||
|
class ProgressEventData;
|
||||||
|
|
||||||
namespace repro {
|
namespace repro {
|
||||||
class DataRecorder;
|
class DataRecorder;
|
||||||
|
@ -84,39 +85,6 @@ public:
|
||||||
Broadcaster &GetBroadcaster() { return m_broadcaster; }
|
Broadcaster &GetBroadcaster() { return m_broadcaster; }
|
||||||
const Broadcaster &GetBroadcaster() const { 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;
|
~Debugger() override;
|
||||||
|
|
||||||
static lldb::DebuggerSP
|
static lldb::DebuggerSP
|
||||||
|
@ -445,7 +413,7 @@ protected:
|
||||||
uint64_t completed, uint64_t total,
|
uint64_t completed, uint64_t total,
|
||||||
llvm::Optional<lldb::user_id_t> debugger_id);
|
llvm::Optional<lldb::user_id_t> debugger_id);
|
||||||
|
|
||||||
void PrintProgress(const Debugger::ProgressEventData &data);
|
void PrintProgress(const ProgressEventData &data);
|
||||||
|
|
||||||
bool StartEventHandlerThread();
|
bool StartEventHandlerThread();
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
@ -35,6 +35,7 @@
|
||||||
#include "lldb/API/SBTypeSynthetic.h"
|
#include "lldb/API/SBTypeSynthetic.h"
|
||||||
|
|
||||||
#include "lldb/Core/Debugger.h"
|
#include "lldb/Core/Debugger.h"
|
||||||
|
#include "lldb/Core/DebuggerEvents.h"
|
||||||
#include "lldb/Core/PluginManager.h"
|
#include "lldb/Core/PluginManager.h"
|
||||||
#include "lldb/Core/Progress.h"
|
#include "lldb/Core/Progress.h"
|
||||||
#include "lldb/Core/StreamFile.h"
|
#include "lldb/Core/StreamFile.h"
|
||||||
|
@ -152,8 +153,8 @@ const char *SBDebugger::GetProgressFromEvent(const lldb::SBEvent &event,
|
||||||
uint64_t &total,
|
uint64_t &total,
|
||||||
bool &is_debugger_specific) {
|
bool &is_debugger_specific) {
|
||||||
LLDB_INSTRUMENT_VA(event);
|
LLDB_INSTRUMENT_VA(event);
|
||||||
const Debugger::ProgressEventData *progress_data =
|
const ProgressEventData *progress_data =
|
||||||
Debugger::ProgressEventData::GetEventDataFromEvent(event.get());
|
ProgressEventData::GetEventDataFromEvent(event.get());
|
||||||
if (progress_data == nullptr)
|
if (progress_data == nullptr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
progress_id = progress_data->GetID();
|
progress_id = progress_data->GetID();
|
||||||
|
|
|
@ -27,6 +27,7 @@ add_lldb_library(lldbCore
|
||||||
Communication.cpp
|
Communication.cpp
|
||||||
DataFileCache.cpp
|
DataFileCache.cpp
|
||||||
Debugger.cpp
|
Debugger.cpp
|
||||||
|
DebuggerEvents.cpp
|
||||||
Declaration.cpp
|
Declaration.cpp
|
||||||
Disassembler.cpp
|
Disassembler.cpp
|
||||||
DumpDataExtractor.cpp
|
DumpDataExtractor.cpp
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "lldb/Core/Debugger.h"
|
#include "lldb/Core/Debugger.h"
|
||||||
|
|
||||||
#include "lldb/Breakpoint/Breakpoint.h"
|
#include "lldb/Breakpoint/Breakpoint.h"
|
||||||
|
#include "lldb/Core/DebuggerEvents.h"
|
||||||
#include "lldb/Core/FormatEntity.h"
|
#include "lldb/Core/FormatEntity.h"
|
||||||
#include "lldb/Core/Mangled.h"
|
#include "lldb/Core/Mangled.h"
|
||||||
#include "lldb/Core/ModuleList.h"
|
#include "lldb/Core/ModuleList.h"
|
||||||
|
@ -1284,36 +1285,6 @@ void Debugger::SetLoggingCallback(lldb::LogOutputCallback log_callback,
|
||||||
std::make_shared<StreamCallback>(log_callback, baton);
|
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,
|
static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id,
|
||||||
const std::string &message,
|
const std::string &message,
|
||||||
uint64_t completed, uint64_t total,
|
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;
|
const uint32_t event_type = Debugger::eBroadcastBitProgress;
|
||||||
if (!debugger.GetBroadcaster().EventTypeHasListeners(event_type))
|
if (!debugger.GetBroadcaster().EventTypeHasListeners(event_type))
|
||||||
return;
|
return;
|
||||||
EventSP event_sp(new Event(event_type, new Debugger::ProgressEventData(
|
EventSP event_sp(new Event(
|
||||||
progress_id, message, completed,
|
event_type, new ProgressEventData(progress_id, message, completed, total,
|
||||||
total, is_debugger_specific)));
|
is_debugger_specific)));
|
||||||
debugger.GetBroadcaster().BroadcastEvent(event_sp);
|
debugger.GetBroadcaster().BroadcastEvent(event_sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1752,8 +1723,7 @@ lldb::thread_result_t Debugger::IOHandlerThread() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
|
void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
|
||||||
auto *data =
|
auto *data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
|
||||||
Debugger::ProgressEventData::GetEventDataFromEvent(event_sp.get());
|
|
||||||
if (!data)
|
if (!data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue