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
61
62
63
64
65
66
|
"""
GDB Python script for debugging raisernics under QEMU.
Usage:
1. Terminal 1: ./scripts/run.sh --debug (GDB stub on :1234)
Add PROFILE=debug for line-level symbols (slower guest).
2. Terminal 2: gdb -x scripts/debug-kernel.py
"""
import gdb
import os
# Find the kernel binary (debug profile preferred, release as fallback)
script_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.dirname(script_dir)
candidates = [
os.path.join(project_root, "target/x86_64-unknown-uefi/debug/rsdos.efi"),
os.path.join(project_root, "target/x86_64-unknown-uefi/release/rsdos.efi"),
]
binary = next((c for c in candidates if os.path.exists(c)), candidates[0])
# Connect to QEMU's GDB stub
gdb.execute("target remote :1234")
# Load the binary (add symbol table)
if os.path.exists(binary):
gdb.execute(f"symbol-file {binary}")
print(f"Loaded symbols from {binary}")
else:
print(f"WARNING: {binary} not found. Build with debug symbols first.")
gdb.execute("set breakpoint pending on")
# Helper commands
class DumpBootServices(gdb.Command):
"""Dump EFI boot services signature and key pointers"""
def __init__(self):
super().__init__("dump-bs", gdb.COMMAND_USER)
def invoke(self, argument, from_tty):
del argument, from_tty
gdb.execute("printf \"SystemTable, BootServices, and key function pointers\\n\"")
gdb.execute("info functions efi_main")
class DumpGop(gdb.Command):
"""Dump GOP framebuffer info"""
def __init__(self):
super().__init__("dump-gop", gdb.COMMAND_USER)
def invoke(self, argument, from_tty):
del argument, from_tty
gdb.execute("printf \"Check the gop::Framebuffer static\\n\"")
DumpBootServices()
DumpGop()
print("")
print("raisernics GDB session ready.")
print(" target remote :1234 (connected)")
print(" Commands: continue, stepi, bt, info registers, etc.")
print(" Custom: dump-bs, dump-gop")
|