1#!/usr/bin/perl -w 2use 5.010; 3use strict; 4use warnings; 5 6############################################################################### 7# 8# Build SIPE with: 9# 10# CFLAGS="-g -O0" ./configure 11# 12# Grab a log with: 13# 14# G_DEBUG="gc-friendly" G_SLICE="always-malloc" valgrind --leak-check=yes \ 15# /usr/bin/pidgin --debug 2>&1 | tee pidgin_debug.log 16# 17# Analyze log with: 18# 19# perl contrib/debug/parse_valgrind.pl pidgin_debug.log 20# 21############################################################################### 22my @heap_lines; 23my @last_heap_lines; 24my $invalid_lines; 25my @all_invalid_lines; 26my $other_lines; 27 28# For all lines from command line files or STDIN 29while (<>) { 30 next unless my($remainder) = /^==\d+== (.*)/; 31 32 if ($remainder eq "HEAP SUMMARY:") { 33 @heap_lines = ($remainder); 34 35 undef $invalid_lines; 36 undef $other_lines; 37 38 } elsif ($remainder =~ /^ERROR SUMMARY:/) { 39 # keep only the last heap summary 40 @last_heap_lines = @heap_lines; 41 42 undef @heap_lines; 43 44 } elsif ($remainder =~ /^Invalid /) { 45 # collect all invalid lines 46 push(@all_invalid_lines, $remainder); 47 48 undef @heap_lines; 49 $invalid_lines++; 50 undef $other_lines; 51 52 } elsif ($remainder =~ /^Conditional/) { 53 undef @heap_lines; 54 undef $invalid_lines; 55 $other_lines++ 56 57 } elsif (@heap_lines) { 58 push(@heap_lines, $remainder); 59 60 } elsif (defined($invalid_lines)) { 61 push(@all_invalid_lines, $remainder); 62 63 } elsif (defined($other_lines)) { 64 undef $other_lines if $remainder eq ""; 65 66 } else { 67 #print "UNKNOWN: $remainder\n"; 68 } 69} 70 71sub check_blocks($$$) { 72 my($label, $start, $lines) = @_; 73 my @block; 74 my $flagged; 75 76 print "$label:\n\n"; 77 foreach (@{$lines}) { 78 if (/$start/../^$/) { 79 push(@block, $_); 80 81 # matcher for SIPE code lines 82 $flagged++ 83 if /\((?:sipe-|sip-|sdpmsg|sipmsg|http-|uuid|purple-|telepathy-)/; 84 85 if (length($_) == 0) { 86 print join("\n", @block), "\n\n" if $flagged; 87 undef @block; 88 undef $flagged; 89 } 90 } 91 } 92} 93 94check_blocks("INVALID ACCESSES", qr/^Invalid /, \@all_invalid_lines); 95check_blocks("MEMORY LEAKS", qr/^\d+ bytes in \d+ blocks/, \@last_heap_lines); 96 97# That's all folks... 98exit 0; 99