From 5e23165b99e76d3cb49e1e70c21e8c4624334148 Mon Sep 17 00:00:00 2001 From: Reset816 Date: Fri, 26 Apr 2024 15:51:44 +0000 Subject: [PATCH 1/2] kernel debug: add DEBUG_INFO --- src/feature/linux/core/debug/config | 1 + 1 file changed, 1 insertion(+) diff --git a/src/feature/linux/core/debug/config b/src/feature/linux/core/debug/config index ea34fe5..aec2ce0 100644 --- a/src/feature/linux/core/debug/config +++ b/src/feature/linux/core/debug/config @@ -4,3 +4,4 @@ CONFIG_KALLSYMS=y CONFIG_KALLSYMS_ALL=y CONFIG_DEBUG_BUGVERBOSE=y CONFIG_STACKTRACE=y +CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y -- Gitee From 5cbc956d527b54b3f57f466aa29f5077694bfc3c Mon Sep 17 00:00:00 2001 From: Yuan Tan Date: Sun, 28 Apr 2024 11:12:03 +0800 Subject: [PATCH 2/2] debug: use tmux in debugging Using tmux to facilitate user-friendly debugging in the CLI. Signed-off-by: Yuan Tan --- .labbegin | 7 +++++++ Makefile | 30 +----------------------------- README.md | 12 ++---------- README_zh.md | 14 ++------------ 4 files changed, 12 insertions(+), 51 deletions(-) diff --git a/.labbegin b/.labbegin index cf295bd..e8621c6 100644 --- a/.labbegin +++ b/.labbegin @@ -32,6 +32,13 @@ ifneq ($(QEMU),) endif endif +# With tmux, the Linux kernel can be debugged in the CLI +ifneq ($(findstring debug,$(firstword $(MAKECMDGOALS)))),) + ifeq ($(wildcard /usr/bin/tmux),) + PKGS += tmux + endif +endif + # gcc 4.3 must work with 2.24 binutils (ld), otherwise, the kernel compiled not boot # LS is a predefined variable, use LDT (ld tool) instead here ifeq ($(CCORI),internal) diff --git a/Makefile b/Makefile index c75bf67..e24ddae 100644 --- a/Makefile +++ b/Makefile @@ -4065,8 +4065,6 @@ G ?= 0 # Force using curses based graphic mode for bash/ssh login ifneq ($(shell env | grep -q ^DISPLAY; echo $$?), 0) - XTERM := null - ifeq ($(G), 1) override G := 2 endif @@ -4533,37 +4531,11 @@ HOME_GDB_INIT ?= $(HOME)/.gdbinit # Force run as ubuntu to avoid permission issue of .gdbinit and ~/.gdbinit GDB_USER ?= $(USER) -# Xterm: terminator -ifeq ($(XTERM), null) - XTERM_STATUS := 1 -else - XTERM ?= $(shell tools/xterm.sh qterminal) - # Testing should use non-interactive mode, otherwise, enable interactive. - ifneq ($(TEST),) - XTERM_CMD ?= sudo -u $(GDB_USER) /bin/bash -c "$(GDB_CMD)" - else - XTERM_CMD ?= $(XTERM) --workdir $(CURDIR) --title "$(GDB_CMD)" -e "$(GDB_CMD)" - endif - XTERM_STATUS := $(shell $(XTERM) --help >/dev/null 2>&1; echo $$?) -endif - -ifeq ($(XTERM_STATUS), 0) - DEBUG_CMD := $(XTERM_CMD) -else - DEBUG_CMD := $(Q)sleep 0.1 && echo "\nLOG: debug server started, please connect it with these commands:\n\n" \ - " (host) $$ cd /path/to/cloud-lab\n" \ - " (host) $$ tools/docker/bash linux-lab\n" \ - " ubuntu@linux-lab:/labs/linux-lab$$ make $(MAKECMDGOALS)\n" \ - "\n\n" \ - "NOTE: To exit debug server, please press 'CTRL+a x'\n\n" -endif - # FIXME: gdb not continue the commands in .gdbinit while runing with 'CASE=debug tools/testing/run.sh' # just ignore the do_fork breakpoint to workaround it. _debug: $(Q)cp -v $(notdir $(GDBINIT_DIR))/$(notdir $(GDB_INIT)) .gdbinit $(Q)sudo -u $(GDB_USER) echo "add-auto-load-safe-path .gdbinit" > $(HOME_GDB_INIT) - $(Q)$(DEBUG_CMD) & _debug_init_1: $(Q)sudo -u $(GDB_USER) sed -i -e "/do_fork/s/^#*//g" $(GDB_INIT) @@ -4607,7 +4579,7 @@ ifneq ($(DEBUG),0) # Debug listen on a unqiue port, should run exclusively DEBUG_LOCK := $(GDBINIT_DIR)/.lock KEEP_UNIQUE := flock -n -x $(DEBUG_LOCK) - RUN_BOOT_CMD := $(KEEP_UNIQUE) $(BOOT_CMD) || $(GDB_CMD) + RUN_BOOT_CMD := tmux new-session -d '$(KEEP_UNIQUE) $(BOOT_CMD)' \; split-window -h '$(GDB_CMD)' \; attach else RUN_BOOT_CMD := $(BOOT_CMD) endif diff --git a/README.md b/README.md index 6cb9743..47ae1c8 100644 --- a/README.md +++ b/README.md @@ -1438,11 +1438,7 @@ And then debug it directly: $ make debug -If login via `vnc` or `webvnc`, It will open a new terminal, load the scripts from `.gdb/kernel.default`, run gdb automatically. - -But if login with `bash`, `ssh` or `webssh`, please read the prompt and run this command again to start debugging: - - $ make debug +The above command will use tmux to split into two terminals, each running QEMU and gdb respectively, and load the script from .gdb/kernel.default. To customize kernel gdbinit script, simply copy one and edit it manually: @@ -1472,11 +1468,7 @@ To debug U-Boot with `.gdb/uboot.default`: $ make debug uboot -If login with `vnc` or `webvnc`, the above command will open a terminal and start debugging automatically. - -But if login with `bash`, `ssh` or `webssh`, please read the prompt and run this command again to start real debugging: - - $ make debug uboot +The above command will use tmux to split into two terminals, each running QEMU and gdb respectively. To automate U-Boot debug testing: diff --git a/README_zh.md b/README_zh.md index f0d8365..db22e13 100644 --- a/README_zh.md +++ b/README_zh.md @@ -1684,17 +1684,11 @@ GCC 的版本可以分别在开发板特定的 Makefile 中针对 Linux, Uboot, $ make kernel JOBS=1 -如果是通过 `vnc` 或者 `webvnc` 登陆的,可运行如下命令直接调试: +可运行如下命令调试: $ make debug -将打开一个新的终端窗口,从 `.gdb/kernel.default` 加载脚本,自动运行 gdb。 - -但是,如果是通过 `bash`、`ssh` 或者 `webssh` 登陆的,请通过相应方式再登陆一次 Linux Lab,再次运行如下命令即可: - - $ make debug - -主要原因是,控制台不支持多窗口,需要手动开多个窗口,方便一边运行,一边调试。 +该命令将使用 tmux 分割出两个终端分别运行 QEMU 和 gdb,并从 `.gdb/kernel.default` 加载脚本。 如果想修改调试脚本,可以拷贝一份到 `.gdb/kernel.user`,这样就可以无缝升级: @@ -1724,10 +1718,6 @@ GCC 的版本可以分别在开发板特定的 Makefile 中针对 Linux, Uboot, $ make debug uboot -如果是通过控制台登陆的 Linux Lab,不会自动拉起窗口,请按提示再次执行如下命令即可开启调试: - - $ make debug uboot - 同样可以自动测试调试: $ make test-debug uboot -- Gitee