lldb_evaluate
Evaluate C/C++ expressions during debugging to inspect variables, call functions, and analyze program state in real-time.
Instructions
Evaluate a C/C++ expression in the debugger context.
Expressions can include:
- Variable access: 'my_var', 'ptr->member'
- Array indexing: 'array[5]'
- Function calls: 'strlen(str)'
- Casts: '(int*)ptr'
- Arithmetic: 'x + y * 2'
- sizeof: 'sizeof(MyStruct)'
Args:
params: EvaluateExpressionInput with expression and context
Returns:
str: Expression result with type information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- lldb_mcp_server.py:825-852 (handler)The main handler function that evaluates C/C++ expressions in LLDB debugger context by creating a target, setting a breakpoint, running the program, executing the expression command, and formatting the output.async def lldb_evaluate(params: EvaluateExpressionInput) -> str: """Evaluate a C/C++ expression in the debugger context. Expressions can include: - Variable access: 'my_var', 'ptr->member' - Array indexing: 'array[5]' - Function calls: 'strlen(str)' - Casts: '(int*)ptr' - Arithmetic: 'x + y * 2' - sizeof: 'sizeof(MyStruct)' Args: params: EvaluateExpressionInput with expression and context Returns: str: Expression result with type information """ commands = [ f"target create {params.executable}", f"breakpoint set --name {params.breakpoint}", "run" + (" " + " ".join(params.args) if params.args else ""), f"expression {params.expression}", "quit", ] result = _run_lldb_script(commands) return f"## Expression: `{params.expression}`\n\n```\n{result['output'].strip()}\n```"
- lldb_mcp_server.py:277-294 (schema)Pydantic input schema defining parameters for the lldb_evaluate tool: executable path, expression to evaluate, breakpoint for context, and optional args.class EvaluateExpressionInput(BaseModel): """Input for evaluating expressions.""" model_config = ConfigDict(str_strip_whitespace=True) executable: str = Field(..., description="Path to the executable", min_length=1) expression: str = Field( ..., description="C/C++ expression to evaluate (e.g., 'sizeof(int)', 'ptr->member', 'array[5]')", min_length=1, ) breakpoint: str = Field( ..., description="Breakpoint location for evaluation context", min_length=1 ) args: list[str] | None = Field( default=None, description="Command-line arguments to pass to the program" )
- lldb_mcp_server.py:815-824 (registration)MCP decorator registering the lldb_evaluate tool with name and annotations indicating it's read-only, non-destructive, idempotent, etc.@mcp.tool( name="lldb_evaluate", annotations={ "title": "Evaluate Expression", "readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, "openWorldHint": False, }, )