ia64/xen-unstable

changeset 1188:17dc27860023

bitkeeper revision 1.803 (4056f51d2UjBnn9uwzC9Vu3LspnUCg)

Simple oops analyser for Xen crashes.
author mwilli2@equilibrium.research.intel-research.net
date Tue Mar 16 12:37:49 2004 +0000 (2004-03-16)
parents b92991cbd303
children f94912902e71
files .rootkeys tools/misc/xensymoops.py
line diff
     1.1 --- a/.rootkeys	Tue Mar 16 10:54:07 2004 +0000
     1.2 +++ b/.rootkeys	Tue Mar 16 12:37:49 2004 +0000
     1.3 @@ -64,6 +64,7 @@ 401d7e16hWEsgEnMwbPM9sKyInomWw tools/mis
     1.4  3f8bcf29ulZIC9rC4wM70H_q4s6VPg tools/misc/xen_log.c
     1.5  3f13d81eQ9Vz-h-6RDGFkNR9CRP95g tools/misc/xen_nat_enable
     1.6  3f13d81e6Z6806ihYYUw8GVKNkYnuw tools/misc/xen_nat_enable.README
     1.7 +4056f5155QYZdsk-1fLdjsZPFTnlhg tools/misc/xensymoops.py
     1.8  4022a73cEKvrYe_DVZW2JlAxobg9wg tools/nsplitd/Makefile
     1.9  4022a73cKms4Oq030x2JBzUB426lAQ tools/nsplitd/nsplitd.c
    1.10  3fbca441SjQr8vJwTQIgH1laysaWog tools/xc/Makefile
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/misc/xensymoops.py	Tue Mar 16 12:37:49 2004 +0000
     2.3 @@ -0,0 +1,118 @@
     2.4 +#!/usr/bin/env python
     2.5 +
     2.6 +# An oops analyser for Xen
     2.7 +# Usage: xensymoops path-to-xen.s < oops-message
     2.8 +
     2.9 +# There's probably some more features that could go in here but this
    2.10 +# is sufficient to analyse most errors in my code ;-)
    2.11 +
    2.12 +# by Mark Williamson (C) 2004 Intel Research Cambridge
    2.13 +
    2.14 +import re, sys
    2.15 +
    2.16 +def read_oops():
    2.17 +    """Process an oops message on stdin and return (eip_addr, stack_addrs)
    2.18 +
    2.19 +    eip_addr is the location of EIP at the point of the crash.
    2.20 +    stack_addrs is a dictionary mapping potential code addresses in the stack
    2.21 +      to their order in the stack trace.
    2.22 +    """
    2.23 +    stackaddr_ptn = "\[([a-z,0-9]*)\]"
    2.24 +    stackaddr_re  = re.compile(stackaddr_ptn)
    2.25 +
    2.26 +    eip_ptn = ".*EIP:.*<([a-z,0-9]*)>.*"
    2.27 +    eip_re  = re.compile(eip_ptn)
    2.28 +
    2.29 +    matches = 0
    2.30 +    stack_addresses = {}
    2.31 +    eip_addr = "Not known"
    2.32 +
    2.33 +    while True:
    2.34 +        line = sys.stdin.readline()
    2.35 +        if not line: break
    2.36 +
    2.37 +        m = eip_re.match(line)
    2.38 +        if m: eip_addr = m.group(1)
    2.39 +        
    2.40 +        m = stackaddr_re.findall(line)
    2.41 +    
    2.42 +        for i in m:
    2.43 +            stack_addresses[i] = matches
    2.44 +            matches += 1
    2.45 +
    2.46 +    return (eip_addr, stack_addresses)
    2.47 +
    2.48 +def usage():
    2.49 +    print >> sys.stderr, """Usage: %s path-to-asm < oops-msg
    2.50 +    The oops message should be fed to the standard input.  The
    2.51 +    command-line argument specifies the path to the Xen assembly dump
    2.52 +    produced by \"make debug\".  The location of EIP and the backtrace
    2.53 +    will be output to standard output.
    2.54 +    """ % sys.argv[0]
    2.55 +    sys.exit()
    2.56 +
    2.57 +##### main
    2.58 +
    2.59 +if len(sys.argv) != 2:
    2.60 +    usage()
    2.61 +
    2.62 +# get address of EIP and the potential code addresses from the stack
    2.63 +(eip_addr, stk_addrs) = read_oops()
    2.64 +
    2.65 +# open Xen disassembly
    2.66 +asm_file = open(sys.argv[1])
    2.67 +
    2.68 +# regexp to match addresses of code lines in the objdump
    2.69 +addr_ptn = "([a-z,0-9]*):"
    2.70 +addr_re  = re.compile(addr_ptn)
    2.71 +
    2.72 +# regexp to match the start of functions in the objdump
    2.73 +func_ptn = "(.*<[\S]*>):"
    2.74 +func_re  = re.compile(func_ptn)
    2.75 +
    2.76 +func = "<No function>" # holds the name of the current function being scanned
    2.77 +
    2.78 +eip_func = "<No function>" # name of the function EIP was in
    2.79 +
    2.80 +# list of (position in original backtrace, code address, function) tuples
    2.81 +# describing all the potential code addresses we identified in the backtrace
    2.82 +# whose addresses we also located in the objdump output
    2.83 +backtrace = []
    2.84 +
    2.85 +while True:
    2.86 +    line = asm_file.readline()
    2.87 +    if not line: break
    2.88 +
    2.89 +    # if we've read the start of the function, record the name and address
    2.90 +    fm = func_re.match(line)
    2.91 +    if fm:
    2.92 +        func = fm.group(1)
    2.93 +        continue
    2.94 +
    2.95 +    # try match the address at the start of the line
    2.96 +    m = addr_re.match(line)
    2.97 +    if not m: continue
    2.98 +
    2.99 +    # we're on a code line...
   2.100 +
   2.101 +    address = m.group(1)
   2.102 +
   2.103 +    # if this address was seen as a potential code address in the backtrace then
   2.104 +    # record it in the backtrace list
   2.105 +    if stk_addrs.has_key(address):
   2.106 +        backtrace.append((stk_addrs[address], address, func))
   2.107 +
   2.108 +    # if this was the address that EIP...
   2.109 +    if address == eip_addr:
   2.110 +        eip_func = func
   2.111 +
   2.112 +
   2.113 +print "EIP %s in function %s" % (eip_addr, eip_func)
   2.114 +print "Backtrace:"
   2.115 +
   2.116 +# sorting will order primarily by the first element of each tuple,
   2.117 +# i.e. the order in the original oops
   2.118 +backtrace.sort()
   2.119 +
   2.120 +for (i, a, f) in backtrace:
   2.121 +    print "%s in function %s" % ( a, f )