summaryrefslogtreecommitdiffstats
path: root/scripts/qemu_gdb_attach.sh
diff options
context:
space:
mode:
authorArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-14 06:43:11 -0400
committerArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-14 06:43:11 -0400
commit5dd8165f1754e156a0f9fb16c7a6bfa90e99ed60 (patch)
tree7523e29d8044d4d5b6dcd7c1c888a3491137fcd1 /scripts/qemu_gdb_attach.sh
parent9a7263fce4e3156349a526631805fce66b87fb1b (diff)
downloadopen-iov-5dd8165f1754e156a0f9fb16c7a6bfa90e99ed60.tar.gz
open-iov-5dd8165f1754e156a0f9fb16c7a6bfa90e99ed60.zip
VFIO device registration fix + IOMMUFD callbacks + VFIO ioctl handlers
- Removed IOMMU group addition before vfio_register_emulated_iommu_dev() in nv_vgpu_mdev_create() - Added IOMMUFD callbacks (bind_iommufd, unbind_iommufd, attach_ioas, detach_ioas) using kernel's vfio_iommufd_emulated_* functions - Implemented VFIO ioctl handlers: GET_INFO, GET_REGION_INFO, GET_IRQ_INFO, SET_IRQS, MMAP - Added config space read/write handlers at offset 0x70000000000 - Mmap handler for config space, BAR0 (emulation shadow), BAR1-5 (physical VRAM/registers) - Interrupt handler for VFIO_DEVICE_SET_IRQS (DATA_EVENTFD, DATA_NONE, DATA_BOOL) - Added udev rules for vfio group permissions - Created stack_manager.sh unified tool - Fixed mdev remove crash with deferred cleanup in vfio_device_release callback - Kernel 6.8+ IOMMUFD compatibility - QEMU launches successfully with vGPU passthrough
Diffstat (limited to 'scripts/qemu_gdb_attach.sh')
-rw-r--r--scripts/qemu_gdb_attach.sh58
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