valgrind.pm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) 1998 - 2005, 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. # $Id$
  22. ###########################################################################
  23. use File::Basename;
  24. sub valgrindparse {
  25. my ($srcdir, # the dir in which the runtests script resides
  26. $sslenabled,
  27. $file) = @_;
  28. my $leak;
  29. my $invalidread;
  30. my $uninitedvar;
  31. my $error;
  32. my $partial;
  33. my $us;
  34. my @o;
  35. my $bt=0;
  36. open(VAL, "<$file");
  37. while(<VAL>) {
  38. if($bt) {
  39. # back trace parsing
  40. if($_ =~ /^==(\d+)== *(at|by) 0x([0-9A-F]+): (.*)/) {
  41. my $w = $4;
  42. if($w =~ /(.*) \(([^:]*):(\d+)/) {
  43. my ($func, $source, $line)=($1, $2, $3);
  44. my $sourcename = basename($source);
  45. if(-f "$srcdir/../src/$sourcename" ||
  46. -f "$srcdir/../lib/$sourcename") {
  47. # this is our source
  48. # print "$func() at $source:$line\n";
  49. $us++;
  50. } #else {print "Not our source: $func, $source, $line\n";}
  51. }
  52. }
  53. else {
  54. if($us) {
  55. # the stack trace included source details about us
  56. $error++;
  57. if($leak) {
  58. push @o, "\n Leaked $leak bytes\n";
  59. }
  60. if($invalidread) {
  61. push @o, "\n Read $invalidread invalid bytes\n";
  62. }
  63. if($uninitedvar) {
  64. push @o, "\n Conditional jump or move depends on uninitialised value(s)\n";
  65. }
  66. }
  67. $bt = 0; # no more backtrace
  68. $us = 0;
  69. }
  70. }
  71. else {
  72. if($_ =~ /(\d+) bytes in (\d+) blocks are definitely lost/) {
  73. $leak = $1;
  74. if($leak) {
  75. $error++;
  76. }
  77. $bt = 1;
  78. }
  79. elsif($_ =~ /Invalid read of size (\d+)/) {
  80. $invalidread = $1;
  81. $error++;
  82. $bt = 1;
  83. }
  84. elsif($_ =~ /Conditional jump or move/) {
  85. # If we require SSL, this test case most probaly makes
  86. # us use OpenSSL. OpenSSL produces numerous valgrind
  87. # errors of this kind, rendering it impossible for us to
  88. # detect (valid) reports on actual curl or libcurl code.
  89. if(!$sslenabled) {
  90. $uninitedvar = 1;
  91. $error++;
  92. $bt = 1;
  93. }
  94. else {
  95. $partial=1;
  96. }
  97. }
  98. }
  99. }
  100. close(VAL);
  101. return @o;
  102. }
  103. 1;