Skip to content

Commit b1c3bbf

Browse files
authored
Merge pull request #4056 from medismailben/stable/20211026
2 parents d8b8d59 + fb76882 commit b1c3bbf

File tree

3 files changed

+61
-17
lines changed

3 files changed

+61
-17
lines changed

lldb/examples/python/crashlog.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828

2929
from __future__ import print_function
3030
import cmd
31+
import contextlib
3132
import datetime
3233
import glob
34+
import json
3335
import optparse
3436
import os
3537
import platform
@@ -41,7 +43,6 @@
4143
import sys
4244
import time
4345
import uuid
44-
import json
4546

4647
try:
4748
# First try for LLDB in case PYTHONPATH is already correctly setup.
@@ -266,7 +267,7 @@ def locate_module_and_debug_symbols(self):
266267
self.resolved = True
267268
uuid_str = self.get_normalized_uuid_string()
268269
if self.show_symbol_progress():
269-
print('Getting symbols for %s %s...' % (uuid_str, self.path), end=' ')
270+
print('Getting symbols for %s %s...\n' % (uuid_str, self.path), end=' ')
270271
if os.path.exists(self.dsymForUUIDBinary):
271272
dsym_for_uuid_command = '%s %s' % (
272273
self.dsymForUUIDBinary, uuid_str)
@@ -316,7 +317,7 @@ def locate_module_and_debug_symbols(self):
316317
pass
317318
if (self.resolved_path and os.path.exists(self.resolved_path)) or (
318319
self.path and os.path.exists(self.path)):
319-
print('ok')
320+
print('Resolved symbols for %s %s...\n' % (uuid_str, self.path), end=' ')
320321
return True
321322
else:
322323
self.unavailable = True
@@ -1006,6 +1007,31 @@ def load_crashlog_in_scripted_process(debugger, crash_log_file):
10061007
error = lldb.SBError()
10071008
process = target.Launch(launch_info, error)
10081009

