mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-21 23:10:54 +00:00
3629e3a2a8
/usr/bin/env is recommended as a cross-platform way to find python. But: - we're only using lldb on darwin, where we know python (or at least, the xcrun-style shortcut) is in /usr/bin/ - the python interpreter in LLDB comes from /S/L/F: $ otool -L Contents/SharedFrameworks/LLDB.framework/LLDB | grep Python /System/Library/Frameworks/Python.framework/Versions/2.7/Python so when we use the lldb python module, it calls into the swig/python support in the lldb framework, and if there's a mismatch between the interpreter and the linked python, weird things occur. In theory, I believe this should be done by: - looking for the LLDB framework (llgdb.py does some of that) - finding the binary inside the framework - looking for the Python it was linked against (otool -L) - finding the interpreter executable inside the Python.framework But in practice, that's only different if we use a custom LLDB framework/pythonpath when running these tests, and AFAIK nobody does that right now, so the code would be dead anyway. Don't pretend we can use any arbitrary python: just use the system one. Differential Revision: https://reviews.llvm.org/D47967 llvm-svn: 334369
82 lines
2.4 KiB
Perl
Executable File
82 lines
2.4 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
#
|
|
# This script tests debugging information generated by a compiler.
|
|
# Input arguments
|
|
# - Input source program. Usually this source file is decorated using
|
|
# special comments to communicate debugger commands.
|
|
# - Executable file. This file is generated by the compiler.
|
|
#
|
|
# This perl script extracts debugger commands from input source program
|
|
# comments in a script. A debugger is used to load the executable file
|
|
# and run the script generated from source program comments. Finally,
|
|
# the debugger output is checked, using FileCheck, to validate
|
|
# debugging information.
|
|
#
|
|
# On Darwin the default is to use the llgdb.py wrapper script which
|
|
# translates gdb commands into their lldb equivalents.
|
|
|
|
use File::Basename;
|
|
use Config;
|
|
use Cwd;
|
|
|
|
my $testcase_file = $ARGV[0];
|
|
my $executable_file = $ARGV[1];
|
|
|
|
my $input_filename = basename $testcase_file;
|
|
my $output_dir = dirname $executable_file;
|
|
|
|
my $debugger_script_file = "$output_dir/$input_filename.debugger.script";
|
|
my $output_file = "$output_dir/$input_filename.gdb.output";
|
|
|
|
my %cmd_map = ();
|
|
# Assume lldb to be the debugger on Darwin.
|
|
my $use_lldb = 0;
|
|
$use_lldb = 1 if ($Config{osname} eq "darwin");
|
|
|
|
# Extract debugger commands from testcase. They are marked with DEBUGGER:
|
|
# at the beginning of a comment line.
|
|
open(INPUT, $testcase_file);
|
|
open(OUTPUT, ">$debugger_script_file");
|
|
while(<INPUT>) {
|
|
my($line) = $_;
|
|
$i = index($line, "DEBUGGER:");
|
|
if ( $i >= 0) {
|
|
$l = length("DEBUGGER:");
|
|
$s = substr($line, $i + $l);
|
|
print OUTPUT "$s";
|
|
}
|
|
}
|
|
print OUTPUT "\n";
|
|
print OUTPUT "quit\n";
|
|
close(INPUT);
|
|
close(OUTPUT);
|
|
|
|
# setup debugger and debugger options to run a script.
|
|
my $my_debugger = $ENV{'DEBUGGER'};
|
|
if (!$my_debugger) {
|
|
if ($use_lldb) {
|
|
my $path = dirname(Cwd::abs_path($0));
|
|
# At least on darwin, LLDB needs te system python.
|
|
$my_debugger = "/usr/bin/python $path/llgdb.py";
|
|
} else {
|
|
$my_debugger = "gdb";
|
|
}
|
|
}
|
|
|
|
# quiet / exit after cmdline / no init file / execute script
|
|
my $debugger_options = "-q -batch -n -x";
|
|
|
|
# run debugger and capture output.
|
|
system("$my_debugger $debugger_options $debugger_script_file $executable_file > $output_file 2>&1");
|
|
|
|
# validate output.
|
|
system("FileCheck", "-input-file", "$output_file", "$testcase_file");
|
|
if ($?>>8 == 1) {
|
|
print "Debugger output was:\n";
|
|
system("cat", "$output_file");
|
|
exit 1;
|
|
}
|
|
else {
|
|
exit 0;
|
|
}
|