valgrind.pm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. #
  10. # This software is licensed as described in the file COPYING, which
  11. # you should have received as part of this distribution. The terms
  12. # are also available at http://curl.haxx.se/docs/copyright.html.
  13. #
  14. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. # copies of the Software, and permit persons to whom the Software is
  16. # furnished to do so, under the terms of the COPYING file.
  17. #
  18. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. # KIND, either express or implied.
  20. #
  21. ###########################################################################
  22. use File::Basename;
  23. sub valgrindparse {
  24. my ($srcdir, # the dir in which the runtests script resides
  25. $sslenabled,
  26. $file) = @_;
  27. my $leak;
  28. my $invalidread;
  29. my $uninitedvar;
  30. my $error;
  31. my $partial;
  32. my $us;
  33. my @o;
  34. my $bt=0;
  35. open(VAL, "<$file");
  36. while(<VAL>) {
  37. if($bt) {
  38. # back trace parsing
  39. if($_ =~ /^==(\d+)== *(at|by) 0x([0-9A-F]+): (.*)/) {
  40. my $w = $4;
  41. if($w =~ /(.*) \(([^:]*):(\d+)/) {
  42. my ($func, $source, $line)=($1, $2, $3);
  43. my $sourcename = basename($source);
  44. if(-f "$srcdir/../src/$sourcename" ||
  45. -f "$srcdir/../lib/$sourcename") {
  46. # this is our source
  47. # print "$func() at $source:$line\n";
  48. $us++;
  49. } #else {print "Not our source: $func, $source, $line\n";}
  50. }
  51. }
  52. else {
  53. if($us) {
  54. # the stack trace included source details about us
  55. $error++;
  56. if($leak) {
  57. push @o, "\n Leaked $leak bytes\n";
  58. }
  59. if($invalidread) {
  60. push @o, "\n Read $invalidread invalid bytes\n";
  61. }
  62. if($uninitedvar) {
  63. push @o, "\n Conditional jump or move depends on uninitialised value(s)\n";
  64. }
  65. }
  66. $bt = 0; # no more backtrace
  67. $us = 0;
  68. }
  69. }
  70. else {
  71. if($_ =~ /(\d+) bytes in (\d+) blocks are definitely lost/) {
  72. $leak = $1;
  73. if($leak) {
  74. $error++;
  75. }
  76. $bt = 1;
  77. }
  78. elsif($_ =~ /Invalid read of size (\d+)/) {
  79. $invalidread = $1;
  80. $error++;
  81. $bt = 1;
  82. }
  83. elsif($_ =~ /Conditional jump or move/) {
  84. # If we require SSL, this test case most probaly makes
  85. # us use OpenSSL. OpenSSL produces numerous valgrind
  86. # errors of this kind, rendering it impossible for us to
  87. # detect (valid) reports on actual curl or libcurl code.
  88. if(!$sslenabled) {
  89. $uninitedvar = 1;
  90. $error++;
  91. $bt = 1;
  92. }
  93. else {
  94. $partial=1;
  95. }
  96. }
  97. }
  98. }
  99. close(VAL);
  100. return @o;
  101. }
  102. 1;