From fb890fdfbdd3be7b67a798fd7914b0eaafcdeee4 Mon Sep 17 00:00:00 2001 From: Wildan Mubarok Date: Fri, 1 Aug 2025 06:37:09 +0000 Subject: [PATCH] Add qemu debugging for any recipes --- mk/config.mk | 6 ++++++ mk/podman.mk | 1 + mk/repo.mk | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/mk/config.mk b/mk/config.mk index 7c0cc320..121e8057 100644 --- a/mk/config.mk +++ b/mk/config.mk @@ -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) diff --git a/mk/podman.mk b/mk/podman.mk index 2fb068dc..8978275f 100644 --- a/mk/podman.mk +++ b/mk/podman.mk @@ -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 diff --git a/mk/repo.mk b/mk/repo.mk index c89e02ae..8174ae95 100644 --- a/mk/repo.mk +++ b/mk/repo.mk @@ -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'"