diff options
author | Konstantin Aladyshev <aladyshev22@gmail.com> | 2021-07-18 20:26:14 +0300 |
---|---|---|
committer | Konstantin Aladyshev <aladyshev22@gmail.com> | 2021-07-18 20:26:14 +0300 |
commit | bca74f05f331ccb65f6243b39645efc60211a1ca (patch) | |
tree | bf64db409511fd0786b921fa52e73f549526f36c /scripts | |
parent | c925f40c2ad6f5e4d7a97eab30ca168ca4e62596 (diff) | |
download | UEFI-Lessons-bca74f05f331ccb65f6243b39645efc60211a1ca.tar.gz UEFI-Lessons-bca74f05f331ccb65f6243b39645efc60211a1ca.tar.bz2 UEFI-Lessons-bca74f05f331ccb65f6243b39645efc60211a1ca.zip |
Add run_gdb_ovmf.sh script for OVMF debug
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/run_gdb_ovmf.sh | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/scripts/run_gdb_ovmf.sh b/scripts/run_gdb_ovmf.sh new file mode 100755 index 0000000..fc283d0 --- /dev/null +++ b/scripts/run_gdb_ovmf.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +##### Controllable parameters ##### +QEMU_SHARED_FOLDER=~/UEFI_disk +################################### + +function show_help { + echo "Description:" + echo " run_gdb_ovmf.sh is a script that helps to debug OVMF" + echo "" + echo "Usage: run_gdb_ovmf.sh [-1] [-q <dir>]" + echo " -1 This is a first run of this configuration" + echo " (in this case before main gdb launch there would be another QEMU start that will create 'debug.log' file)" + echo " -q <dir> QEMU shared directory" + echo " (by default it is equal to QEMU_SHARED_FOLDER variable in the head of the script)" + echo "" + echo "Examples:" + echo " run_gdb_ovmf.sh -1 - create 'debug.log' file with the necessary address information" + echo " and debug OVMF it with gdb" + echo " run_gdb_ovmf.sh - debug OVMF with gdb ('debug.log' was created in the last run, no need to remake it again)" +} + + +# A POSIX variable +OPTIND=1 # Reset in case getopts has been used previously in the shell. + +while getopts "h?1q:" opt; do + case "$opt" in + h|\?) + show_help + exit 0 + ;; + 1) FIRST_RUN=1 + ;; + q) QEMU_SHARED_FOLDER=$OPTARG + ;; + esac +done + +shift $((OPTIND-1)) + +[ "${1:-}" = "--" ] && shift + + + +function test_file { + FILE_NAME=$1 + if [[ ! -f ${FILE_NAME} ]]; then + echo "Error! There is no file ${FILE_NAME}" + exit 1; + fi +} + +OVMF="Build/OvmfX64/DEBUG_GCC5/FV/OVMF.fd" + +test_file "${OVMF}" + + +if [[ ! -z "${FIRST_RUN}" || ! -f debug.log ]]; then + touch debug.log + # If it is a first run, we need to create 'debug.log' file for addresses + tmux new-session \; \ + send-keys "tail -f debug.log" Enter \; \ + split-window -v \; \ + send-keys "qemu-system-x86_64 \ + -drive if=pflash,format=raw,readonly,file=${OVMF} \ + -drive format=raw,file=fat:rw:${QEMU_SHARED_FOLDER} \ + -net none \ + -nographic \ + -global isa-debugcon.iobase=0x402 \ + -debugcon file:debug.log \ + -s" C-m Enter \; +fi + +touch debug_temp.log +tmux new-session \; \ + send-keys "gdb -ex 'source efi.py' -tui" Enter \; \ + split-window -h \; \ + send-keys "tail -f debug_temp.log" Enter \; \ + split-window -v \; \ + send-keys "qemu-system-x86_64 \ + -drive if=pflash,format=raw,readonly,file=${OVMF} \ + -drive format=raw,file=fat:rw:${QEMU_SHARED_FOLDER} \ + -net none \ + -nographic \ + -global isa-debugcon.iobase=0x402 \ + -debugcon file:debug_temp.log \ + -s -S" C-m Enter \; \ + select-pane -t 0 \; \ + send-keys "efi -64" Enter \; \ + send-keys "target remote :1234" Enter \; + + |