[Lldb-commits] [lldb] 0975e2a - [LLDB][Minidump] Add a progress bar to minidump (#108309)

via lldb-commits lldb-commits at lists.llvm.org
Mon Sep 16 15:13:39 PDT 2024


Author: Jacob Lalonde
Date: 2024-09-16T15:13:35-07:00
New Revision: 0975e2ac58b6d62429d51df54911fb4d03dcda05

URL: https://github.com/llvm/llvm-project/commit/0975e2ac58b6d62429d51df54911fb4d03dcda05
DIFF: https://github.com/llvm/llvm-project/commit/0975e2ac58b6d62429d51df54911fb4d03dcda05.diff

LOG: [LLDB][Minidump] Add a progress bar to minidump (#108309)

Added a progress tracker to Minidump file builders memory saving

Added: 
    

Modified: 
    lldb/include/lldb/Target/CoreFileMemoryRanges.h
    lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
    lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Target/CoreFileMemoryRanges.h b/lldb/include/lldb/Target/CoreFileMemoryRanges.h
index 503ecd691e5948..0cc5433525ddc4 100644
--- a/lldb/include/lldb/Target/CoreFileMemoryRanges.h
+++ b/lldb/include/lldb/Target/CoreFileMemoryRanges.h
@@ -8,6 +8,7 @@
 
 #include "lldb/Utility/RangeMap.h"
 #include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
 
 #include "llvm/ADT/AddressRanges.h"
 
@@ -35,6 +36,16 @@ struct CoreFileMemoryRange {
       return lldb_permissions < rhs.lldb_permissions;
     return false;
   }
+
+  std::string Dump() const {
+    lldb_private::StreamString stream;
+    stream << "[";
+    stream.PutHex64(range.start());
+    stream << '-';
+    stream.PutHex64(range.end());
+    stream << ")";
+    return stream.GetString().str();
+  }
 };
 
 class CoreFileMemoryRanges

diff  --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
index ca22dacb2ba6c9..3f1e25f730a184 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp
@@ -837,15 +837,17 @@ Status MinidumpFileBuilder::AddMemoryList() {
   error = m_process_sp->CalculateCoreFileSaveRanges(m_save_core_options,
                                                     all_core_memory_ranges);
 
+  if (error.Fail())
+    return error;
+
+  lldb_private::Progress progress("Saving Minidump File", "",
+                                  all_core_memory_ranges.GetSize());
   std::vector<CoreFileMemoryRange> all_core_memory_vec;
   // Extract all the data into just a vector of data. So we can mutate this in
   // place.
   for (const auto &core_range : all_core_memory_ranges)
     all_core_memory_vec.push_back(core_range.data);
 
-  if (error.Fail())
-    return error;
-
   // Start by saving all of the stacks and ensuring they fit under the 32b
   // limit.
   uint64_t total_size = GetCurrentDataEndOffset();
@@ -892,13 +894,13 @@ Status MinidumpFileBuilder::AddMemoryList() {
     }
   }
 
-  error = AddMemoryList_32(ranges_32);
+  error = AddMemoryList_32(ranges_32, progress);
   if (error.Fail())
     return error;
 
   // Add the remaining memory as a 64b range.
   if (!ranges_64.empty()) {
-    error = AddMemoryList_64(ranges_64);
+    error = AddMemoryList_64(ranges_64, progress);
     if (error.Fail())
       return error;
   }
@@ -972,8 +974,9 @@ GetLargestRangeSize(const std::vector<CoreFileMemoryRange> &ranges) {
   return max_size;
 }
 
-Status MinidumpFileBuilder::AddMemoryList_32(
-    std::vector<CoreFileMemoryRange> &ranges) {
+Status
+MinidumpFileBuilder::AddMemoryList_32(std::vector<CoreFileMemoryRange> &ranges,
+                                      Progress &progress) {
   std::vector<MemoryDescriptor> descriptors;
   Status error;
   if (ranges.size() == 0)
@@ -996,6 +999,7 @@ Status MinidumpFileBuilder::AddMemoryList_32(
               region_index, ranges.size(), size, addr, addr + size);
     ++region_index;
 
+    progress.Increment(1, "Adding Memory Range " + core_range.Dump());
     const size_t bytes_read =
         m_process_sp->ReadMemory(addr, data_up->GetBytes(), size, error);
     if (error.Fail() || bytes_read == 0) {
@@ -1049,8 +1053,9 @@ Status MinidumpFileBuilder::AddMemoryList_32(
   return error;
 }
 
-Status MinidumpFileBuilder::AddMemoryList_64(
-    std::vector<CoreFileMemoryRange> &ranges) {
+Status
+MinidumpFileBuilder::AddMemoryList_64(std::vector<CoreFileMemoryRange> &ranges,
+                                      Progress &progress) {
   Status error;
   if (ranges.empty())
     return error;
@@ -1111,6 +1116,7 @@ Status MinidumpFileBuilder::AddMemoryList_64(
               region_index, ranges.size(), size, addr, addr + size);
     ++region_index;
 
+    progress.Increment(1, "Adding Memory Range " + core_range.Dump());
     const size_t bytes_read =
         m_process_sp->ReadMemory(addr, data_up->GetBytes(), size, error);
     if (error.Fail()) {

diff  --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
index 72e5658718b3c4..d5eac9015ac422 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
@@ -23,6 +23,7 @@
 #include <utility>
 #include <variant>
 
+#include "lldb/Core/Progress.h"
 #include "lldb/Symbol/SaveCoreOptions.h"
 #include "lldb/Target/Process.h"
 #include "lldb/Target/Target.h"
@@ -79,7 +80,7 @@ class MinidumpFileBuilder {
                       const lldb::ProcessSP &process_sp,
                       lldb_private::SaveCoreOptions &save_core_options)
       : m_process_sp(process_sp), m_core_file(std::move(core_file)),
-        m_save_core_options(save_core_options){}
+        m_save_core_options(save_core_options) {}
 
   MinidumpFileBuilder(const MinidumpFileBuilder &) = delete;
   MinidumpFileBuilder &operator=(const MinidumpFileBuilder &) = delete;
@@ -124,9 +125,11 @@ class MinidumpFileBuilder {
   lldb_private::Status AddData(const void *data, uint64_t size);
   // Add MemoryList stream, containing dumps of important memory segments
   lldb_private::Status
-  AddMemoryList_64(std::vector<lldb_private::CoreFileMemoryRange> &ranges);
+  AddMemoryList_64(std::vector<lldb_private::CoreFileMemoryRange> &ranges,
+                   lldb_private::Progress &progress);
   lldb_private::Status
-  AddMemoryList_32(std::vector<lldb_private::CoreFileMemoryRange> &ranges);
+  AddMemoryList_32(std::vector<lldb_private::CoreFileMemoryRange> &ranges,
+                   lldb_private::Progress &progress);
   // Update the thread list on disk with the newly emitted stack RVAs.
   lldb_private::Status FixThreadStacks();
   lldb_private::Status FlushBufferToDisk();


        


More information about the lldb-commits mailing list