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=....)$/) {
51 $segreg = "none" unless defined $segreg;
53 push @
{$tid_callstack{$tid}}, [$func, $retaddr, $segreg];
56 # Assume a line got cut by a line feed in a string.
59 print "Err[$tid] string probably cut by newline.\n";
67 if (/^([0-9a-f]+):Ret ([A-Za-z0-9]+\.[A-Za-z0-9_]+)\(.*\) .* ret=(........)$/ ||
68 /^([0-9a-f]+):Ret ([A-Za-z0-9]+\.[A-Za-z0-9_]+)\(.*\) .* ret=(....:....) (ds=....)$/ ||
69 /^([0-9a-f]+):RET ([A-Za-z0-9]+\.[A-Za-z0-9_]+: [A-Za-z0-9]+)\(.*\) .* ret=(........)$/) {
74 my ($topfunc,$topaddr,$topseg);
76 # print "have ret func=$func <$_>\n";
77 if (!defined($tid_callstack{$tid}))
79 print "Err[$tid]: unknown tid\n";
83 $segreg = "none" unless defined $segreg;
87 if ($#{$tid_callstack{$tid}} == -1) {
88 print "Err[$tid]: Return from $func to $retaddr with empty stack.\n";
92 ($topfunc,$topaddr,$topseg) = @
{pop @
{$tid_callstack{$tid}}};
94 if ($topfunc ne $func) {
95 print "Err[$tid]: Return from $topfunc, but call from $func.\n";
101 my $addrok = ($topaddr eq $retaddr);
102 my $segok = ($topseg eq $segreg);
103 if ($addrok && $segok) {
104 print "Ok [$tid]: ", ($indentp ?
(' ' x
(1 + $#{$tid_callstack{$tid}})) : '');
105 print "$func from $retaddr with $segreg.\n";
107 print "Err[$tid]: Return from $func is to $retaddr, not $topaddr.\n"
109 print "Err[$tid]: Return from $func with segreg $segreg, not $topseg.\n"
115 foreach my $tid (keys %tid_callstack) {
116 while ($#{$tid_callstack{$tid}} != -1) {
117 my ($topfunc,$topaddr,$topseg) = @
{pop @
{$tid_callstack{$tid}}};
118 print "Err[$tid]: leftover call to $topfunc from $topaddr.\n";