[Lldb-commits] [PATCH] D143687: [lldb] Add an SB API to get progress events as SBStructuredData

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 9 15:28:16 PST 2023


JDevlieghere created this revision.
JDevlieghere added reviewers: clayborg, mib, kastiglione, bulbazord.
Herald added a project: All.
JDevlieghere requested review of this revision.

This is a preparatory patch to add an SB API to get the progress data as SBStructuredData. The approach is identical to the one taken for `SBDebugger::GetDiagnosticFromEvent`. By returning SBStructuredData we can grow the dictionary over time with more fields, which is what my follow up patch does.


https://reviews.llvm.org/D143687

Files:
  lldb/bindings/interface/SBDebugger.i
  lldb/include/lldb/API/SBDebugger.h
  lldb/source/API/SBDebugger.cpp
  lldb/test/API/functionalities/progress_reporting/TestProgressReporting.py


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)
+
Index: lldb/source/API/SBDebugger.cpp
===================================================================
--- lldb/source/API/SBDebugger.cpp
+++ lldb/source/API/SBDebugger.cpp
@@ -168,6 +168,28 @@
   return progress_data->GetMessage().c_str();
 }
 
+lldb::SBStructuredData
+SBDebugger::GetProgressDataFromEvent(const lldb::SBEvent &event) {
+  LLDB_INSTRUMENT_VA(event);
+
+  const ProgressEventData *progress_data =
+      ProgressEventData::GetEventDataFromEvent(event.get());
+  if (!progress_data)
+    return {};
+
+  auto dictionary = std::make_unique<StructuredData::Dictionary>();
+  dictionary->AddStringItem("message", progress_data->GetMessage());
+  dictionary->AddIntegerItem("progress_id", progress_data->GetID());
+  dictionary->AddIntegerItem("completed", progress_data->GetCompleted());
+  dictionary->AddIntegerItem("total", progress_data->GetTotal());
+  dictionary->AddBooleanItem("debugger_specific",
+                             progress_data->IsDebuggerSpecific());
+
+  SBStructuredData data;
+  data.m_impl_up->SetObjectSP(std::move(dictionary));
+  return data;
+}
+
 lldb::SBStructuredData
 SBDebugger::GetDiagnosticFromEvent(const lldb::SBEvent &event) {
   LLDB_INSTRUMENT_VA(event);
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/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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143687.496261.patch
Type: text/x-patch
Size: 3291 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230209/9ba43d56/attachment-0001.bin>


More information about the lldb-commits mailing list