Add qemu debugging for any recipes

This commit is contained in:
Wildan Mubarok 2025-08-01 06:37:09 +00:00
parent 2094548c40
commit fb890fdfbd
3 changed files with 28 additions and 0 deletions

View File

@ -19,6 +19,8 @@ CONFIG_NAME?=desktop
REPO_NONSTOP?=0
## Do not update source repos, attempt to build in offline condition
REPO_OFFLINE?=0
## Do not strip debug info for local build
REPO_DEBUG?=0
## Select filesystem config
ifeq ($(BOARD),)
FILESYSTEM_CONFIG?=config/$(ARCH)/$(CONFIG_NAME).toml
@ -67,6 +69,10 @@ ifeq ($(REPO_OFFLINE),1)
else ifeq ($(REPO_OFFLINE),0)
REPO_OFFLINE=
endif
ifeq ($(REPO_DEBUG),1)
export COOKBOOK_NOSTRIP=true
export COOKBOOK_DEBUG=true
endif
UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)

View File

@ -75,6 +75,7 @@ KERNEL_PATH := cookbook/recipes/core/kernel
KERNEL_PATH_SOURCE := $(ROOT)/$(KERNEL_PATH)/source
KERNEL_PATH_TARGET := $(ROOT)/$(KERNEL_PATH)/target/$(TARGET)
# TODO: make this work using `make debug.kernel` and remove this
kernel_debugger:
@echo "Building and running gdbgui container..."
podman build -t redox-kernel-debug - < $(ROOT)/podman/redox-gdb-containerfile

View File

@ -137,3 +137,24 @@ else
$(MAKE) uc.$*
$(MAKE) f.$*
endif
export DEBUG_BIN?=
# Debug a recipe with gdbgui inside podman, for example: debug.drivers-initfs DEBUG_BIN=pcid
# Please set REPO_DEBUG=1 to your .config to enable debug symbols and run `make cr.recipe rebuild`
# Also, before opening gdbgui at http://localhost:5000, start qemu with `make qemu gdb=yes`
# Experimental and may not work if ARCH is different with what podman is running
debug.%: $(FSTOOLS_TAG) FORCE
@cd cookbook/$(shell make find.$* | grep ^recipes) && \
export RECIPE_STAGE=target/$(TARGET)/stage && \
export BIN_PATH=$$(find $$RECIPE_STAGE -type f -name "$(DEBUG_BIN)" -or -type f -name "$*") && \
file $$BIN_PATH 2> /dev/null || ( echo "Binary is not found, please set DEBUG_BIN" && exit 1 ) && \
echo "Opening gdbgui for debugging $* with binary '$$BIN_PATH'" && echo "----------" && \
podman build -t redox-kernel-debug - < $(ROOT)/podman/redox-gdb-containerfile > /dev/null && \
podman run --rm -p 5000:5000 -it --name redox-gdb \
-v "./$$BIN_PATH:/binary" \
-v "./source:/source" -w "/source" \
redox-kernel-debug --gdb-cmd "gdb -ex 'set confirm off' \
-ex 'add-symbol-file /binary' \
-ex 'target remote host.containers.internal:1234'"