aboutsummaryrefslogtreecommitdiff
path: root/.local/share/bin/dbg
diff options
context:
space:
mode:
Diffstat (limited to '.local/share/bin/dbg')
-rwxr-xr-x.local/share/bin/dbg40
1 files changed, 40 insertions, 0 deletions
diff --git a/.local/share/bin/dbg b/.local/share/bin/dbg
new file mode 100755
index 0000000..424110b
--- /dev/null
+++ b/.local/share/bin/dbg
@@ -0,0 +1,40 @@
+#!/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" "$@"
+