brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 9c922bc Raw
91 lines · plain
1#!/usr/bin/env perl2#3# This script tests debugging information generated by a compiler.4# Input arguments5#   - Input source program. Usually this source file is decorated using6#     special comments to communicate debugger commands.7#   - Executable file. This file is generated by the compiler.8#9# This perl script extracts debugger commands from input source program10# comments in a script. A debugger is used to load the executable file11# and run the script generated from source program comments. Finally,12# the debugger output is checked, using FileCheck, to validate13# debugging information.14#15# On Darwin the default is to use the llgdb.py wrapper script which16# translates gdb commands into their lldb equivalents.17 18use File::Basename;19use Config;20use Cwd;21 22my $testcase_file = $ARGV[0];23my $executable_file = $ARGV[1];24 25my $input_filename = basename $testcase_file;26my $output_dir = dirname $executable_file;27 28my $debugger_script_file = "$output_dir/$input_filename.debugger.script";29my $output_file = "$output_dir/$input_filename.gdb.output";30 31my %cmd_map = ();32# Assume lldb to be the debugger on Darwin.33my $use_lldb = 0;34$use_lldb = 1 if ($Config{osname} eq "darwin");35 36# Extract debugger commands from testcase. They are marked with DEBUGGER:37# at the beginning of a comment line.38open(INPUT, $testcase_file);39open(OUTPUT, ">$debugger_script_file");40while(<INPUT>) {41    my($line) = $_;42    $i = index($line, "DEBUGGER:");43    if ( $i >= 0) {44        $l = length("DEBUGGER:");45        $s = substr($line, $i + $l);46        print OUTPUT  "$s";47    }48}49print OUTPUT "\n";50print OUTPUT "quit\n";51close(INPUT);52close(OUTPUT);53 54# setup debugger and debugger options to run a script.55my $my_debugger = $ENV{'DEBUGGER'};56if (!$my_debugger) {57    if ($use_lldb) {58        my $path = dirname(Cwd::abs_path($0));59        my $python_exec_path = $ENV{'PYTHON_EXEC_PATH'};60        if (!$python_exec_path) {61          $python_exec_path = 'python3';62        }63        $my_debugger = "LLDB_PYTHON_PATH=$ENV{'LLDB_PYTHON_PATH'} /usr/bin/xcrun $python_exec_path $path/llgdb.py";64    } else {65        $my_debugger = "gdb";66    }67}68 69# quiet / exit after cmdline / no init file / execute script70my $debugger_options = "-q -batch -n -x";71 72# run debugger and capture output.73print("Running debugger\n");74system("$my_debugger $debugger_options $debugger_script_file $executable_file > $output_file 2>&1");75if ($?) {76    print("Debugger output was:\n");77    system("cat", "$output_file");78    exit 1;79}80# validate output.81print("Running FileCheck\n");82system("FileCheck", "-input-file", "$output_file", "$testcase_file");83if ($?) {84    print("Debugger output was:\n");85    system("cat", "$output_file");86    exit 1;87}88else {89    exit 0;90}91