Skip to content

Commit 5e65e79

Browse files
committed
[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
1 parent 04b717c commit 5e65e79

File tree

6 files changed

+103
-71
lines changed

6 files changed

+103
-71
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Process;
5757
class Stream;
5858
class SymbolContext;
5959
class Target;
60+
class ProgressEventData;
6061

6162
namespace repro {
6263
class DataRecorder;
@@ -84,39 +85,6 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
8485
Broadcaster &GetBroadcaster() { return m_broadcaster; }
8586
const Broadcaster &GetBroadcaster() const { return m_broadcaster; }
8687

87-
class ProgressEventData : public EventData {
88-
89-
public:
90-
ProgressEventData(uint64_t progress_id, const std::string &message,
91-
uint64_t completed, uint64_t total,
92-
bool debugger_specific)
93-
: m_message(message), m_id(progress_id), m_completed(completed),
94-
m_total(total), m_debugger_specific(debugger_specific) {}
95-
96-
static ConstString GetFlavorString();
97-
98-
ConstString GetFlavor() const override;
99-
100-
void Dump(Stream *s) const override;
101-
102-
static const ProgressEventData *
103-
GetEventDataFromEvent(const Event *event_ptr);
104-
uint64_t GetID() const { return m_id; }
105-
uint64_t GetCompleted() const { return m_completed; }
106-
uint64_t GetTotal() const { return m_total; }
107-
const std::string &GetMessage() const { return m_message; }
108-
bool IsDebuggerSpecific() const { return m_debugger_specific; }
109-
110-
private:
111-
std::string m_message;
112-
const uint64_t m_id;
113-
uint64_t m_completed;
114-
const uint64_t m_total;
115-
const bool m_debugger_specific;
116-
ProgressEventData(const ProgressEventData &) = delete;
117-
const ProgressEventData &operator=(const ProgressEventData &) = delete;
118-
};
119-
12088
~Debugger() override;
12189

12290
static lldb::DebuggerSP
@@ -445,7 +413,7 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
445413
uint64_t completed, uint64_t total,
446414
llvm::Optional<lldb::user_id_t> debugger_id);
447415

448-
void PrintProgress(const Debugger::ProgressEventData &data);
416+
void PrintProgress(const ProgressEventData &data);
449417

450418
bool StartEventHandlerThread();
451419

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
uint64_t GetCompleted() const { return m_completed; }
36+
uint64_t GetTotal() const { return m_total; }
37+
const std::string &GetMessage() const { return m_message; }
38+
bool IsDebuggerSpecific() const { return m_debugger_specific; }
39+
40+
private:
41+
std::string m_message;
42+
const uint64_t m_id;
43+
uint64_t m_completed;
44+
const uint64_t m_total;
45+
const bool m_debugger_specific;
46+
ProgressEventData(const ProgressEventData &) = delete;
47+
const ProgressEventData &operator=(const ProgressEventData &) = delete;
48+
};
49+
} // namespace lldb_private
50+
51+
#endif // LLDB_CORE_DEBUGGER_EVENTS_H

lldb/source/API/SBDebugger.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "lldb/API/SBTypeSynthetic.h"
3636

3737
#include "lldb/Core/Debugger.h"
38+
#include "lldb/Core/DebuggerEvents.h"
3839
#include "lldb/Core/PluginManager.h"
3940
#include "lldb/Core/Progress.h"
4041
#include "lldb/Core/StreamFile.h"
@@ -152,8 +153,8 @@ const char *SBDebugger::GetProgressFromEvent(const lldb::SBEvent &event,
152153
uint64_t &total,
153154
bool &is_debugger_specific) {
154155
LLDB_INSTRUMENT_VA(event);
155-
const Debugger::ProgressEventData *progress_data =
156-
Debugger::ProgressEventData::GetEventDataFromEvent(event.get());
156+
const ProgressEventData *progress_data =
157+
ProgressEventData::GetEventDataFromEvent(event.get());
157158
if (progress_data == nullptr)
158159
return nullptr;
159160
progress_id = progress_data->GetID();

lldb/source/Core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ add_lldb_library(lldbCore
2727
Communication.cpp
2828
DataFileCache.cpp
2929
Debugger.cpp
30+
DebuggerEvents.cpp
3031
Declaration.cpp
3132
Disassembler.cpp
3233
DumpDataExtractor.cpp

lldb/source/Core/Debugger.cpp

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "lldb/Core/Debugger.h"
1010

1111
#include "lldb/Breakpoint/Breakpoint.h"
12+
#include "lldb/Core/DebuggerEvents.h"
1213
#include "lldb/Core/FormatEntity.h"
1314
#include "lldb/Core/Mangled.h"
1415
#include "lldb/Core/ModuleList.h"
@@ -1284,36 +1285,6 @@ void Debugger::SetLoggingCallback(lldb::LogOutputCallback log_callback,
12841285
std::make_shared<StreamCallback>(log_callback, baton);
12851286
}
12861287

1287-
ConstString Debugger::ProgressEventData::GetFlavorString() {
1288-
static ConstString g_flavor("Debugger::ProgressEventData");
1289-
return g_flavor;
1290-
}
1291-
1292-
ConstString Debugger::ProgressEventData::GetFlavor() const {
1293-
return Debugger::ProgressEventData::GetFlavorString();
1294-
}
1295-
1296-
void Debugger::ProgressEventData::Dump(Stream *s) const {
1297-
s->Printf(" id = %" PRIu64 ", message = \"%s\"", m_id, m_message.c_str());
1298-
if (m_completed == 0 || m_completed == m_total)
1299-
s->Printf(", type = %s", m_completed == 0 ? "start" : "end");
1300-
else
1301-
s->PutCString(", type = update");
1302-
// If m_total is UINT64_MAX, there is no progress to report, just "start"
1303-
// and "end". If it isn't we will show the completed and total amounts.
1304-
if (m_total != UINT64_MAX)
1305-
s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total);
1306-
}
1307-
1308-
const Debugger::ProgressEventData *
1309-
Debugger::ProgressEventData::GetEventDataFromEvent(const Event *event_ptr) {
1310-
if (event_ptr)
1311-
if (const EventData *event_data = event_ptr->GetData())
1312-
if (event_data->GetFlavor() == ProgressEventData::GetFlavorString())
1313-
return static_cast<const ProgressEventData *>(event_ptr->GetData());
1314-
return nullptr;
1315-
}
1316-
13171288
static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id,
13181289
const std::string &message,
13191290
uint64_t completed, uint64_t total,
@@ -1322,9 +1293,9 @@ static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id,
13221293
const uint32_t event_type = Debugger::eBroadcastBitProgress;
13231294
if (!debugger.GetBroadcaster().EventTypeHasListeners(event_type))
13241295
return;
1325-
EventSP event_sp(new Event(event_type, new Debugger::ProgressEventData(
1326-
progress_id, message, completed,
1327-
total, is_debugger_specific)));
1296+
EventSP event_sp(new Event(
1297+
event_type, new ProgressEventData(progress_id, message, completed, total,
1298+
is_debugger_specific)));
13281299
debugger.GetBroadcaster().BroadcastEvent(event_sp);
13291300
}
13301301

@@ -1752,8 +1723,7 @@ lldb::thread_result_t Debugger::IOHandlerThread() {
17521723
}
17531724

17541725
void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
1755-
auto *data =
1756-
Debugger::ProgressEventData::GetEventDataFromEvent(event_sp.get());
1726+
auto *data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
17571727
if (!data)
17581728
return;
17591729

lldb/source/Core/DebuggerEvents.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===-- DebuggerEvents.cpp ------------------------------------------------===//
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/Core/DebuggerEvents.h"
10+
11+
using namespace lldb_private;
12+
13+
ConstString ProgressEventData::GetFlavorString() {
14+
static ConstString g_flavor("ProgressEventData");
15+
return g_flavor;
16+
}
17+
18+
ConstString ProgressEventData::GetFlavor() const {
19+
return ProgressEventData::GetFlavorString();
20+
}
21+
22+
void ProgressEventData::Dump(Stream *s) const {
23+
s->Printf(" id = %" PRIu64 ", message = \"%s\"", m_id, m_message.c_str());
24+
if (m_completed == 0 || m_completed == m_total)
25+
s->Printf(", type = %s", m_completed == 0 ? "start" : "end");
26+
else
27+
s->PutCString(", type = update");
28+
// If m_total is UINT64_MAX, there is no progress to report, just "start"
29+
// and "end". If it isn't we will show the completed and total amounts.
30+
if (m_total != UINT64_MAX)
31+
s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total);
32+
}
33+
34+
const ProgressEventData *
35+
ProgressEventData::GetEventDataFromEvent(const Event *event_ptr) {
36+
if (event_ptr)
37+
if (const EventData *event_data = event_ptr->GetData())
38+
if (event_data->GetFlavor() == ProgressEventData::GetFlavorString())
39+
return static_cast<const ProgressEventData *>(event_ptr->GetData());
40+
return nullptr;
41+
}

0 commit comments

Comments
 (0)