#!/bin/sh
while getopts "a" option
do
    case $option in
        a) attach=1;;
    esac
done

if test ! -x /bin/gdbserver
then
    (
        cd /;
        tftp -gr gdbserver-6.1.tar.bz2 192.168.20.3;
        tar xovjf gdbserver-6.1.tar.bz2;
        rm gdbserver-6.1.tar.bz2
    )
fi

if test $attach -eq 1
then
    micSplitIoPid=$(echo $(ps | grep MicSplitter | grep -v grep | cut -c-5) | cut -c-4)
    echo "/bin/gdbserver 192.168.20.3:2345 --attach $micSplitIoPid"
    /bin/gdbserver 192.168.20.3:2345 --attach $micSplitIoPid
else
    echo "/bin/gdbserver 192.168.20.3:2345 /upgradeable/bin/MicSplitter"
    /bin/gdbserver 192.168.20.3:2345 /upgradeable/bin/MicSplitter
fi
