#!/bin/sh progname="$(basename "$(readlink -f "$0")")" die() { ec="$1" shift echo "$@" exit "$ec" } GDB="arm-none-eabi-gdb" [ $# -lt 1 ] && die 1 "usage: $progname DEVICE [gdb args...]" DEVICE="$1" shift if [ $# -eq 0 ] ; then # automatically add --se flag if executable can be found exec="$(find . -maxdepth 3 -name '*.elf' | head -n1)" [ -n "$exec" ] && set -- --se="$exec" fi [ -n "$(echo "$*" | grep -i zephyr)" ] && GDB="arm-zephyr-eabi-gdb" fork JLinkGDBServerCLExe \ -device "$DEVICE" \ -select USB \ -endian little \ -if SWD \ -speed auto \ -singlerun \ -noir \ -nologtofile \ -silent # append startup attach command to args set -- --eval-command="target extended-remote :2331" "$@" # launch gdb and forward any other args to it exec "$GDB" "$@"