akaros/scripts/bt-akaros.sh
<<
>>
Prefs
   1#!/bin/bash
   2# Barret Rhoden (brho@cs.berkeley.edu)
   3#
   4# Resolves functions from Akaros backtraces, both user and kernel.
   5# Pipe a backtrace (echo "huge-copy-paste" | ./thisfile.sh) to it.
   6#
   7# There are a few environment variables you may want to override, which control
   8# the location of the binaries and libraries.  If you use AKAROS_ROOT, KFS, and
   9# x86, just stick with the defaults.
  10
  11: ${SOLIBS_PREFIX:=$AKAROS_ROOT/kern/kfs/lib/}
  12: ${SO_REGEX:=.*so$}
  13: ${BIN_PREFIX:=$AKAROS_ROOT/kern/kfs/bin/}
  14: ${KERNEL_BINARY:=$AKAROS_ROOT/obj/kern/akaros-kernel-64b}
  15
  16# takes the path to the binary and offset (offset in hex), prints name of the
  17# function where the offset is in the binary.  basically a wrapper for
  18# addr2line.
  19print_user_func() {
  20        addr2line -e $1 -fC $2 | xargs
  21}
  22
  23kernel_line() {
  24        line=$1
  25
  26        addr=`echo $line | cut -c 7-25`
  27        frame_num=`echo $line | cut -f 1 -d ' '`
  28
  29        IFS=' '
  30        addr2line -afip -e $KERNEL_BINARY $addr | while read -ra RET
  31        do
  32                if [ "${RET[0]}" == "(inlined" ]; then
  33                        # (inlined by) with spaces to line up with a 64 bit addr
  34                        addr="   ${RET[0]} ${RET[1]}   "
  35                        func="${RET[2]}"
  36                        srcl="${RET[4]}"
  37                else
  38                        addr="${RET[0]}"
  39                        addr="${addr%?}"        # drop the trailing ':'
  40                        func="${RET[1]}"
  41                        srcl="${RET[3]}"
  42                fi
  43                # sed cleans out build paths.  All kernel files start with
  44                # '/kern', unlike arbitrary user binaries.
  45                srcl=`echo $srcl | sed 's/^.*\/kern\//kern\//'`
  46                echo "$frame_num [<$addr>] in ${func}() at $srcl"
  47        done
  48}
  49
  50user_line() {
  51        line=$1
  52
  53        binary=`echo $line | cut -f 6 -d ' '`
  54        lib_off=`echo $line | cut -f 9 -d ' '`
  55        app_off=`echo $line | cut -f 3 -d ' '`
  56
  57        echo -n $line " "
  58        if [[ $binary =~ $SO_REGEX ]]; then
  59                # could also do addr=$(print_user_func $lib $off)
  60                print_user_func $SOLIBS_PREFIX/$binary $lib_off
  61        else
  62                print_user_func $BIN_PREFIX/$binary $app_off
  63        fi
  64}
  65
  66while read line; do
  67        fifth_char=`echo $line | cut -c 5`
  68
  69        if [[ $fifth_char == "[" ]]; then
  70                kernel_line "$line"
  71        elif [[ $fifth_char == "A" ]]; then
  72                user_line "$line"
  73        fi
  74done
  75