-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scripts: debug): add a script to start a debug session
Since switching to a higher-half kernel, placing the "target remote ..." inside the gdbinit script seems to make GDB crash. Having it executed as a CLI argument seems to be a working alternative. This script lets us chose which symbol we want to set a breakpoint on, instead of hardcoding it to kernel_main inside the gdbinit script.
- Loading branch information
Showing
2 changed files
with
40 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1 @@ | ||
# Connect to qemu's gdbserver | ||
target remote :1234 | ||
|
||
# Change layout | ||
layout reg | ||
|
||
# Continue execution until entering the kernel | ||
break kernel_main | ||
continue | ||
layout src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Start a GDB session connected to our kernel. | ||
# You can also pass in symbols to set breakpoints on as arguments. | ||
# | ||
# example: ./debug.sh kernel_main mmu_init | ||
|
||
# Absolute path to this script | ||
SCRIPT=$(readlink -f "$0") | ||
SCRIPTDIR=$(dirname "$SCRIPT") | ||
GITROOT="$SCRIPTDIR/.." | ||
|
||
if ! command -v gdb > /dev/null; then | ||
echo "[ERROR] GDB not found in path" >&2 | ||
exit 127 | ||
fi | ||
|
||
cd "$GITROOT" || exit | ||
|
||
BREAKPOINTS=() | ||
for symbol in "$@"; do | ||
BREAKPOINTS+=("-ex" "break $symbol") | ||
done | ||
|
||
if [ ! -d "build" ]; then | ||
echo "[INFO] build dir not found, setting up meson project" | ||
meson setup build --cross-file "scripts/meson_cross.ini" --reconfigure -Dbuildtype=debug | ||
fi | ||
|
||
echo "[INFO] Starting a debugging session" | ||
ninja -C build qemu-server || exit | ||
gdb -x .gdbinit --symbol ./build/kernel/kernel.sym \ | ||
-iex "set pagination of" \ | ||
-iex "target remote localhost:1234" \ | ||
"${BREAKPOINTS[@]}" \ | ||
-ex "continue" | ||
|
||
echo "[INFO] Terminating debugging session" | ||
pkill qemu |