[lldb] Parse the crashlog only once
authorJonas Devlieghere <jonas@devlieghere.com>
Wed, 12 Apr 2023 00:03:49 +0000 (17:03 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Wed, 12 Apr 2023 00:05:15 +0000 (17:05 -0700)
Now that we can pass Python objects to the scripted process instance, we
don't need to parse the crashlog twice anymore.

Differential revision: https://reviews.llvm.org/D148063

lldb/examples/python/crashlog.py
lldb/examples/python/scripted_process/crashlog_scripted_process.py
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h

index b09c03a..68ead43 100755 (executable)
@@ -1111,12 +1111,17 @@ def load_crashlog_in_scripted_process(debugger, crash_log_file, options, result)
     launch_info.SetProcessPluginName("ScriptedProcess")
     launch_info.SetScriptedProcessClassName("crashlog_scripted_process.CrashLogScriptedProcess")
     launch_info.SetScriptedProcessDictionary(structured_data)
+    launch_info.SetLaunchFlags(lldb.eLaunchFlagStopAtEntry)
+
     error = lldb.SBError()
     process = target.Launch(launch_info, error)
 
     if not process or error.Fail():
         raise InteractiveCrashLogException("couldn't launch Scripted Process", error)
 
+    process.GetScriptedImplementation().set_crashlog(crashlog)
+    process.Continue()
+
     if not options.skip_status:
         @contextlib.contextmanager
         def synchronous(debugger):
index 8c32b40..b8c0571 100644 (file)
@@ -9,20 +9,18 @@ from lldb.plugins.scripted_process import ScriptedThread
 from lldb.macosx.crashlog import CrashLog,CrashLogParser
 
 class CrashLogScriptedProcess(ScriptedProcess):
-    def parse_crashlog(self):
-        crashlog_parser = CrashLogParser.create(self.dbg, self.crashlog_path, False)
-        crash_log = crashlog_parser.parse()
-
-        self.pid = crash_log.process_id
-        self.addr_mask = crash_log.addr_mask
-        self.crashed_thread_idx = crash_log.crashed_thread_idx
+    def set_crashlog(self, crashlog):
+        self.crashlog = crashlog
+        self.pid = self.crashlog.process_id
+        self.addr_mask = self.crashlog.addr_mask
+        self.crashed_thread_idx = self.crashlog.crashed_thread_idx
         self.loaded_images = []
-        self.exception = crash_log.exception
+        self.exception = self.crashlog.exception
         self.app_specific_thread = None
-        if hasattr(crash_log, 'asi'):
-            self.metadata['asi'] = crash_log.asi
-        if hasattr(crash_log, 'asb'):
-            self.extended_thread_info = crash_log.asb
+        if hasattr(self.crashlog, 'asi'):
+            self.metadata['asi'] = self.crashlog.asi
+        if hasattr(self.crashlog, 'asb'):
+            self.extended_thread_info = self.crashlog.asb
 
         def load_images(self, images):
             #TODO: Add to self.loaded_images and load images in lldb
@@ -38,12 +36,12 @@ class CrashLogScriptedProcess(ScriptedProcess):
                         else:
                             self.loaded_images.append(image)
 
-        for thread in crash_log.threads:
+        for thread in self.crashlog.threads:
             if self.load_all_images:
-                load_images(self, crash_log.images)
+                load_images(self, self.crashlog.images)
             elif thread.did_crash():
                 for ident in thread.idents:
-                    load_images(self, crash_log.find_images_with_identifier(ident))
+                    load_images(self, self.crashlog.find_images_with_identifier(ident))
 
             if hasattr(thread, 'app_specific_backtrace') and thread.app_specific_backtrace:
                 # We don't want to include the Application Specific Backtrace
@@ -92,7 +90,6 @@ class CrashLogScriptedProcess(ScriptedProcess):
         self.crashed_thread_idx = 0
         self.exception = None
         self.extended_thread_info = None
-        self.parse_crashlog()
 
     def read_memory_at_address(self, addr: int, size: int, error: lldb.SBError) -> lldb.SBData:
         # NOTE: CrashLogs don't contain any memory.
index 5e7f88c..999edd8 100644 (file)
@@ -168,7 +168,7 @@ Status ScriptedProcess::DoLaunch(Module *exe_module,
   return {};
 }
 
-void ScriptedProcess::DidLaunch() {
+void ScriptedProcess::DidResume() {
   m_pid = GetInterface().GetProcessID();
   GetLoadedDynamicLibrariesInfos();
 }
index 368c54b..856e05c 100644 (file)
@@ -47,7 +47,7 @@ public:
 
   Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
 
-  void DidLaunch() override;
+  void DidResume() override;
 
   Status DoResume() override;