支持对 RAM 代码区的调用栈回溯 - #93
Open
Baseline-K wants to merge 1 commit into
Open
Conversation
Owner
|
感谢你的 PR 。我建议最好能支持自定义的 Section 这样会更加灵活
|
Baseline-K
force-pushed
the
feature/ram-code-backtrace
branch
from
August 10, 2026 07:53
c9a6af4 to
f96210a
Compare
Author
|
感谢建议!已按您的意见改为「自定义代码区表」方案:
请再帮忙 review 一下,谢谢! |
Cortex-M7 etc. can execute time-critical functions from RAM (ITCM) or
split the firmware across multiple code regions. The default scan only
recognizes one Flash code region (CMB_CODE_SECTION_NAME), so frames that
cross the Flash boundary are dropped and the call stack breaks at the
most critical code.
Add an optional user code section backtrace:
- cmb_cfg.h: CMB_USING_USER_CODE_SECTION switch; when ON, CMB_USER_CODE_SECTIONS
declares extra code regions as a const {start,end} array initializer.
Flash is always auto-detected via CMB_CODE_SECTION_NAME.
- cmb_def.h: CMB_CODE_REGION_MAX (default 8), the code region table capacity.
- cm_backtrace.c: cm_backtrace_init() fills code_regions[] (Flash first, then
user-defined); cmb_pc_in_code()/cmb_pc_in_code_skip_first() walk the table.
- When CMB_USING_USER_CODE_SECTION is not defined all new code is stripped by
the preprocessor, byte-identical to v1.5.0.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Baseline-K
force-pushed
the
feature/ram-code-backtrace
branch
from
August 10, 2026 08:45
f96210a to
890636d
Compare
Author
|
补充:把命名统一改成了「用户代码区」——开关为 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Cortex-M7 等 MCU 允许把对时序要求高的函数放到 RAM 中执行(如 ITCM),
会把固件拆分成多个代码区。这些函数的地址落在
CMB_CODE_SECTION_NAME(Flash)之外,原回溯扫描会把所有跨过 Flash 边界的帧当作无效帧丢弃——调用栈恰好断在最关键的代码处。
改动
新增可选的多代码区回溯支持,代码区采用可自定义的表格声明:
cmb_cfg.h:新增开关CMB_USING_USER_CODE_SECTION;开启后可用CMB_USER_CODE_SECTIONS配置额外代码区——一个 const 的{ start, end }结构体数组初始化器,可声明任意多个代码区(ITCM、CCM、其他Flash区等)
cmb_def.h:新增CMB_CODE_REGION_MAX(默认 8),代码区表容量上限,仿
CMB_CALL_STACK_MAX_DEPTH用#ifndef默认值,可在cmb_cfg.h覆盖cm_backtrace.c:cm_backtrace_init()填充代码区表code_regions[](自动检测的 Flash 区在前,随后按
CMB_USER_CODE_SECTIONS追加);将原单区域判定替换为
cmb_pc_in_code()/cmb_pc_in_code_skip_first(),遍历所有已登记区域
CMB_USING_USER_CODE_SECTION时,所有新增代码均被预处理裁剪,与 v1.5.0 逐字节一致