Skip to content

Commit cf5a10c

Browse files
committed
[lldb/crashlog] Avoid StopAtEntry when launch crashlog in interactive mode (llvm#154651)
In 88f4091, we changed the way the crashlog scripted process was launched since the previous approach required to parse the file twice, by stopping at entry, setting the crashlog object in the middle of the scripted process launch and resuming it. Since then, we've introduced SBScriptObject which allows to pass any arbitrary python object accross the SBAPI boundary to another scripted affordance. This patch make sure of that to include the parse crashlog object into the scripted process launch info dictionary, which eliviates the need to stop at entry. Signed-off-by: Med Ismail Bennani <[email protected]> Signed-off-by: Med Ismail Bennani <[email protected]> (cherry picked from commit 595148a) (cherry picked from commit e4ed3f5)
1 parent 1803232 commit cf5a10c

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

lldb/examples/python/crashlog.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,23 +1540,26 @@ def load_crashlog_in_scripted_process(debugger, crashlog_path, options, result):
15401540
}
15411541
)
15421542
)
1543+
1544+
crashlog_sd = lldb.SBStructuredData()
1545+
crashlog_sd.SetGenericValue(
1546+
lldb.SBScriptObject(crashlog, lldb.eScriptLanguagePython)
1547+
)
1548+
structured_data.SetValueForKey("crashlog", crashlog_sd)
1549+
15431550
launch_info = lldb.SBLaunchInfo(None)
15441551
launch_info.SetProcessPluginName("ScriptedProcess")
15451552
launch_info.SetScriptedProcessClassName(
15461553
"crashlog_scripted_process.CrashLogScriptedProcess"
15471554
)
15481555
launch_info.SetScriptedProcessDictionary(structured_data)
1549-
launch_info.SetLaunchFlags(lldb.eLaunchFlagStopAtEntry)
15501556

15511557
error = lldb.SBError()
15521558
process = target.Launch(launch_info, error)
15531559

15541560
if not process or error.Fail():
15551561
raise InteractiveCrashLogException("couldn't launch Scripted Process", error)
15561562

1557-
process.GetScriptedImplementation().set_crashlog(crashlog)
1558-
process.Continue()
1559-
15601563
if not options.skip_status:
15611564

15621565
@contextlib.contextmanager

lldb/examples/python/crashlog_scripted_process.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111

1212
class CrashLogScriptedProcess(ScriptedProcess):
13-
def set_crashlog(self, crashlog):
14-
self.crashlog = crashlog
13+
def parse_crashlog(self):
1514
if self.crashlog.process_id:
1615
if type(self.crashlog.process_id) is int:
1716
self.pid = self.crashlog.process_id
@@ -29,8 +28,6 @@ def set_crashlog(self, crashlog):
2928
if hasattr(self.crashlog, "asb"):
3029
self.extended_thread_info = self.crashlog.asb
3130

32-
crashlog.load_images(self.options, self.loaded_images)
33-
3431
for thread in self.crashlog.threads:
3532
if (
3633
hasattr(thread, "app_specific_backtrace")
@@ -92,10 +89,21 @@ def __init__(self, exe_ctx: lldb.SBExecutionContext, args: lldb.SBStructuredData
9289
no_parallel_image_loading.GetBooleanValue()
9390
)
9491

92+
self.crashlog = None
93+
crashlog = args.GetValueForKey("crashlog")
94+
if crashlog and crashlog.IsValid():
95+
if crashlog.GetType() == lldb.eStructuredDataTypeGeneric:
96+
self.crashlog = crashlog.GetGenericValue()
97+
98+
if not self.crashlog:
99+
# Return error
100+
return
101+
95102
self.pid = super().get_process_id()
96103
self.crashed_thread_idx = 0
97104
self.exception = None
98105
self.extended_thread_info = None
106+
self.parse_crashlog()
99107

100108
def read_memory_at_address(
101109
self, addr: int, size: int, error: lldb.SBError
@@ -104,8 +112,8 @@ def read_memory_at_address(
104112
return lldb.SBData()
105113

106114
def get_loaded_images(self):
107-
# TODO: Iterate over corefile_target modules and build a data structure
108-
# from it.
115+
if len(self.loaded_images) == 0:
116+
self.crashlog.load_images(self.options, self.loaded_images)
109117
return self.loaded_images
110118

111119
def should_stop(self) -> bool:

0 commit comments

Comments
 (0)