Skip to content

Commit 7cedca1

Browse files
committed
[lldb] Parse the crashlog only once
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 (cherry picked from commit 88f4091)
1 parent 1def071 commit 7cedca1

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

lldb/examples/python/crashlog.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,12 +1111,17 @@ def load_crashlog_in_scripted_process(debugger, crash_log_file, options, result)
11111111
launch_info.SetProcessPluginName("ScriptedProcess")
11121112
launch_info.SetScriptedProcessClassName("crashlog_scripted_process.CrashLogScriptedProcess")
11131113
launch_info.SetScriptedProcessDictionary(structured_data)
1114+
launch_info.SetLaunchFlags(lldb.eLaunchFlagStopAtEntry)
1115+
11141116
error = lldb.SBError()
11151117
process = target.Launch(launch_info, error)
11161118

11171119
if not process or error.Fail():
11181120
raise InteractiveCrashLogException("couldn't launch Scripted Process", error)
11191121

1122+
process.GetScriptedImplementation().set_crashlog(crashlog)
1123+
process.Continue()
1124+
11201125
if not options.skip_status:
11211126
@contextlib.contextmanager
11221127
def synchronous(debugger):

lldb/examples/python/scripted_process/crashlog_scripted_process.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,18 @@
99
from lldb.macosx.crashlog import CrashLog,CrashLogParser
1010

1111
class CrashLogScriptedProcess(ScriptedProcess):
12-
def parse_crashlog(self):
13-
crashlog_parser = CrashLogParser.create(self.dbg, self.crashlog_path, False)
14-
crash_log = crashlog_parser.parse()
15-
16-
self.pid = crash_log.process_id
17-
self.addr_mask = crash_log.addr_mask
18-
self.crashed_thread_idx = crash_log.crashed_thread_idx
12+
def set_crashlog(self, crashlog):
13+
self.crashlog = crashlog
14+
self.pid = self.crashlog.process_id
15+
self.addr_mask = self.crashlog.addr_mask
16+
self.crashed_thread_idx = self.crashlog.crashed_thread_idx
1917
self.loaded_images = []
20-
self.exception = crash_log.exception
18+
self.exception = self.crashlog.exception
2119
self.app_specific_thread = None
22-
if hasattr(crash_log, 'asi'):
23-
self.metadata['asi'] = crash_log.asi
24-
if hasattr(crash_log, 'asb'):
25-
self.extended_thread_info = crash_log.asb
20+
if hasattr(self.crashlog, 'asi'):
21+
self.metadata['asi'] = self.crashlog.asi
22+
if hasattr(self.crashlog, 'asb'):
23+
self.extended_thread_info = self.crashlog.asb
2624

2725
def load_images(self, images):
2826
#TODO: Add to self.loaded_images and load images in lldb
@@ -38,12 +36,12 @@ def load_images(self, images):
3836
else:
3937
self.loaded_images.append(image)
4038

41-
for thread in crash_log.threads:
39+
for thread in self.crashlog.threads:
4240
if self.load_all_images:
43-
load_images(self, crash_log.images)
41+
load_images(self, self.crashlog.images)
4442
elif thread.did_crash():
4543
for ident in thread.idents:
46-
load_images(self, crash_log.find_images_with_identifier(ident))
44+
load_images(self, self.crashlog.find_images_with_identifier(ident))
4745

4846
if hasattr(thread, 'app_specific_backtrace') and thread.app_specific_backtrace:
4947
# We don't want to include the Application Specific Backtrace
@@ -92,7 +90,6 @@ def __init__(self, exe_ctx: lldb.SBExecutionContext, args : lldb.SBStructuredDat
9290
self.crashed_thread_idx = 0
9391
self.exception = None
9492
self.extended_thread_info = None
95-
self.parse_crashlog()
9693

9794
def read_memory_at_address(self, addr: int, size: int, error: lldb.SBError) -> lldb.SBData:
9895
# NOTE: CrashLogs don't contain any memory.

lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Status ScriptedProcess::DoLaunch(Module *exe_module,
161161
return error;
162162
}
163163

164-
void ScriptedProcess::DidLaunch() {
164+
void ScriptedProcess::DidResume() {
165165
m_pid = GetInterface().GetProcessID();
166166
GetLoadedDynamicLibrariesInfos();
167167
}

lldb/source/Plugins/Process/scripted/ScriptedProcess.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ScriptedProcess : public Process {
4747

4848
Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
4949

50-
void DidLaunch() override;
50+
void DidResume() override;
5151

5252
Status DoResume() override;
5353

0 commit comments

Comments
 (0)