From d4728072a43c5757c9b772632e7c3432240bafa1 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Tue, 21 Apr 2020 16:52:54 -0700 Subject: [PATCH 1/2] boot-qemu.sh: Add the ability to debug with GDB Adding '-s -S' stops the CPU and allows us to connect with GDB via 'target remote :1234'. This implies '-i' so that the machine does not get killed in the middle of debugging. Signed-off-by: Nathan Chancellor --- boot-qemu-help.txt | 3 +++ boot-qemu.sh | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/boot-qemu-help.txt b/boot-qemu-help.txt index 11b13d9..f5080c8 100644 --- a/boot-qemu-help.txt +++ b/boot-qemu-help.txt @@ -25,6 +25,9 @@ Optional parameters: -d | --debug: Invokes 'set -x' for debugging the script. + -g | --gdb: + Add '-s -S' to the QEMU invocation to allow debugging via GDB. + -h | --help: Prints this message then exits. diff --git a/boot-qemu.sh b/boot-qemu.sh index 5a5541d..d891053 100755 --- a/boot-qemu.sh +++ b/boot-qemu.sh @@ -31,6 +31,10 @@ function parse_parameters() { -d|--debug) set -x ;; + -g|--gdb) + GDB=true + INTERACTIVE=true ;; + -h|--help) echo cat "${BASE}"/boot-qemu-help.txt @@ -177,6 +181,7 @@ function setup_qemu_args() { # Invoke QEMU function invoke_qemu() { ${INTERACTIVE} || QEMU=( timeout "${TIMEOUT:=3m}" unbuffer "${QEMU[@]}" ) + ${GDB:=false} && QEMU=( "${QEMU[@]}" -s -S ) set -x "${QEMU[@]}" \ From 3379b3845683c581a30554ba7095be1e106e0e55 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Wed, 22 Apr 2020 16:54:32 -0700 Subject: [PATCH 2/2] boot-qemu.sh: Add message when GDB debugging option is used Suggested-by: Nick Desaulniers Signed-off-by: Nathan Chancellor --- boot-qemu.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/boot-qemu.sh b/boot-qemu.sh index d891053..cd13a4e 100755 --- a/boot-qemu.sh +++ b/boot-qemu.sh @@ -181,7 +181,21 @@ function setup_qemu_args() { # Invoke QEMU function invoke_qemu() { ${INTERACTIVE} || QEMU=( timeout "${TIMEOUT:=3m}" unbuffer "${QEMU[@]}" ) - ${GDB:=false} && QEMU=( "${QEMU[@]}" -s -S ) + if ${GDB:=false}; then + # Print message in bold green + printf '\033[01;32m' + echo + echo "Starting QEMU with GDB connection on port 1234..." + echo + echo "Use:" + echo + printf '\ttarget remote :1234\n' + echo + echo "to connect" + echo + printf '\033[0m' + QEMU=( "${QEMU[@]}" -s -S ) + fi set -x "${QEMU[@]}" \