diff options
Diffstat (limited to 'scripts/qemu_gdb_attach.sh')
| -rw-r--r-- | scripts/qemu_gdb_attach.sh | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/scripts/qemu_gdb_attach.sh b/scripts/qemu_gdb_attach.sh new file mode 100644 index 0000000..310c196 --- /dev/null +++ b/scripts/qemu_gdb_attach.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# qemu_gdb_attach.sh - Launch QEMU with GDB server for guest kernel debugging +# Usage: ./qemu_gdb_attach.sh [gdb_port] [freeze_at_start] + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BASE_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" + +GDB_PORT="${1:-1234}" +FREEZE="${2:-true}" # -S flag to freeze at startup + +# Default QEMU command from launch_qemu_vgpu.sh +QEMU_CMD=( + qemu-system-x86_64 + -enable-kvm + -cpu host + -smp 4 + -m 8G + -device vfio-pci,sysfsdev=/sys/bus/mdev/devices/$(cat /sys/bus/mdev/devices/*/uuid 2>/dev/null | head -1),display=off + -drive file=/var/lib/libvirt/images/ubuntu-vgpu.qcow2,format=qcow2,if=virtio + -netdev user,id=net0,hostfwd=tcp::2222-:22 + -device virtio-net-pci,netdev=net0 + -nographic + -serial mon:stdio +) + +# Add GDB server options +if [[ "$FREEZE" == "true" ]]; then + QEMU_CMD+=(-s -S) # -s = gdbserver on :1234, -S = freeze at startup +else + QEMU_CMD+=(-s) # -s = gdbserver on :1234, run normally +fi + +# Override port if specified +if [[ "$GDB_PORT" != "1234" ]]; then + QEMU_CMD+=(-gdb "tcp::$GDB_PORT") +fi + +echo "==========================================" +echo "QEMU GDB Debug Launch" +echo "==========================================" +echo "GDB Port: $GDB_PORT" +echo "Freeze at start: $FREEZE" +echo "QEMU Command: ${QEMU_CMD[*]}" +echo "" +echo "In another terminal, connect with:" +echo " gdb ./vmlinux" +echo " (gdb) target remote localhost:$GDB_PORT" +echo " (gdb) break nvidia_probe" +echo " (gdb) continue" +echo "" +echo "Or use the GDB script:" +echo " gdb -x $BASE_DIR/tools/gdb_scripts/nvidia_init.gdb ./vmlinux" +echo "" + +# Launch QEMU +exec "${QEMU_CMD[@]}"
\ No newline at end of file |
