Index: lldb/bindings/interface/SBDebugger.i =================================================================== --- lldb/bindings/interface/SBDebugger.i +++ lldb/bindings/interface/SBDebugger.i @@ -131,6 +131,8 @@ uint64_t &OUTPUT, bool &OUTPUT); + static lldb::SBStructuredData GetProgressDataFromEvent(const lldb::SBEvent &event); + static lldb::SBStructuredData GetDiagnosticFromEvent(const lldb::SBEvent &event); SBBroadcaster GetBroadcaster(); Index: lldb/include/lldb/API/SBDebugger.h =================================================================== --- lldb/include/lldb/API/SBDebugger.h +++ lldb/include/lldb/API/SBDebugger.h @@ -83,6 +83,9 @@ 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); Index: lldb/include/lldb/Core/DebuggerEvents.h =================================================================== --- lldb/include/lldb/Core/DebuggerEvents.h +++ lldb/include/lldb/Core/DebuggerEvents.h @@ -33,6 +33,10 @@ 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; } Index: lldb/source/API/SBDebugger.cpp =================================================================== --- lldb/source/API/SBDebugger.cpp +++ lldb/source/API/SBDebugger.cpp @@ -168,6 +168,21 @@ 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); Index: lldb/source/Core/DebuggerEvents.cpp =================================================================== --- lldb/source/Core/DebuggerEvents.cpp +++ lldb/source/Core/DebuggerEvents.cpp @@ -49,6 +49,25 @@ return GetEventDataFromEventImpl(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(); + 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: Index: lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py =================================================================== --- lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py +++ lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py @@ -28,3 +28,14 @@ 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) +