From 7edefbf28185d23633e198ba6847348db88f8bca Mon Sep 17 00:00:00 2001 From: r4 Date: Mon, 25 Jul 2022 23:00:59 +0200 Subject: [PATCH] add GDB support --- cscript | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cscript b/cscript index 8b6bb73..4b5e109 100755 --- a/cscript +++ b/cscript @@ -6,9 +6,13 @@ if [ -z "$1" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ]; then echo " $(basename "$0") ... <-option>... [-- ...]" echo "Or at the beginning of a C file:" echo " #!$(basename "$0") -s [...]" + echo + echo "To debug the program in GDB, just set CSCRIPT_GDB=1." exit 1 fi +[ -n "$CSCRIPT_GDB" ] && ([ "$CSCRIPT_GDB" = "0" ] || [ "$CSCRIPT_GDB" = "false" ]) && unset CSCRIPT_GDB + # Get file names, options and passed-through args basedir="." files="" @@ -53,6 +57,7 @@ arg() { for a in "$@"; do arg "$a" done +[ -n "$CSCRIPT_GDB" ] && opts="$(printf "%s\n%s" "$opts" "-ggdb")" # Remove empty lines files="$(printf "%s" "$files" | grep '.')" opts="$(printf "%s" "$opts" | grep '.')" @@ -82,6 +87,10 @@ if ! printf "%s\n%s" "$files" "$opts" | xargs -d'\n' cc -Wall -pedantic -o "$tmp cleanup exit 1 fi -printf "%s" "$args" | xargs -d'\n' "$tmpfile" +if [ -n "$CSCRIPT_GDB" ]; then + printf "%s" "$args" | xargs -o -d'\n' gdb --args "$tmpfile" +else + printf "%s" "$args" | xargs -d'\n' "$tmpfile" +fi trap - INT cleanup