test_bcc_debuginfo.pl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. use File::Basename;
  26. my $filecheck_tool = $ARGV[0];
  27. my $testcase_file = $ARGV[1];
  28. my $testcase_output = $ARGV[2];
  29. my $input_filename = basename $testcase_file;
  30. my $output_dir = dirname $testcase_output;
  31. my $debugger_script_file = "$output_dir/$input_filename.debugger.script";
  32. my $output_file = "$output_dir/$input_filename.gdb.output";
  33. open(OUTPUT, ">$debugger_script_file");
  34. # Enable extra verbosity in GDB
  35. print OUTPUT "set verbose on\n";
  36. # Extract debugger commands from testcase. They are marked with DEBUGGER:
  37. # at the beginning of a comment line.
  38. open(INPUT, $testcase_file);
  39. while(<INPUT>) {
  40. my($line) = $_;
  41. $i = index($line, "DEBUGGER:");
  42. if ( $i >= 0) {
  43. $l = length("DEBUGGER:");
  44. $s = substr($line, $i + $l);
  45. $s =~ s/\%s/$input_filename/g;
  46. $s =~ s/\%t/$testcase_output/g;
  47. print OUTPUT "$s";
  48. }
  49. }
  50. print OUTPUT "\n";
  51. print OUTPUT "quit\n";
  52. close(INPUT);
  53. close(OUTPUT);
  54. # setup debugger and debugger options to run a script.
  55. my $debugger = $ENV{'DEBUGGER'};
  56. my $debugger_options = $ENV{'DEBUGGER_ARGS'};
  57. if (!$debugger) {
  58. print "Please set DEBUGGER prior to using this script";
  59. exit 1;
  60. }
  61. $debugger_options = "-x $debugger_script_file $debugger_options $testcase_output";
  62. # run debugger and capture output.
  63. system("$debugger $debugger_options > $output_file 2>&1") ;
  64. if ($?>>8 != 0) {
  65. print "Error during debugger invocation. Command used was: \n";
  66. print("$debugger $debugger_options > $output_file 2>&1\n") ;
  67. exit 1;
  68. }
  69. # validate output.
  70. system("$filecheck_tool", "-input-file", "$output_file", "$testcase_file");
  71. if ($?>>8 != 0) {
  72. print "Error during verification. Debugger command used was: \n";
  73. print("$debugger $debugger_options > $output_file 2>&1\n") ;
  74. print "Verification command used was: \n";
  75. print "$filecheck_tool -input-file $output_file $testcase_file\n";
  76. exit 1;
  77. }
  78. else {
  79. exit 0;
  80. }