xv6-vscode调试

.gdbinit

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
set $lastcs = -1

define hook-stop
# There doesn't seem to be a good way to detect if we're in 16- or
# 32-bit mode, but in 32-bit mode we always run with CS == 8 in the
# kernel and CS == 35 in user space
if $cs == 8 || $cs == 35
if $lastcs != 8 && $lastcs != 35
set architecture i386
end
x/i $pc
else
if $lastcs == -1 || $lastcs == 8 || $lastcs == 35
set architecture i8086
end
# Translate the segment:offset into a physical address
printf "[%4x:%4x] ", $cs, $eip
x/i $cs*16+$eip
end
set $lastcs = $cs
end

# 需要注释掉
# echo + target remote localhost:25000\n
# target remote localhost:25000

echo + symbol-file kernel\n
symbol-file kernel

launch.json

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
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug xv6 x86",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/kernel", // 修改kernel 或者 bootblock
"miDebuggerServerAddress": "localhost:25000",
"miDebuggerPath": "/usr/bin/gdb",
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"setupCommands": [
{
"text": "set architecture i386:x86-64"
},
{
"text": "set disassemble-next-line auto"
},
{
"description": "Enable pretty-print for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "xv6build",
"logging": {
"trace": true,
"traceResponse": true,
"engineLogging": true
}
}
]
}

tasks.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"version": "2.0.0",
"tasks": [
{
"label": "xv6build",
"type": "shell",
"isBackground": true,
"command": "make qemu-nox-gdb",
"problemMatcher": {
"pattern":{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
},
"background": {
"beginsPattern": ".* Now run 'gdb'.",
"endsPattern": "."
}
}
}
]
}