summaryrefslogtreecommitdiff
path: root/utils/test_debuginfo.pl
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2010-09-13 20:42:15 +0000
committerDevang Patel <dpatel@apple.com>2010-09-13 20:42:15 +0000
commitc7183baac67b263c4bc961e134bcab870f615ccb (patch)
treea82b32a2a52ad1ee0c5f640dbc087f5a767ec9f3 /utils/test_debuginfo.pl
parent12ea76563276b656b4bcf7ff38a404c10b0a675f (diff)
downloadllvm-c7183baac67b263c4bc961e134bcab870f615ccb.tar.gz
llvm-c7183baac67b263c4bc961e134bcab870f615ccb.tar.bz2
llvm-c7183baac67b263c4bc961e134bcab870f615ccb.tar.xz
Add little test script to check debug info.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113779 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/test_debuginfo.pl')
-rwxr-xr-xutils/test_debuginfo.pl61
1 files changed, 61 insertions, 0 deletions
diff --git a/utils/test_debuginfo.pl b/utils/test_debuginfo.pl
new file mode 100755
index 0000000000..740405ffd9
--- /dev/null
+++ b/utils/test_debuginfo.pl
@@ -0,0 +1,61 @@
+#!/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.
+
+use File::Basename;
+
+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.gdb.scirpt";
+my $output_file = "$output_dir/$input_filename.gdb.output";
+
+# Extract debugger commands from testcase. They are marked with DEBUGGER:
+# at the beginnign 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) {
+ $my_debugger = "gdb";
+}
+my $debugger_options = "-q -batch -n -x";
+
+# run debugger and capture output.
+system("$my_debugger $debugger_options $debugger_script_file $executable_file >& $output_file");
+
+# validate output.
+system("FileCheck", "-input-file", "$output_file", "$testcase_file");
+if ($?>>8 == 1) {
+ exit 1;
+}
+else {
+ exit 0;
+}