From 3e7fdebda3715f38dda0ca303a434d9f7b09a067 Mon Sep 17 00:00:00 2001 From: Roberto Rosmaninho Date: Wed, 4 Oct 2023 15:03:41 -0300 Subject: [PATCH] Introduces `--debugger-command` flag to krun (#3687) This PR reflects a new modification on the `llvm-krun` from the llvm-backend. This new flag enables the user to pass a file with debug commands to its debugger and run them in a non-interactive mode! This new flag also allows testing the debugger on our current CI. --- k-distribution/src/main/scripts/bin/krun | 31 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/k-distribution/src/main/scripts/bin/krun b/k-distribution/src/main/scripts/bin/krun index 7f684964a01..e5e88599fe4 100755 --- a/k-distribution/src/main/scripts/bin/krun +++ b/k-distribution/src/main/scripts/bin/krun @@ -37,12 +37,16 @@ filterSubst= if [[ "$OSTYPE" == "darwin"* ]]; then LLDB_FILE="$(dirname "$0")/../lib/kllvm/lldb/k_lldb_path" if [ -f "$LLDB_FILE" ]; then - DBG_CMD="$(cat "$LLDB_FILE") -- " + DBG_EXE="$(cat "$LLDB_FILE")" else - DBG_CMD="lldb --" + DBG_EXE="lldb" fi + DBG_CMD=" --" + DBG_FLAG=" -s " else - DBG_CMD="gdb --args " + DBG_EXE="gdb" + DBG_FLAG=" -x " + DBG_CMD=" --args " fi @@ -112,6 +116,10 @@ $KRUN options: parser. This can be overridden with -p. --debugger Launch the backend in a debugging console. Currently only supported on LLVM backend. + --debugger-batch Launch the backend in a debugging console in batch + mode. Currently only supported on LLVM backend. + --debugger-command FILE Execute GDB commands from FILE to debug program. + Currently only supported on LLVM backend. -d, --directory DIR [DEPRECATED] Look for a kompiled directory ending in "-kompiled" under the directory DIR. --dry-run Do not execute backend, but instead print the @@ -392,9 +400,24 @@ do ;; --debugger) - cmdprefix="$DBG_CMD" + cmdprefix="$DBG_EXE $DBG_CMD" ;; + --debugger-command) + debugCommandFile="$2" + cmdprefix="$DBG_EXE $DBG_FLAG $debugCommandFile $DBG_CMD" + shift + ;; + + --debugger-batch) + if [[ $cmdprefix == *gdb* || $cmdprefix == *lldb* ]]; then + cmdprefix="$DBG_EXE --batch $DBG_FLAG $debugCommandFile $DBG_CMD" + else + DBG_CMD=" --batch $DBG_CMD" + fi + ;; + + --statistics) statistics=true ;;