Skip to main content
Glama

按变量名查询变量地址与内容

read_variable
Read-onlyIdempotent

Reads a variable's memory address and current value by name, supports arrays and relocation offsets. Falls back to .axf symbol table + read_mem when standard read fails.

Instructions

按变量名查询变量的内存地址与当前内容(值),支持数组等类型。内部用 '&变量名' 取地址、'变量名' 取值、'sizeof(变量名)' 取大小,AI 无需手写取地址表达式即可定位变量。name 为变量名(如 'SData_UA'、'timer.sec'、'arr');count 可选:>0 时按数组逐元素读 name[0..count-1] 返回 elements;返回 {address, value, value_type, size_bytes, elements, memory_hex}。读 App 侧变量(运行期重定位过)时传 reloc_delta="0xF000",或先调 set_reloc_delta 设一次全局偏移:工具会把符号的链接地址 + 偏移当作运行地址去读,返回 link_address / run_address,不必再手工换算(此时 value 按小端整数解析内存,浮点看 value_as_float)。符号解析双轨(批次48):Keil 表达式这条路读不到时(static 变量、符号漂移、停在不相关位置),会自动改走 .axf 符号表地址 + read_mem 兜底,返回 fallback=".axf 符号表 + read_mem" 与 fallback_reason 说明为什么换了轨道;两条都不通就如实报错,不会给一个像样的假值。若返回 value_suspect/value_warning(读回整帧全 0x00/全 0xFF),不要据此判定「变量被清零」——先用 reloc_check 校验 reloc_delta 是否与实际布局相符。适合先查地址/数组内容,再配合 read_mem/write_mem 进一步读写。注意:需目标暂停(运行中读取会失败/错位);依赖 .axf 调试符号。刚停止瞬间取值可能读到脏值。 【参数】必填: name;可选: count, read_memory, reloc_delta 【调用示例】{"name": "SData_UA"} 【参数别名】name ← arr/expression/func/function/keyword/location/pattern/query/symbol/target/var/variable/varname;count ← items/length/n/num。规范名以上方【参数】行为准;未列出的参数名会被拒绝,不会静默忽略

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
countNo
read_memoryNo
reloc_deltaNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.8

TDQS

A4.6/5.0
Behavior5/5

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

Annotations only say read-only/idempotent/non-destructive. The description adds major behavioral detail: internal address/value/sizeof expressions, reloc_delta handling for App-side variables, fallback to .axf symbol table plus read_mem, fallback_reason, the value_suspect warning, and dirty values right after stop. This is strong value beyond the annotations.

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?

The description is long but information-dense, front-loading purpose and parameter rules before caveats. Almost every sentence adds value, though the parameter/alias list partially repeats content already in the schema and could be tightened.

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

Completeness5/5

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

It covers prerequisites (paused target, .axf symbols), failure modes (fallback, both paths failing, all-zero frame warning), return fields (address, value, value_type, size_bytes, elements, memory_hex), and the intended workflow with read_mem/write_mem. Given the tool's complexity, nothing essential is missing.

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 carries the burden. It explains name with examples, count with array indices and elements, and reloc_delta with the offset and returned link_address/run_address. The only gap is read_memory, which appears in the parameter list but has no semantic explanation.

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?

The description states a precise verb+resource: query a variable's memory address and current value by variable name, including array support. It also differentiates itself from siblings like read_mem/write_mem by explaining that it resolves symbols automatically and is meant to locate addresses before raw memory access.

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?

It gives clear usage context: '适合先查地址/数组内容,再配合 read_mem/write_mem 进一步读写' and explicitly warns that the target must be paused and .axf debug symbols are required. It lacks a full when-not-to-use comparison against calc_expression or list_symbol_projects, so it falls just short of an explicit exclusion list.

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