summaryrefslogtreecommitdiffstats
path: root/tests/debuginfo/test_bcc_debuginfo.pl
blob: fd2057d64c7b4036143c3f11e5dec8990a716d98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl
#===-- test_bcc_debuginfo.pl - Debugger integration test driver script ---===#
#
#                     The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
#===----------------------------------------------------------------------===#
#
# This script tests debugging information generated by a compiler.
# Input arguments
#   - Path to FileCheck tool.
#   - Input source program. Usually this source file is decorated using
#     special comments (//DEBUGGER:, //CHECK:)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.
#
#===----------------------------------------------------------------------===#

use File::Basename;

my $filecheck_tool = $ARGV[0];
my $testcase_file = $ARGV[1];
my $testcase_output = $ARGV[2];

my $input_filename = basename $testcase_file;
my $output_dir = dirname $testcase_output;

my $debugger_script_file = "$output_dir/$input_filename.debugger.script";
my $output_file = "$output_dir/$input_filename.gdb.output";

open(OUTPUT, ">$debugger_script_file");

# Enable extra verbosity in GDB
print OUTPUT "set verbose on\n";

# Extract debugger commands from testcase. They are marked with DEBUGGER:
# at the beginning of a comment line.
open(INPUT, $testcase_file);
while(<INPUT>) {
    my($line) = $_;
    $i = index($line, "DEBUGGER:");
    if ( $i >= 0) {
        $l = length("DEBUGGER:");
        $s = substr($line, $i + $l);
        $s =~ s/\%s/$input_filename/g;
        $s =~ s/\%t/$testcase_output/g;
        print OUTPUT  "$s";
    }
}
print OUTPUT "\n";
print OUTPUT "quit\n";
close(INPUT);
close(OUTPUT);

# setup debugger and debugger options to run a script.
my $debugger = $ENV{'DEBUGGER'};
my $debugger_options = $ENV{'DEBUGGER_ARGS'};
if (!$debugger) {
    print "Please set DEBUGGER prior to using this script";
    exit 1;
}
$debugger_options = "-x $debugger_script_file $debugger_options $testcase_output";

# run debugger and capture output.
system("$debugger $debugger_options > $output_file 2>&1") ;
if ($?>>8 != 0) {
  print "Error during debugger invocation. Command used was: \n";
  print("$debugger $debugger_options > $output_file 2>&1\n") ;
  exit 1;
}

# validate output.
system("$filecheck_tool", "-input-file", "$output_file", "$testcase_file");
if ($?>>8 != 0) {
    print "Error during verification. Debugger command used was: \n";
    print("$debugger $debugger_options > $output_file 2>&1\n") ;
    print "Verification command used was: \n";
    print "$filecheck_tool -input-file $output_file $testcase_file\n";
    exit 1;
}
else {
    exit 0;
}