-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.sh
More file actions
executable file
·48 lines (37 loc) · 926 Bytes
/
debug.sh
File metadata and controls
executable file
·48 lines (37 loc) · 926 Bytes
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
#!/bin/bash
set -e
OUT="$1"
if [ -z "$OUT" ]; then
echo "Usage: $0 <program.elf>"
exit 1
fi
if [ ! -f "$OUT" ]; then
echo "[-] Error: File $OUT does not exist"
exit 1
fi
pkill -f "qemu-riscv64.*1235" 2>/dev/null && echo "[+] Killed existing QEMU" || echo "[-] No QEMU to kill"
sleep 2
while ss -ln | grep -q ":1235 "; do
echo "[+] Waiting for port 1235 to be free..."
sleep 1
done
echo "[+] Starting QEMU in debug mode..."
qemu-riscv64 -g 1235 "$OUT" &
QEMU_PID=$!
echo "[+] Waiting for QEMU to be ready..."
sleep 3
cleanup() {
echo "[+] Cleaning up QEMU..."
kill $QEMU_PID 2>/dev/null || true
}
trap cleanup EXIT INT TERM
echo "[+] Connecting GDB..."
gdb-multiarch \
-ex "set architecture riscv:rv64" \
-ex "file $OUT" \
-ex "target remote localhost:1235" \
-ex "tui enable" \
-ex "layout regs" \
-ex "break main" \
-ex "continue"
echo "[+] GDB session ended"