#! /bin/bash
export LD_LIBRARY_PATH=`pwd`

EXTRA_INPUT_ARGS=""

INPUT_ARGS=${@//[]/-} # replace bizarre minuses with normal one

./trex-cfg $INPUT_ARGS
RESULT=$?

if [ $RESULT -eq 255 ]; then
  echo "ERROR encountered while configuring trex system"
  exit $RESULT
fi

if [ $RESULT -eq 2 ]; then
  echo "ERROR encountered while configuring trex system"
  exit $RESULT
fi

                    
if [ $RESULT -eq 32 ]; then
  EXTRA_INPUT_ARGS="--mlx5-so"
fi

if [ $RESULT -eq 64 ]; then
  EXTRA_INPUT_ARGS="--ntacc-so"
fi

# comment out to enable watchdog
NO_WATCH="--no-watchdog"

saveterm="$(stty -g)"
/usr/bin/gdb --args ./_t-rex-64-debug $@ $NO_WATCH $EXTRA_INPUT_ARGS
stty $saveterm

