home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5686 < prev    next >
Encoding:
Text File  |  1992-09-02  |  3.3 KB  |  109 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!darwin.sura.net!uvaarpa!mmdf
  3. From: Alan Stebbens <aks%anywhere@hub.ucsb.edu>
  4. Subject: "panicanal": vmunix panic analyzer
  5. Message-ID: <1992Sep2.201803.20778@uvaarpa.Virginia.EDU>
  6. Sender: mmdf@uvaarpa.Virginia.EDU (Mail System)
  7. Reply-To: aks%anywhere@hub.ucsb.edu
  8. Organization: The Internet
  9. Date: Wed, 2 Sep 1992 20:18:03 GMT
  10. Lines: 97
  11.  
  12. The following is a first-cut attempt Perl script at parsing panic dump
  13. output.  The script accepts a filename argument, defaulting to
  14. /var/adm/messages, and scans the file for "vmunix: panic:" messages.  If
  15. there is any subsequent traceback listing, they are listed along with
  16. the symbolic addresses and instructions at those locations using adb
  17. queries on the kernel code.
  18.  
  19. A really clever script would even attempt to parse the arg lists and
  20. show the values at the corresponding addresses, but this script isn't
  21. that one (yet).
  22.  
  23. Enjoy.
  24.  
  25. Alan Stebbens        <aks@hub.ucsb.edu>             (805) 893-3221
  26.      Center for Computational Sciences and Engineering (CCSE)
  27.           University of California, Santa Barbara (UCSB)
  28.            3111 Engineering I, Santa Barbara, CA 93106
  29.  
  30. ============================= cut here ===================================
  31. #!/bin/perl -s
  32. # panicanal [-i] [file]
  33. #
  34. # $Revision: 1.2 $ $Date: 1992/09/02 19:06:10 $
  35. # Alan K. Stebbens <aks@hub.ucsb.edu>, CCSE, UCSB
  36. #
  37. # Do analysis of vmunix panic's as written in file (default is
  38. # /var/adm/messages).
  39. #
  40. # If -a given, do all dumps, otherwise, interact with the user
  41. # If STDOUT is not a tty, assume -a.
  42. #
  43. $all = $a unless $all;
  44. $dumpfile = '/var/adm/messages' unless $dumpfile = shift;
  45. die "$dumpfile doesn't exist" unless -f $dumpfile;
  46.  
  47. $interact = $all ? '' : -t;
  48.  
  49. open(DUMP,$dumpfile) || die "Can't read $dumpfile because $!\n";
  50. $defans = 'n';                # initial default answer is 'no'
  51. while (<DUMP>) {
  52.     next unless /vmunix: panic:/;
  53.     chop;
  54.     ($mon, $day, $time, $host, $what) = split(' ');
  55.     $thispanic = $1 if s/^(.* vmunix: )//;# strip leader
  56.     $what = $1 if /panic: (.*)/;
  57.     @panic = ($_);             # start saving the panic
  58.     $begin = 0;
  59.     while (<DUMP>) {
  60.     last unless s/^$thispanic//;    # quit when no more data
  61.     $begin++ if /Begin traceback\.\.\./;
  62.     chop;
  63.     push(@panic,$_);        # add to panic data
  64.     last if /End traceback\.\.\./;
  65.     }
  66.     next unless $begin;            # don't analyze without a traceback
  67.     if ($interact) {            # talk to user?
  68.     print "\nPanic: \"$what\" on $mon $day at $time, analyze (ynq)? [$defans]";
  69.     exit unless $ans = <STDIN>;
  70.     chop($ans);
  71.     $ans = $defans unless $ans;
  72.     $defans = $ans;            # new default
  73.     exit     if !index('quit',$ans);
  74.     next unless !index('yes',$ans);
  75.     }
  76.     &analyze;
  77. }
  78. close DUMP;
  79. exit;
  80.  
  81. sub analyze {
  82.     local($_);
  83.  
  84.     $addr = '';
  85.     $tmp = "/tmp/$$.anal";
  86.     open(TMP,">$tmp") || die "Can't open $tmp because $!\n";
  87.     @addrs = ();
  88.     foreach (@panic) {
  89.     printf "%s\n",$_;
  90.     next unless /Called from ([0-9a-f]+),/ || /pc=0x([0-9a-f]+),/;
  91.     $addr = $1;
  92.     print TMP "$addr?i\n";
  93.     push(@addrs,$addr);
  94.     }
  95.     close TMP;
  96.     open(ADB,"adb /vmunix < $tmp|") || die "Can't open pipe from adb because $!\n";
  97.     while (<ADB>) {
  98.     chop;
  99.     next if /^\s*$/;
  100.     $addr = shift @addrs;
  101.     if (!/text address not found/) {
  102.         ($symaddr,$instr) = ($1,$2) if /^([^:]+:)\s+(.*)/;
  103.         printf "%s: %-30s %s\n",$addr,$symaddr,$instr;
  104.     }
  105.     }
  106.     close ADB;
  107.     unlink $tmp;
  108. }
  109.