blob: fb7597fac079e5fee179b313dc6d6cd471d39dce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/bin/bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2026 Open-IOV contributors
# 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[@]}"
|