2
0

btgrep 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/perl
  2. # Copyright (c) 2007-2014, Anthony Minessale II
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions
  7. # are met:
  8. #
  9. # Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. #
  12. # Redistributions in binary form must reproduce the above copyright
  13. # notice, this list of conditions and the following disclaimer in the
  14. # documentation and/or other materials provided with the distribution.
  15. #
  16. # Neither the name of the original author; nor the names of any contributors
  17. # may be used to endorse or promote products derived from this software
  18. # without specific prior written permission.
  19. #
  20. #
  21. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  25. # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26. # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29. # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. #
  33. # Contributors:
  34. #
  35. # btgrep - Search for regex in backtraces
  36. #
  37. $| = 0;
  38. $/ = undef;
  39. my $file = shift;
  40. open I, $file or die;
  41. my $i = <I>;
  42. close I;
  43. my @all = $i =~ /Thread \d.*?\n\n/smg;
  44. foo:
  45. foreach my $m (@all) {
  46. foreach (@ARGV) {
  47. my $arg;
  48. my $neg = 0;
  49. if (/^\-(.*)$/) {
  50. $arg = $1;
  51. $neg = 1;
  52. } else {
  53. $arg = $_;
  54. }
  55. if ($neg) {
  56. next foo if($m =~ /$arg/);
  57. } else {
  58. next foo unless($m =~ /$arg/);
  59. }
  60. }
  61. print "Match: $m";
  62. }
  63. # For Emacs:
  64. # Local Variables:
  65. # mode:perl
  66. # indent-tabs-mode:t
  67. # tab-width:4
  68. # c-basic-offset:4
  69. # End:
  70. # For VIM:
  71. # vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet: