From cb2b39b34641711a1be4cc746351e3be01affc14 Mon Sep 17 00:00:00 2001 From: Hui Su <3164683437@qq.com> Date: Fri, 28 Aug 2026 11:13:16 +0800 Subject: [PATCH] [bsp/qemu-vexpress-a9] support function names in backtraces Pass -mpoke-function-name to the compiler and assembler when RT_BACKTRACE_FUNCTION_NAME is enabled for the Cortex-A9 QEMU BSP. Keep the BSP configuration opt-in so users can enable symbolized backtraces through menuconfig without changing the default build. The flag is appended through CCFLAGS and ASPPCOM after the build environment is created instead of concatenating it into CFLAGS/CXXFLAGS/ASFLAGS: when the toolchain is selected with --exec-path, PrepareBuilding() reloads rtconfig and _apply_exec_path_override() overwrites those variables, which would silently drop the option. The build still succeeds but function names are missing from the text section, leaving backtraces without usable frames. Example backtrace in QEMU (vexpress-a9, RT_BACKTRACE_FUNCTION_NAME=y, fault triggered from msh through cmd_fault -> fault_level1 -> fault_level2 -> fault_level3): backtrace: 0x600475a8 @ fault_level3 0x600475dc @ fault_level2 0x60047608 @ fault_level1 0x60047630 @ cmd_fault 0x6006ca80 @ _msh_exec_cmd 0x6006cb3c @ msh_exec 0x600717b4 @ finsh_thread_entry Signed-off-by: Hui Su <3164683437@qq.com> --- bsp/qemu-vexpress-a9/SConstruct | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bsp/qemu-vexpress-a9/SConstruct b/bsp/qemu-vexpress-a9/SConstruct index aa95fff7dfc6..8d23c60e70ab 100644 --- a/bsp/qemu-vexpress-a9/SConstruct +++ b/bsp/qemu-vexpress-a9/SConstruct @@ -2,6 +2,16 @@ import os import sys import rtconfig +TRACE_CONFIG = '' +try: + with open('rtconfig.h') as f: + for line in f: + if line.strip() == '#define RT_BACKTRACE_FUNCTION_NAME': + TRACE_CONFIG = '-mpoke-function-name' + break +except OSError: + pass + if os.getenv('RTT_ROOT'): RTT_ROOT = os.getenv('RTT_ROOT') else: @@ -20,6 +30,11 @@ env = Environment(tools = ['mingw'], AR = rtconfig.AR, ARFLAGS = '-rc', LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS) env.PrependENVPath('PATH', rtconfig.EXEC_PATH) + +if TRACE_CONFIG: + env.AppendUnique(CCFLAGS=[TRACE_CONFIG]) + env['ASPPCOM'] += ' ' + TRACE_CONFIG + env['ASCOM'] = env['ASPPCOM'] Export('RTT_ROOT')