Skip to content

Commit

Permalink
Add debug configuration for VSCode
Browse files Browse the repository at this point in the history
  • Loading branch information
fruhland committed Feb 21, 2024
1 parent bd4de7a commit dfc15d2
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 16 deletions.
21 changes: 20 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,26 @@ Cargo.lock
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# End of https://www.toptal.com/developers/gitignore/api/rust,clion+iml
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# End of https://www.toptal.com/developers/gitignore/api/rust,clion+iml,VisualStudioCode

d3os.img
efi/OVMF.fd
Expand Down
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "qemu-gdb",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/loader/kernel.elf",
"cwd": "${workspaceFolder}",
"miDebuggerPath": "/usr/bin/gdb",
"miDebuggerServerAddress": "localhost:1234",
"stopAtEntry": false,
"setupCommands": [
{ "text": "-enable-pretty-printing" },
{ "text": "set disassembly-flavor intel"}
],
"preLaunchTask": "qemu-gdb"
}
]
}
34 changes: 34 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "qemu-gdb",
"type": "shell",
"isBackground": true,
"command": "${workspaceRoot}/run.sh",
"args": ["--debug", "vscode"],
"problemMatcher": [
{
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".",
"endsPattern": "Debugging with VSCode...",
}
}
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false
}
}
]
}
31 changes: 16 additions & 15 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ readonly CONST_QEMU_ARGS="-boot d -vga std -rtc base=localtime -device isa-debug
readonly CONST_QEMU_OLD_AUDIO_ARGS="-soundhw pcspk"
readonly CONST_QEMU_NEW_AUDIO_ARGS="-audiodev id=pa,driver=pa -machine pcspk-audiodev=pa"
readonly CONST_QEMU_BOOT_DEVICE="-drive driver=raw,node-name=boot,file.driver=file,file.filename=d3os.img"
readonly CONST_QEMU_GDB_PORT="1234"

QEMU_BIOS=""
QEMU_MACHINE="${CONST_QEMU_MACHINE_PC}"
Expand All @@ -19,8 +20,7 @@ QEMU_CPU_OVERWRITE="false"
QEMU_AUDIO_ARGS="${CONST_QEMU_NEW_AUDIO_ARGS}"
QEMU_BOOT_DEVICE="${CONST_QEMU_BOOT_DEVICE}"
QEMU_ARGS="${CONST_QEMU_ARGS}"

QEMU_GDB_PORT=""
QEMU_DEBUG_TYPE=""

version_lt() {
test "$(printf "%s\n" "$@" | sort -V | tr ' ' '\n' | head -n 1)" != "${2}"
Expand Down Expand Up @@ -88,13 +88,14 @@ parse_cpu() {
}

parse_debug() {
local port=$1

echo "set architecture i386
set disassembly-flavor intel
target remote 127.0.0.1:${port}" >/tmp/gdbcommands."$(id -u)"
local type=$1

QEMU_GDB_PORT="${port}"
if [ "${type}" == "default" ] || [ "${type}" == "background" ] || [ "${type}" == "vscode" ]; then
QEMU_DEBUG_TYPE="${type}"
else
printf "Invalid debug type '%s'!\\n" "${type}"
exit 1
fi
}

parse_bios() {
Expand All @@ -115,7 +116,7 @@ print_usage() {
-c, --cpu
Set the CPU model, which qemu should emulate (e.g. 486, pentium, pentium2, ...) (Default: base)
-d, --debug
Set the port, on which qemu should listen for GDB clients (default: disabled)
Enable debugging with a debug type ([default] | [vscode]) (default: Disabled)
-b, --bios
Set the BIOS file, which qemu should use (Default: Download OVMF from Ubuntu 20.04 packages)
-h, --help
Expand Down Expand Up @@ -168,12 +169,12 @@ run_qemu() {

printf "Running: %s\\n" "${command}"

if [ -n "${QEMU_GDB_PORT}" ]; then
if [ "${QEMU_GDB_PORT}" == "1234" ]; then
$command -gdb tcp::"${QEMU_GDB_PORT}" -S &
else
$command -gdb tcp::"${QEMU_GDB_PORT}" -S
fi
if [ "${QEMU_DEBUG_TYPE}" == "default" ]; then
$command -gdb tcp::"${CONST_QEMU_GDB_PORT}" -S
elif [ "${QEMU_DEBUG_TYPE}" == "background" ]; then
$command -gdb tcp::"${CONST_QEMU_GDB_PORT}" -S &
elif [ "${QEMU_DEBUG_TYPE}" == "vscode" ]; then
echo "Debugging with VSCode..."; $command -gdb tcp::"${CONST_QEMU_GDB_PORT}" -S
else
$command
fi
Expand Down

0 comments on commit dfc15d2

Please sign in to comment.