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