Skip to main content
Glama

stack_unwind

Reconstruct the call chain from a Cortex-M fault stack frame to locate the faulting function. Accepts an ELF path, optional frame, SP, and EXC_RETURN for accurate MSP/PSP and FPU frame handling.

Instructions

栈回溯:把 fault 时压栈的 8 个字还原成调用链,定位出错函数。

frame 按硬件压栈顺序:[R0, R1, R2, R3, R12, LR, PC, xPSR] stack_unwind("build/app.elf", frame=[r0,r1,r2,r3,r12,lr,pc,xpsr]) ★同 symbol_lookup:优先给 .elf。.map 的符号表稀疏时 PC/LR 可能反查出 假函数名,工具会就此提示。 exc_return 传 handler 入口时的 LR——它决定栈帧是标准还是 FPU 扩展、 以及异常前用的是 MSP 还是 PSP(RTOS 任务)。传了会给出更准的判断。 ★ PC 反查不到符号时,说明是典型「跑飞」,工具会给排查方向。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
spNo
pathYes
frameNo
exc_returnNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and does so well: it discloses the warning behavior for sparse .map symbol tables (fake function names), the effect of exc_return on frame/stack determination, and the 'runaway' diagnosis when PC cannot be resolved. It does not state whether the tool reads only or writes, so it is not exhaustive.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loads the purpose, then packs frame layout, an example call, and edge-case guidance into tight lines. The ★ markers and inline example are efficient, though the density and mixed-script formatting add minor reading overhead.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

An output schema exists, so return formatting need not be covered, and the description supplies most of what a caller needs for a 4-param, annotation-free tool. The main gap is that sp is unexplained and the relationship between sp and frame (alternative ways to supply the stack) is never clarified.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description must carry parameter meaning, and it does for three of four: frame is fully specified by hardware push order, path is scoped to .elf vs .map, and exc_return's semantics are explained. sp is never described, leaving one parameter undocumented in both schema and description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb+resource: unwind the 8 stacked words from fault time into a call chain and locate the failing function. It also names the frame layout and distinguishes itself by referencing symbol_lookup as a related-but-different tool. An agent can immediately tell what this does versus decode_fault/parse_map.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives clear context: use after a fault, prefer the .elf like symbol_lookup, and pass exc_return for a more accurate MSP/PSP and frame-type judgment. It stops short of explicitly contrasting with the obvious sibling decode_fault or stating when-not to use it, so it is strong but not fully routing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.