1010+
if not process or error.Fail():
1011+
return
1012+
1013+
@contextlib.contextmanager
1014+
def synchronous(debugger):
1015+
async_state = debugger.GetAsync()
1016+
debugger.SetAsync(False)
1017+
try:
1018+
yield
1019+
finally:
1020+
debugger.SetAsync(async_state)
1021+
1022+
with synchronous(debugger):
1023+
run_options = lldb.SBCommandInterpreterRunOptions()
1024+
run_options.SetStopOnError(True)
1025+
run_options.SetStopOnCrash(True)
1026+
run_options.SetEchoCommands(True)
1027+
1028+
commands_stream = lldb.SBStream()
1029+
commands_stream.Print("process status\n")
1030+
commands_stream.Print("thread backtrace\n")
1031+
error = debugger.SetInputString(commands_stream.GetData())
1032+
if error.Success():
1033+
debugger.RunCommandInterpreter(True, False, run_options, 0, False, True)
1034+
10091035
def CreateSymbolicateCrashLogOptions(
10101036
command_name,
10111037
description,

lldb/test/API/functionalities/scripted_process/TestScriptedProcess.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Test python scripted process in lldb
33
"""
44

5-
import os
5+
import os, shutil
66

77
import lldb
88
from lldbsuite.test.decorators import *
@@ -43,29 +43,39 @@ def test_python_plugin_package(self):
4343
self.expect('script dir(ScriptedProcess)',
4444
substrs=["launch"])
4545

46+
def move_blueprint_to_dsym(self, blueprint_name):
47+
blueprint_origin_path = os.path.join(self.getSourceDir(), blueprint_name)
48+
dsym_bundle = self.getBuildArtifact("a.out.dSYM")
49+
blueprint_destination_path = os.path.join(dsym_bundle, "Contents",
50+
"Resources", "Python")
51+
if not os.path.exists(blueprint_destination_path):
52+
os.mkdir(blueprint_destination_path)
53+
54+
blueprint_destination_path = os.path.join(blueprint_destination_path, "a_out.py")
55+
shutil.copy(blueprint_origin_path, blueprint_destination_path)
56+
4657
@skipUnlessDarwin
4758
def test_invalid_scripted_register_context(self):
4859
"""Test that we can launch an lldb scripted process with an invalid
4960
Scripted Thread, with invalid register context."""
5061
self.build()
51-
target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
52-
self.assertTrue(target, VALID_TARGET)
53-
log_file = self.getBuildArtifact('thread.log')
54-
self.runCmd("log enable lldb thread -f " + log_file)
55-
self.assertTrue(os.path.isfile(log_file))
5662

5763
os.environ['SKIP_SCRIPTED_PROCESS_LAUNCH'] = '1'
5864
def cleanup():
5965
del os.environ["SKIP_SCRIPTED_PROCESS_LAUNCH"]
6066
self.addTearDownHook(cleanup)
6167

62-
scripted_process_example_relpath = 'invalid_scripted_process.py'
63-
self.runCmd("command script import " + os.path.join(self.getSourceDir(),
64-
scripted_process_example_relpath))
68+
self.runCmd("settings set target.load-script-from-symbol-file true")
69+
self.move_blueprint_to_dsym('invalid_scripted_process.py')
70+
target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
71+
self.assertTrue(target, VALID_TARGET)
72+
log_file = self.getBuildArtifact('thread.log')
73+
self.runCmd("log enable lldb thread -f " + log_file)
74+
self.assertTrue(os.path.isfile(log_file))
6575

6676
launch_info = lldb.SBLaunchInfo(None)
6777
launch_info.SetProcessPluginName("ScriptedProcess")
68-
launch_info.SetScriptedProcessClassName("invalid_scripted_process.InvalidScriptedProcess")
78+
launch_info.SetScriptedProcessClassName("a_out.InvalidScriptedProcess")
6979
error = lldb.SBError()
7080

7181
process = target.Launch(launch_info, error)

lldb/test/Shell/ScriptInterpreter/Python/Crashlog/scripted_crashlog_json.test

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44

55
# RUN: cp %S/Inputs/scripted_crashlog.ips %t.crash
66
# RUN: %python %S/patch-crashlog.py --binary %t.out --crashlog %t.crash --offsets '{"main":20, "bar":9, "foo":16}' --json
7-
# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog -i %t.crash' -o 'process status' 2>&1 | FileCheck %s
7+
# RUN: %lldb %t.out -o 'command script import lldb.macosx.crashlog' -o 'crashlog -i %t.crash' 2>&1 | FileCheck %s
88

99
# CHECK: "crashlog" {{.*}} commands have been installed, use the "--help" options on these commands
10-
# CHECK: Process 92190 stopped
11-
# CHECK: * thread #1, name = 'CrashLogScriptedThread.thread-0', stop reason = EXC_BAD_ACCESS
12-
# CHECK: frame #0: 0x0000000104a23f68 scripted_crashlog_json.test.tmp.out`foo at test.c:3:6 [artificial]
10+
# CHECK: (lldb) process status
11+
# CHECK-NEXT: Process 92190 stopped
12+
# CHECK-NEXT: * thread #1, name = 'CrashLogScriptedThread.thread-0', stop reason = EXC_BAD_ACCESS
13+
# CHECK-NEXT: frame #0: 0x0000000104a23f68 scripted_crashlog_json.test.tmp.out`foo at test.c:3:6 [artificial]
14+
15+
# CHECK: (lldb) thread backtrace
16+
# CHECK-NEXT: * thread #1, name = 'CrashLogScriptedThread.thread-0', stop reason = EXC_BAD_ACCESS
17+
# CHECK-NEXT: * frame #0: 0x0000000104a23f68 scripted_crashlog_json.test.tmp.out`foo at test.c:3:6 [artificial]
18+
# CHECK-NEXT: frame #1: 0x0000000104a23f80 scripted_crashlog_json.test.tmp.out`bar at test.c:6:21 [artificial]
19+
# CHECK-NEXT: frame #2: 0x0000000104a23fa0 scripted_crashlog_json.test.tmp.out`main(argc=<no summary available>, argv=<unavailable>) at test.c:8:35 [artificial]
20+
# CHECK-NEXT: frame #3: 0x0000000104a6108c dyld`start(kernArgs=<no summary available>) at dyldMain.cpp:879:18 [opt] [artificial]

0 commit comments

Comments
 (0)