2 # -----------------------------------------------------------------------------
6 # This program will inspect a log file with relay information and tell you
7 # whether calls and returns match. If not, this suggests that the parameter
8 # list might be incorrect. (It could be something else also.)
10 # Copyright 1997-1998 Morten Welinder (terra@diku.dk)
13 # This library is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU Lesser General Public
15 # License as published by the Free Software Foundation; either
16 # version 2.1 of the License, or (at your option) any later version.
18 # This library is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # Lesser General Public License for more details.
23 # You should have received a copy of the GNU Lesser General Public
24 # License along with this library; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 # -----------------------------------------------------------------------------
30 my $srcfile = $ARGV[0];
31 my %tid_callstack = ();
35 open (IN, "<$srcfile") || die "Cannot open $srcfile for reading: $!\n";
40 if (/^([0-9a-f]+):Call ([A-Za-z0-9]+\.[A-Za-z0-9_]+)\((.*\)) .*/ ||
41 /^([0-9a-f]+):CALL ([A-Za-z0-9]+\.[A-Za-z0-9_]+: [A-Za-z0-9]+)\((.*\)) .*/) {
45 # print "have call func=$func <$_>\n";
46 if (/ ret=(........)$/ ||
47 / ret=(....:....) (ds=....)$/ ||
48 / ret=(........) fs=....$/) {
52 $segreg = "none" unless defined $segreg;
54 push @{$tid_callstack{$tid}}, [$func, $retaddr, $segreg];
57 # Assume a line got cut by a line feed in a string.
60 print "Err[$tid] string probably cut by newline at line $. .\n";
68 if (/^([0-9a-f]+):Ret ([A-Za-z0-9]+\.[A-Za-z0-9_]+)\(.*\) .* ret=(........)$/ ||
69 /^([0-9a-f]+):Ret ([A-Za-z0-9]+\.[A-Za-z0-9_]+)\(.*\) .* ret=(....:....) (ds=....)$/ ||
70 /^([0-9a-f]+):Ret ([A-Za-z0-9]+\.[A-Za-z0-9_]+)\(.*\) .* ret=(........) fs=....$/ ||
71 /^([0-9a-f]+):RET ([A-Za-z0-9]+\.[A-Za-z0-9_]+: [A-Za-z0-9]+)\(.*\) .* ret=(........)$/) {
76 my ($topfunc,$topaddr,$topseg);
78 # print "have ret func=$func <$_>\n";
79 if (!defined($tid_callstack{$tid}))
81 print "Err[$tid]: unknown tid\n";
85 $segreg = "none" unless defined $segreg;
89 if ($#{$tid_callstack{$tid}} == -1) {
90 print "Err[$tid]: Return from $func to $retaddr with empty stack.\n";
94 ($topfunc,$topaddr,$topseg) = @{pop @{$tid_callstack{$tid}}};
96 if ($topfunc ne $func) {
97 print "Err[$tid]: Return from $topfunc, but call from $func.\n";
103 my $addrok = ($topaddr eq $retaddr);
104 my $segok = ($topseg eq $segreg);
105 if ($addrok && $segok) {
106 print "Ok [$tid]: ", ($indentp ? (' ' x (1 + $#{$tid_callstack{$tid}})) : '');
107 print "$func from $retaddr with $segreg.\n";
109 print "Err[$tid]: Return from $func is to $retaddr, not $topaddr.\n"
111 print "Err[$tid]: Return from $func with segreg $segreg, not $topseg.\n"
117 foreach my $tid (keys %tid_callstack) {
118 while ($#{$tid_callstack{$tid}} != -1) {
119 my ($topfunc,$topaddr,$topseg) = @{pop @{$tid_callstack{$tid}}};
120 print "Err[$tid]: leftover call to $topfunc from $topaddr.\n";