[Lldb-commits] [lldb] 0ac8dfd - [lldb] Add an SB API to get progress events as SBStructuredData
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Fri Feb 10 17:18:06 PST 2023
Author: Jonas Devlieghere
Date: 2023-02-10T17:18:00-08:00
New Revision: 0ac8dfd0587a1a95e8ed464bc59741837aae9c1f
URL: https://github.com/llvm/llvm-project/commit/0ac8dfd0587a1a95e8ed464bc59741837aae9c1f
DIFF: https://github.com/llvm/llvm-project/commit/0ac8dfd0587a1a95e8ed464bc59741837aae9c1f.diff
LOG: [lldb] Add an SB API to get progress events as SBStructuredData
This is a preparatory patch to add an SB API to get the progress data as
SBStructuredData. The advantage of using SBStructuredData is that the
dictionary can grow over time with more fields.
This approach is identical to the way this is implemented for diagnostic
events.
Differential revision: https://reviews.llvm.org/D143687
Added:
Modified:
lldb/bindings/interface/SBDebugger.i
lldb/include/lldb/API/SBDebugger.h
lldb/include/lldb/Core/DebuggerEvents.h
lldb/source/API/SBDebugger.cpp
lldb/source/Core/DebuggerEvents.cpp
lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
Removed:
################################################################################
diff --git a/lldb/bindings/interface/SBDebugger.i b/lldb/bindings/interface/SBDebugger.i
index e82ce2aa8e7c..7132902275ff 100644
--- a/lldb/bindings/interface/SBDebugger.i
+++ b/lldb/bindings/interface/SBDebugger.i
@@ -131,6 +131,8 @@ public:
uint64_t &OUTPUT,
bool &OUTPUT);
+ static lldb::SBStructuredData GetProgressDataFromEvent(const lldb::SBEvent &event);
+
static lldb::SBStructuredData GetDiagnosticFromEvent(const lldb::SBEvent &event);
SBBroadcaster GetBroadcaster();
diff --git a/lldb/include/lldb/API/SBDebugger.h b/lldb/include/lldb/API/SBDebugger.h
index 950e8e29ef79..0aee6b7dbddf 100644
--- a/lldb/include/lldb/API/SBDebugger.h
+++ b/lldb/include/lldb/API/SBDebugger.h
@@ -83,6 +83,9 @@ class LLDB_API SBDebugger {
uint64_t &completed, uint64_t &total,
bool &is_debugger_specific);
+ static lldb::SBStructuredData
+ GetProgressDataFromEvent(const lldb::SBEvent &event);
+
static lldb::SBStructuredData
GetDiagnosticFromEvent(const lldb::SBEvent &event);
diff --git a/lldb/include/lldb/Core/DebuggerEvents.h b/lldb/include/lldb/Core/DebuggerEvents.h
index 7d22574aa03e..0dade0f9629a 100644
--- a/lldb/include/lldb/Core/DebuggerEvents.h
+++ b/lldb/include/lldb/Core/DebuggerEvents.h
@@ -33,6 +33,10 @@ class ProgressEventData : public EventData {
void Dump(Stream *s) const override;
static const ProgressEventData *GetEventDataFromEvent(const Event *event_ptr);
+
+ static StructuredData::DictionarySP
+ GetAsStructuredData(const Event *event_ptr);
+
uint64_t GetID() const { return m_id; }
bool IsFinite() const { return m_total != UINT64_MAX; }
uint64_t GetCompleted() const { return m_completed; }
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index be86078c7203..2fa93e47a44c 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -168,6 +168,21 @@ const char *SBDebugger::GetProgressFromEvent(const lldb::SBEvent &event,
return progress_data->GetMessage().c_str();
}
+lldb::SBStructuredData
+SBDebugger::GetProgressDataFromEvent(const lldb::SBEvent &event) {
+ LLDB_INSTRUMENT_VA(event);
+
+ StructuredData::DictionarySP dictionary_sp =
+ ProgressEventData::GetAsStructuredData(event.get());
+
+ if (!dictionary_sp)
+ return {};
+
+ SBStructuredData data;
+ data.m_impl_up->SetObjectSP(std::move(dictionary_sp));
+ return data;
+}
+
lldb::SBStructuredData
SBDebugger::GetDiagnosticFromEvent(const lldb::SBEvent &event) {
LLDB_INSTRUMENT_VA(event);
diff --git a/lldb/source/Core/DebuggerEvents.cpp b/lldb/source/Core/DebuggerEvents.cpp
index 6e47da7abd2c..fd459f899aba 100644
--- a/lldb/source/Core/DebuggerEvents.cpp
+++ b/lldb/source/Core/DebuggerEvents.cpp
@@ -49,6 +49,25 @@ ProgressEventData::GetEventDataFromEvent(const Event *event_ptr) {
return GetEventDataFromEventImpl<ProgressEventData>(event_ptr);
}
+StructuredData::DictionarySP
+ProgressEventData::GetAsStructuredData(const Event *event_ptr) {
+ const ProgressEventData *progress_data =
+ ProgressEventData::GetEventDataFromEvent(event_ptr);
+
+ if (!progress_data)
+ return {};
+
+ auto dictionary_sp = std::make_shared<StructuredData::Dictionary>();
+ dictionary_sp->AddStringItem("message", progress_data->GetMessage());
+ dictionary_sp->AddIntegerItem("progress_id", progress_data->GetID());
+ dictionary_sp->AddIntegerItem("completed", progress_data->GetCompleted());
+ dictionary_sp->AddIntegerItem("total", progress_data->GetTotal());
+ dictionary_sp->AddBooleanItem("debugger_specific",
+ progress_data->IsDebuggerSpecific());
+
+ return dictionary_sp;
+}
+
llvm::StringRef DiagnosticEventData::GetPrefix() const {
switch (m_type) {
case Type::Info:
diff --git a/lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py b/lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
index 164ccbf72bf8..8d1821e4e92d 100644
--- a/lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
+++ b/lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py
@@ -28,3 +28,14 @@ def test_dwarf_symbol_loading_progress_report(self):
message = ret_args[0]
self.assertGreater(len(message), 0)
+ def test_dwarf_symbol_loading_progress_report_structured_data(self):
+ """Test that we are able to fetch dwarf symbol loading progress events
+ using the structured data API"""
+ self.build()
+
+ lldbutil.run_to_source_breakpoint(self, 'break here', lldb.SBFileSpec('main.c'))
+
+ event = lldbutil.fetch_next_event(self, self.listener, self.broadcaster)
+ progress_data = lldb.SBDebugger.GetProgressDataFromEvent(event)
+ message = progress_data.GetValueForKey("message").GetStringValue(100)
+ self.assertGreater(len(message), 0)
More information about the lldb-commits
mailing list