Skip to content

[lldb/Process] Silence toolchain mismatch warnings for Scripted Processes (NFC) #4067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lldb/examples/python/crashlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ def SymbolicateCrashLog(crash_log, options):
for error in crash_log.errors:
print(error)

def load_crashlog_in_scripted_process(debugger, crash_log_file):
def load_crashlog_in_scripted_process(debugger, crash_log_file, options):
result = lldb.SBCommandReturnObject()

crashlog_path = os.path.expanduser(crash_log_file)
Expand Down Expand Up @@ -999,7 +999,8 @@ def load_crashlog_in_scripted_process(debugger, crash_log_file):
return

structured_data = lldb.SBStructuredData()
structured_data.SetFromJSON(json.dumps({ "crashlog_path" : crashlog_path }))
structured_data.SetFromJSON(json.dumps({ "crashlog_path" : crashlog_path,
"load_all_images": options.load_all_images }))
launch_info = lldb.SBLaunchInfo(None)
launch_info.SetProcessPluginName("ScriptedProcess")
launch_info.SetScriptedProcessClassName("crashlog_scripted_process.CrashLogScriptedProcess")
Expand Down Expand Up @@ -1058,7 +1059,9 @@ def CreateSymbolicateCrashLogOptions(
'-a',
action='store_true',
dest='load_all_images',
help='load all executable images, not just the images found in the crashed stack frames',
help='load all executable images, not just the images found in the '
'crashed stack frames, loads stackframes for all the threads in '
'interactive mode.',
default=False)
option_parser.add_option(
'--images',
Expand Down Expand Up @@ -1186,7 +1189,8 @@ def should_run_in_interactive_mode(options, ci):
if args:
for crash_log_file in args:
if should_run_in_interactive_mode(options, ci):
load_crashlog_in_scripted_process(debugger, crash_log_file)
load_crashlog_in_scripted_process(debugger, crash_log_file,
options)
else:
crash_log = CrashLogParser().parse(debugger, crash_log_file, options.verbose)
SymbolicateCrashLog(crash_log, options)
Expand Down
36 changes: 25 additions & 11 deletions lldb/examples/python/scripted_process/crashlog_scripted_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@ def parse_crashlog(self):
self.crashed_thread_idx = crash_log.crashed_thread_idx
self.loaded_images = []

def load_images(self, images):
#TODO: Add to self.loaded_images and load images in lldb
if images:
for image in images:
if image not in self.loaded_images:
err = image.add_module(self.target)
if err:
print(err)
else:
self.loaded_images.append(image)

for thread in crash_log.threads:
if thread.did_crash():
if self.load_all_images:
load_images(self, crash_log.images)
elif thread.did_crash():
for ident in thread.idents:
images = crash_log.find_images_with_identifier(ident)
if images:
for image in images:
#TODO: Add to self.loaded_images and load images in lldb
err = image.add_module(self.target)
if err:
print(err)
else:
self.loaded_images.append(image)
load_images(self, crash_log.find_images_with_identifier(ident))

self.threads[thread.index] = CrashLogScriptedThread(self, None, thread)

def __init__(self, target: lldb.SBTarget, args : lldb.SBStructuredData):
Expand All @@ -49,6 +55,14 @@ def __init__(self, target: lldb.SBTarget, args : lldb.SBStructuredData):
if not self.crashlog_path:
return

load_all_images = args.GetValueForKey("load_all_images")
if load_all_images and load_all_images.IsValid():
if load_all_images.GetType() == lldb.eStructuredDataTypeBoolean:
self.load_all_images = load_all_images.GetBooleanValue()

if not self.load_all_images:
self.load_all_images = False

self.pid = super().get_process_id()
self.crashed_thread_idx = 0
self.parse_crashlog()
Expand Down Expand Up @@ -101,7 +115,7 @@ def create_register_ctx(self):
return self.register_ctx

def create_stackframes(self):
if not self.has_crashed:
if not (self.scripted_process.load_all_images or self.has_crashed):
return None

if not self.backing_thread or not len(self.backing_thread.frames):
Expand Down
8 changes: 8 additions & 0 deletions lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5930,6 +5930,14 @@ void Process::PrintWarningCantLoadSwiftModule(const Module &module,
}

void Process::PrintWarningToolchainMismatch(const SymbolContext &sc) {
if (GetTarget().GetProcessLaunchInfo().IsScriptedProcess())
// It's very likely that the debugger used to launch the ScriptedProcess
// will not match the compiler version used to build the target, and we
// shouldn't need Swift's serialized AST to symbolicate the frame where we
// stopped. However, because this is called from a generic place
// (Thread::FrameSelectedCallback), it's safe to silence the warning for
// Scripted Processes.
return;
if (!GetWarningsToolchainMismatch())
return;
if (!sc.module_sp || !sc.comp_unit)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <mutex>
#include <thread>

int bar(int i) {
int *j = 0;
*j = 1;
return i; // break here
}

int foo(int i) { return bar(i); }

void call_and_wait(int &n) {
std::cout << "waiting for computation!" << std::endl;
while (n != 42 * 42)
;
std::cout << "finished computation!" << std::endl;
}

void compute_pow(int &n) { n = foo(n); }

int main() {
int n = 42;
std::mutex mutex;
std::unique_lock<std::mutex> lock(mutex);

std::thread thread_1(call_and_wait, std::ref(n));
std::thread thread_2(compute_pow, std::ref(n));
lock.unlock();

thread_1.join();
thread_2.join();

return 0;
}
Loading