1 #!/usr/bin/perl 2 #===-- test_bcc_debuginfo.pl - Debugger integration test driver script ---===# 3 # 4 # The LLVM Compiler Infrastructure 5 # 6 # This file is distributed under the University of Illinois Open Source 7 # License. See LICENSE.TXT for details. 8 # 9 #===----------------------------------------------------------------------===# 10 # 11 # This script tests debugging information generated by a compiler. 12 # Input arguments 13 # - Path to FileCheck tool. 14 # - Input source program. Usually this source file is decorated using 15 # special comments (//DEBUGGER:, //CHECK:)to communicate debugger commands. 16 # - Executable file. This file is generated by the compiler. 17 # 18 # This perl script extracts debugger commands from input source program 19 # comments in a script. A debugger is used to load the executable file 20 # and run the script generated from source program comments. Finally, 21 # the debugger output is checked, using FileCheck, to validate 22 # debugging information. 23 # 24 #===----------------------------------------------------------------------===# 25 26 use File::Basename; 27 28 my $filecheck_tool = $ARGV[0]; 29 my $testcase_file = $ARGV[1]; 30 my $testcase_output = $ARGV[2]; 31 32 my $input_filename = basename $testcase_file; 33 my $output_dir = dirname $testcase_output; 34 35 my $debugger_script_file = "$output_dir/$input_filename.debugger.script"; 36 my $output_file = "$output_dir/$input_filename.gdb.output"; 37 38 open(OUTPUT, ">$debugger_script_file"); 39 40 # Enable extra verbosity in GDB 41 print OUTPUT "set verbose on\n"; 42 43 # Extract debugger commands from testcase. They are marked with DEBUGGER: 44 # at the beginning of a comment line. 45 open(INPUT, $testcase_file); 46 while(<INPUT>) { 47 my($line) = $_; 48 $i = index($line, "DEBUGGER:"); 49 if ( $i >= 0) { 50 $l = length("DEBUGGER:"); 51 $s = substr($line, $i + $l); 52 $s =~ s/\%s/$input_filename/g; 53 $s =~ s/\%t/$testcase_output/g; 54 print OUTPUT "$s"; 55 } 56 } 57 print OUTPUT "\n"; 58 print OUTPUT "quit\n"; 59 close(INPUT); 60 close(OUTPUT); 61 62 # setup debugger and debugger options to run a script. 63 my $debugger = $ENV{'DEBUGGER'}; 64 my $debugger_options = $ENV{'DEBUGGER_ARGS'}; 65 if (!$debugger) { 66 print "Please set DEBUGGER prior to using this script"; 67 exit 1; 68 } 69 $debugger_options = "-x $debugger_script_file $debugger_options $testcase_output"; 70 71 # run debugger and capture output. 72 system("$debugger $debugger_options > $output_file 2>&1") ; 73 if ($?>>8 != 0) { 74 print "Error during debugger invocation. Command used was: \n"; 75 print("$debugger $debugger_options > $output_file 2>&1\n") ; 76 exit 1; 77 } 78 79 # validate output. 80 system("$filecheck_tool", "-input-file", "$output_file", "$testcase_file"); 81 if ($?>>8 != 0) { 82 print "Error during verification. Debugger command used was: \n"; 83 print("$debugger $debugger_options > $output_file 2>&1\n") ; 84 print "Verification command used was: \n"; 85 print "$filecheck_tool -input-file $output_file $testcase_file\n"; 86 exit 1; 87 } 88 else { 89 exit 0; 90 } 91