repro_fail 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash -eu
  2. #
  3. # Script to reproduce a test failure from a dejagnu .log file.
  4. #
  5. # Contributed by Diego Novillo <dnovillo@google.com>
  6. #
  7. # Copyright (C) 2011, 2012, 2013 Free Software Foundation, Inc.
  8. #
  9. # This file is part of GCC.
  10. #
  11. # GCC is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 3, or (at your option)
  14. # any later version.
  15. #
  16. # GCC is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU General Public License
  22. # along with GCC; see the file COPYING. If not, write to
  23. # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
  24. # Boston, MA 02110-1301, USA.
  25. # This script will search a line starting with 'spawn' that includes the
  26. # pattern you are looking for (typically a source file name).
  27. #
  28. # Once it finds that pattern, it re-executes the whole command
  29. # in the spawn line. If the pattern matches more than one spawn
  30. # command, it asks which one you want.
  31. if [ $# -lt 2 ] ; then
  32. echo "usage: $0 [--debug|--debug-tui] pattern file.log [additional-args]"
  33. echo
  34. echo "Finds the 'spawn' line matching PATTERN in FILE.LOG and executes"
  35. echo "the command with any arguments in ADDITIONAL-ARGS."
  36. echo
  37. echo "If --debug is used, the compiler is invoked with -wrapper gdb,--args"
  38. echo "If --debug-tui is used, the compiler is invoked with -wrapper "\
  39. "gdb,--tui,--args"
  40. exit 1
  41. fi
  42. if [ "$1" == "--debug" ] ; then
  43. debug_args="-wrapper gdb,--args"
  44. shift
  45. elif [ "$1" == "--debug-tui" ] ; then
  46. debug_args="-wrapper gdb,--tui,--args"
  47. shift
  48. else
  49. debug_args=""
  50. fi
  51. pattern="$1"
  52. logf="$2"
  53. shift 2
  54. # Find the commands in LOGF that reference PATTERN.
  55. lines=$(grep -E "^spawn .*$pattern" $logf \
  56. | sed -e 's/^spawn -ignore SIGHUP //' \
  57. | sed -e 's/^spawn //')
  58. if [ -z "$lines" ] ; then
  59. echo "Could not find a spawn command for pattern $pattern"
  60. exit 1
  61. fi
  62. # Collect all the command lines into the COMMANDS array.
  63. old_IFS="$IFS"
  64. IFS=" "
  65. num_lines=0
  66. for line in $lines ; do
  67. num_lines=$[$num_lines + 1]
  68. echo "[$num_lines] $line"
  69. commands[$num_lines]=$line
  70. done
  71. # If we found more than one line for PATTERN, ask which one we should run.
  72. cmds_to_run='0'
  73. if [ $num_lines -gt 1 ] ; then
  74. echo
  75. echo
  76. echo -n "Enter the list of commands to run or '0' to run them all: "
  77. read cmds_to_run
  78. fi
  79. if [ "$cmds_to_run" = "0" ] ; then
  80. cmds_to_run=$(seq 1 $num_lines)
  81. fi
  82. IFS="$old_IFS"
  83. # Finally, execute all the commands we were told to execute.
  84. for cmd_num in $cmds_to_run ; do
  85. cmd=${commands[$cmd_num]}
  86. set -x +e
  87. $cmd $debug_args "$@"
  88. set +x -e
  89. done