[Lldb-commits] [PATCH] D141702: [lldb/crashlog] Make module loading use Scripted Process affordance

Med Ismail Bennani via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Jan 13 16:34:13 PST 2023


mib updated this revision to Diff 489152.
mib added a comment.

Only force symbol lookup for crashlog scripted process.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141702/new/

https://reviews.llvm.org/D141702

Files:
  lldb/examples/python/scripted_process/crashlog_scripted_process.py
  lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp


Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
===================================================================
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -11,7 +11,7 @@
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/Module.h"
 #include "lldb/Core/PluginManager.h"
-
+#include "lldb/Core/Progress.h"
 #include "lldb/Host/OptionParser.h"
 #include "lldb/Host/ThreadLauncher.h"
 #include "lldb/Interpreter/CommandInterpreter.h"
@@ -19,6 +19,7 @@
 #include "lldb/Interpreter/OptionGroupBoolean.h"
 #include "lldb/Interpreter/ScriptInterpreter.h"
 #include "lldb/Interpreter/ScriptedMetadata.h"
+#include "lldb/Symbol/LocateSymbolFile.h"
 #include "lldb/Target/MemoryRegionInfo.h"
 #include "lldb/Target/Queue.h"
 #include "lldb/Target/RegisterContext.h"
@@ -410,15 +411,19 @@
 
   StructuredData::ArraySP loaded_images_sp = GetInterface().GetLoadedImages();
 
-  if (!loaded_images_sp || !loaded_images_sp->GetSize())
+  size_t num_image_to_load = loaded_images_sp->GetSize();
+  if (!loaded_images_sp || !num_image_to_load)
     return ScriptedInterface::ErrorWithMessage<StructuredData::ObjectSP>(
         LLVM_PRETTY_FUNCTION, "No loaded images.", error);
 
   ModuleList module_list;
   Target &target = GetTarget();
+  bool force_lookup = m_scripted_metadata.GetClassName().contains("CrashLog");
 
-  auto reload_image = [&target, &module_list, &error_with_message](
-                          StructuredData::Object *obj) -> bool {
+  Progress progress("Fetching external dependencies", num_image_to_load);
+  auto reload_image = [&target, &module_list, &error_with_message, &progress,
+                       &force_lookup](StructuredData::Object *obj) -> bool {
+    progress.Increment();
     StructuredData::Dictionary *dict = obj->GetAsDictionary();
 
     if (!dict)
@@ -445,6 +450,13 @@
     }
     module_spec.GetArchitecture() = target.GetArchitecture();
 
+    Status error;
+    if (!Symbols::DownloadObjectAndSymbolFile(module_spec, error,
+                                              force_lookup) ||
+        error.Fail() ||
+        !FileSystem::Instance().Exists(module_spec.GetFileSpec()))
+      return error_with_message(error.AsCString());
+
     ModuleSP module_sp =
         target.GetOrCreateModule(module_spec, true /* notify */);
 
@@ -469,9 +481,11 @@
     if (!changed && !module_sp->GetObjectFile())
       return error_with_message("Couldn't set the load address for module.");
 
-    dict->GetValueForKeyAsString("path", value);
-    FileSpec objfile(value);
-    module_sp->SetFileSpecAndObjectName(objfile, objfile.GetFilename());
+    if (has_path) {
+      dict->GetValueForKeyAsString("path", value);
+      FileSpec objfile(value);
+      module_sp->SetFileSpecAndObjectName(objfile, objfile.GetFilename());
+    }
 
     return module_list.AppendIfNeeded(module_sp);
   };
Index: lldb/examples/python/scripted_process/crashlog_scripted_process.py
===================================================================
--- lldb/examples/python/scripted_process/crashlog_scripted_process.py
+++ lldb/examples/python/scripted_process/crashlog_scripted_process.py
@@ -31,12 +31,10 @@
                     if image not in self.loaded_images:
                         if image.uuid == uuid.UUID(int=0):
                             continue
-                        err = image.add_module(self.target)
-                        if err:
-                            # Append to SBCommandReturnObject
-                            print(err)
-                        else:
-                            self.loaded_images.append(image)
+                        for section in image.section_infos:
+                            if section.start_addr and section.name == "__TEXT":
+                                self.loaded_images.append({"uuid": str(image.uuid),
+                                                           "load_addr": section.start_addr})
 
         for thread in crash_log.threads:
             if self.load_all_images:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141702.489152.patch
Type: text/x-patch
Size: 4077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230114/422b0f15/attachment-0001.bin>


More information about the lldb-commits mailing list