find_variables
Find C/C++ variables by name or prefix and identify every function that reads or writes them, tracing shared state and side effects across the call graph.
Instructions
Find C/C++ variables by name or prefix and trace who reads or
writes them through the call graph. libclang-powered: splits
variables into global (varglobal — file/namespace/class-scope)
and local (varlocal — inside a function body).
Each result includes a type signature (bool timeSet,
const IPAddress modbus_ip), the enclosing function for locals
("<file scope>" for globals), and a references list showing
every function that reads or writes the variable — the same
ref_kind values as find_references ("call", "ref",
"member").
Use when you need to understand shared state, find who modifies a
global variable, trace side effects, or distinguish important globals
from loop counters. For general symbol search use search_code or
lookup_symbol. For all references to a specific variable
(including reads in expressions), use find_references.
Legacy indexes with kind="variable" (pre-split) are detected and
included in results — reindex to fully benefit from the split.
Read-only. No side effects.
Args:
name: Variable name or prefix to search. Uses LIKE match
(e.g. g_ finds g_debug_level, g_state).
project_root: Project root directory. Auto-detected if omitted.
kind: Optional kind filter — "varglobal", "varlocal",
"field", or None (all). Default None.
limit: Maximum results (default 20, max 100).
Returns:
list of dicts, each with: name (str), qualified_name (str),
kind (str — "varglobal" or "varlocal"), file (str),
line (int), signature (str — e.g. "const IPAddress modbus_ip"),
enclosing_function (str — function name for varlocal,
"<file scope>" for varglobal), enclosing_class (str — class
name for static members, empty otherwise),
references (list[dict] — function, file, line,
ref_kind).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kind | No | Filter by kind: 'varglobal', 'varlocal', 'field', or None for all. | |
| name | Yes | Variable name or prefix to search. Uses LIKE match (e.g. 'g_' finds g_debug_level, g_state). | |
| limit | No | Maximum results (default 20, max 100). | |
| project_root | No | Project root. Auto-detected if omitted. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |