Skip to content

Commit 607208f

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 (cherry picked from commit 5e65e79)
1 parent 21c0536 commit 607208f

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
@@ -454,7 +422,7 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
454422
uint64_t completed, uint64_t total,
455423
llvm::Optional<lldb::user_id_t> debugger_id);
456424

457-
void PrintProgress(const Debugger::ProgressEventData &data);
425+
void PrintProgress(const ProgressEventData &data);
458426

459427
bool StartEventHandlerThread();
460428

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
@@ -26,6 +26,7 @@ add_lldb_library(lldbCore
2626
AddressResolverFileLine.cpp
2727
Communication.cpp
2828
Debugger.cpp
29+
DebuggerEvents.cpp
2930
Declaration.cpp
3031
Disassembler.cpp
3132
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"
@@ -1323,36 +1324,6 @@ void Debugger::SetLoggingCallback(lldb::LogOutputCallback log_callback,
13231324
std::make_shared<StreamCallback>(log_callback, baton);
13241325
}
13251326

1326-
ConstString Debugger::ProgressEventData::GetFlavorString() {
1327-
static ConstString g_flavor("Debugger::ProgressEventData");
1328-
return g_flavor;
1329-
}
1330-
1331-
ConstString Debugger::ProgressEventData::GetFlavor() const {
1332-
return Debugger::ProgressEventData::GetFlavorString();
1333-
}
1334-
1335-
void Debugger::ProgressEventData::Dump(Stream *s) const {
1336-
s->Printf(" id = %" PRIu64 ", message = \"%s\"", m_id, m_message.c_str());
1337-
if (m_completed == 0 || m_completed == m_total)
1338-
s->Printf(", type = %s", m_completed == 0 ? "start" : "end");
1339-
else
1340-
s->PutCString(", type = update");
1341-
// If m_total is UINT64_MAX, there is no progress to report, just "start"
1342-
// and "end". If it isn't we will show the completed and total amounts.
1343-
if (m_total != UINT64_MAX)
1344-
s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total);
1345-
}
1346-
1347-
const Debugger::ProgressEventData *
1348-
Debugger::ProgressEventData::GetEventDataFromEvent(const Event *event_ptr) {
1349-
if (event_ptr)
1350-
if (const EventData *event_data = event_ptr->GetData())
1351-
if (event_data->GetFlavor() == ProgressEventData::GetFlavorString())
1352-
return static_cast<const ProgressEventData *>(event_ptr->GetData());
1353-
return nullptr;
1354-
}
1355-
13561327
static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id,
13571328
const std::string &message,
13581329
uint64_t completed, uint64_t total,
@@ -1361,9 +1332,9 @@ static void PrivateReportProgress(Debugger &debugger, uint64_t progress_id,
13611332
const uint32_t event_type = Debugger::eBroadcastBitProgress;
13621333
if (!debugger.GetBroadcaster().EventTypeHasListeners(event_type))
13631334
return;
1364-
EventSP event_sp(new Event(event_type, new Debugger::ProgressEventData(
1365-
progress_id, message, completed,
1366-
total, is_debugger_specific)));
1335+
EventSP event_sp(new Event(
1336+
event_type, new ProgressEventData(progress_id, message, completed, total,
1337+
is_debugger_specific)));
13671338
debugger.GetBroadcaster().BroadcastEvent(event_sp);
13681339
}
13691340

@@ -1808,8 +1779,7 @@ lldb::thread_result_t Debugger::IOHandlerThread(lldb::thread_arg_t arg) {
18081779
}
18091780

18101781
void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
1811-
auto *data =
1812-
Debugger::ProgressEventData::GetEventDataFromEvent(event_sp.get());
1782+
auto *data = ProgressEventData::GetEventDataFromEvent(event_sp.get());
18131783
if (!data)
18141784
return;
18151785

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)