#!/usr/local/bin/perl # -*-perl-*- # # Take a 'spin -a' dump and reformat it. Much more readable this way. # # This is in the public domain, you are merely a jerk if you # don't include this notice in a derived work. # $rc{0} = "0"; $rc{100} = "KR_USER_EXCEPTION"; $rc{101} = "KR_PAGE_FAULT"; $rc{102} = "KR_CANCEL"; $rc{103} = "KR_NO_MEMORY"; $rc{104} = "KR_RESTART"; $rc{199} = "KR_INVALID"; $blanks = " "; while (<>) { chop; if (m/proc\s*([0-9]).*line\s*([0-9]*)[^[]*\[(.*)\]/) { $proc = $1; # id number of process $line = $2; # file/line number info $cmd = $3; # the command $cmd = &mungeCommand($cmd); $spc = "$blanks |" x $proc; printf("(line %5.5d) %s%s%2d: %s\n", $line, $spc, $blanks, $proc, $cmd); } else { print "$_\n"; } } # # Some specific munge commands to bring the dump closer to # our sources. # sub mungeCommand { local($cmd) = @_; local($tmp); # restore the donewith macro return "*donewith($1)" if ($cmd =~ /(\w*)\s=\s\(1-1\)$/); # Restore disable and enable interrupts macros return "*disableInterrupts()" if ($cmd =~ /\(\(100==100\)\)/); return "*enableInterrupts()" if ($cmd =~ /\(\(101==101\)\)/); # Use KR_* menemonics for setting/checking rc if ($cmd =~ /rc\D*(\d+)/i && $rc{$1} ne "") { $cmd =~ s/(rc\D*)(\d+)/"$1$rc{$2}"/gie; } # Replace 2+ digit numeric constants with hex equivalents $cmd =~ s/(^|\s|[=&\-\(])([0-9]{2,})($|\s|[=&\-\)!])/sprintf("${1}0x%x$3", $2)/eg; # Prefix switch/if guards with "::" return ":: $cmd" if ($cmd =~ /^\(/); return ":: $cmd" if ($cmd =~ /^else$/); return $cmd; }