From 86fba41a91f274687a4be7fd36c3632382d8c24d Mon Sep 17 00:00:00 2001 From: Wildan Mubarok Date: Sun, 21 Sep 2025 16:11:55 +0000 Subject: [PATCH] Add gdbgui that works for native build --- mk/config.mk | 3 +++ mk/repo.mk | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/mk/config.mk b/mk/config.mk index e625b1a57..a96bb1954 100644 --- a/mk/config.mk +++ b/mk/config.mk @@ -72,6 +72,9 @@ endif ifeq ($(REPO_DEBUG),1) export COOKBOOK_NOSTRIP=true export COOKBOOK_DEBUG=true +#TODO: https://gitlab.redox-os.org/redox-os/relibc/-/issues/226 +# export PROFILE=debug +# export RUSTCFLAGS="-Cdebuginfo=2" endif UNAME := $(shell uname) diff --git a/mk/repo.mk b/mk/repo.mk index dfbcacfe4..b617f1e5f 100644 --- a/mk/repo.mk +++ b/mk/repo.mk @@ -169,11 +169,12 @@ 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 a statically linked program with gdbgui, for example: debug.drivers-initfs DEBUG_BIN=pcid +# Enable debug symbols with `REPO_DEBUG=1 make cr.recipe rebuild`, make sure `file` outputs "debug_info, not stripped" +# Open http://localhost:5000/dashboard, start QEMU with `make qemu kvm=no QEMU_SMP=1 gdb=yes` before opening a session +# Experimental, may not work if ARCH is different with what host is running debug.%: $(FSTOOLS_TAG) FORCE +ifeq ($(PODMAN_BUILD),1) @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 "$*") && \ @@ -186,3 +187,13 @@ debug.%: $(FSTOOLS_TAG) FORCE redox-kernel-debug --gdb-cmd "gdb -ex 'set confirm off' \ -ex 'add-symbol-file /binary' \ -ex 'target remote host.containers.internal:1234'" +else + @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 "----------" && \ + gdbgui.pex --gdb-cmd "gdb -ex 'set confirm off' \ + -ex 'add-symbol-file $$BIN_PATH' \ + -ex 'target remote localhost:1234'" +endif