#! /bin/sh -e

usage()
{
    echo "$@" >&2
    echo "Usage: $0 System.map dumpfile" >&2
    echo "  Initialized the dumpfile and arms the dumper" >&2
    exit 1
}

if [ $# -ne 2 ]; then usage Need two args; fi

# Make the device if required.
[ -r /dev/oopser ] || mknod /dev/oopser c 240 0

[ -r $1 ] || usage "Can't read System.map from $1"

echo Feeding in symbols from $1...
# Filter out everything from _stext to _etext.
awk '/ _stext/ { TEXT=1; } / _etext/ { TEXT = 0; print $1,$3; } / [tT ] / { if (TEXT) print $1, $3; }' < $1 | ./oopsd --add-symbols kernel

echo Arming the oopser...
./oopsd --arm $2

echo Done.
