Skip to content

Commit d5c883e

Browse files
committed
arch: introduce arch_stack_walk()
An architecture can indicate that it has an implementation for the `arch_stack_walk()` function by selecting `ARCH_HAS_STACKWALK`. Set the default value of `EXCEPTION_STACK_TRACE_MAX_FRAMES` to `ARCH_STACKWALK_MAX_FRAMES` if the latter is available. Signed-off-by: Yong Cong Sin <[email protected]>
1 parent d18fd46 commit d5c883e

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

arch/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,14 @@ config FRAME_POINTER
409409
Select Y here to gain precise stack traces at the expense of slightly
410410
increased size and decreased speed.
411411

412+
config ARCH_STACKWALK_MAX_FRAMES
413+
int "Max depth for stack walk function"
414+
default 8
415+
depends on ARCH_HAS_STACKWALK
416+
help
417+
Depending on implementation, this can place a hard limit on the depths of the stack
418+
for the stack walk function to examine.
419+
412420
menu "Interrupt Configuration"
413421

414422
config ISR_TABLES_LOCAL_DECLARATION_SUPPORTED
@@ -654,6 +662,11 @@ config ARCH_HAS_EXTRA_EXCEPTION_INFO
654662
config ARCH_HAS_GDBSTUB
655663
bool
656664

665+
config ARCH_HAS_STACKWALK
666+
bool
667+
help
668+
This is selected when the architecture implemented the arch_stack_walk() API.
669+
657670
config ARCH_HAS_COHERENCE
658671
bool
659672
help

include/zephyr/arch/arch_interface.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,33 @@ bool arch_pcie_msi_vector_connect(msi_vector_t *vector,
12511251
*/
12521252
void arch_spin_relax(void);
12531253

1254+
/**
1255+
* stack_trace_callback_fn - Callback for @ref arch_stack_walk
1256+
* @param cookie Caller supplied pointer handed back by @ref arch_stack_walk
1257+
* @param addr The stack entry address to consume
1258+
*
1259+
* @return True, if the entry was consumed or skipped. False, if there is no space left to store
1260+
*/
1261+
typedef bool (*stack_trace_callback_fn)(void *cookie, unsigned long addr);
1262+
1263+
/**
1264+
* @brief Architecture-specific function to walk the stack
1265+
*
1266+
* @param callback_fn Callback which is invoked by the architecture code for each entry.
1267+
* @param cookie Caller supplied pointer which is handed back to @a callback_fn
1268+
* @param thread Pointer to a k_thread struct, can be NULL
1269+
* @param esf Pointer to an arch_esf struct, can be NULL
1270+
*
1271+
* ============ ======= ============================================
1272+
* thread esf
1273+
* ============ ======= ============================================
1274+
* thread NULL Stack trace from thread (can be _current)
1275+
* thread esf Stack trace starting on esf
1276+
* ============ ======= ============================================
1277+
*/
1278+
void arch_stack_walk(stack_trace_callback_fn callback_fn, void *cookie,
1279+
const struct k_thread *thread, const struct arch_esf *esf);
1280+
12541281
#ifdef __cplusplus
12551282
}
12561283
#endif /* __cplusplus */

subsys/debug/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ config EXCEPTION_STACK_TRACE
382382

383383
config EXCEPTION_STACK_TRACE_MAX_FRAMES
384384
int "Configures the depth of stack trace"
385+
default ARCH_STACKWALK_MAX_FRAMES if ARCH_HAS_STACKWALK
385386
default 8
386387
depends on EXCEPTION_STACK_TRACE
387388
help

0 commit comments

Comments
 (0)