lldb_analyze_crash
Analyze crashed programs or core dumps to identify root causes by examining backtraces, register states, local variables, and loaded modules.
Instructions
Analyze a crashed program or core dump to determine the cause.
This tool loads a core dump or crashed executable and provides:
- Backtrace showing the crash location
- Register state at crash time
- Local variables in the crash frame
- Loaded modules information
Args:
params: AnalyzeCrashInput with executable path and optional core file
Returns:
str: Crash analysis including backtrace, registers, and variables
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- lldb_mcp_server.py:539-593 (handler)The main asynchronous handler function that implements the core logic of the 'lldb_analyze_crash' tool. It constructs LLDB commands to analyze the crash (backtrace, registers, variables, images), executes them using _run_lldb_script, and formats the output in Markdown or JSON.async def lldb_analyze_crash(params: AnalyzeCrashInput) -> str: """Analyze a crashed program or core dump to determine the cause. This tool loads a core dump or crashed executable and provides: - Backtrace showing the crash location - Register state at crash time - Local variables in the crash frame - Loaded modules information Args: params: AnalyzeCrashInput with executable path and optional core file Returns: str: Crash analysis including backtrace, registers, and variables """ commands = [] if params.core_file: commands.append(f"target create {params.executable} --core {params.core_file}") else: commands.append(f"target create {params.executable}") commands.extend(["bt all", "register read", "frame variable", "image list"]) result = _run_lldb_script(commands, working_dir=params.working_dir) if params.response_format == ResponseFormat.JSON: return json.dumps( { "success": result["success"], "executable": params.executable, "core_file": params.core_file, "output": result["output"], "error": result.get("error"), }, indent=2, ) # Markdown format lines = [f"# Crash Analysis: {Path(params.executable).name}", ""] if params.core_file: lines.append(f"**Core file:** {params.core_file}") lines.append("") if result["success"]: lines.append("## Analysis Output") lines.append("```") lines.append(result["output"].strip()) lines.append("```") else: lines.append("## Error") lines.append(f"```\n{result.get('error', 'Unknown error')}\n```") return "\n".join(lines)
- lldb_mcp_server.py:194-205 (schema)Pydantic BaseModel defining the input schema/validation for the lldb_analyze_crash tool parameters.class AnalyzeCrashInput(BaseModel): """Input for analyzing a crashed program.""" model_config = ConfigDict(str_strip_whitespace=True) executable: str = Field(..., description="Path to the executable that crashed", min_length=1) core_file: str | None = Field(default=None, description="Path to the core dump file (optional)") response_format: ResponseFormat = Field( default=ResponseFormat.MARKDOWN, description="Output format: 'markdown' for human-readable or 'json' for structured data", ) working_dir: str | None = Field(default=None, description="Working directory for the analysis")
- lldb_mcp_server.py:529-538 (registration)The @mcp.tool decorator that registers the lldb_analyze_crash function as an MCP tool with the specified name and annotations describing its behavior (read-only, idempotent, etc.).@mcp.tool( name="lldb_analyze_crash", annotations={ "title": "Analyze Crash Dump", "readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, "openWorldHint": False, }, )
- lldb_mcp_server.py:118-156 (helper)Utility helper function that executes a sequence of LLDB commands in batch mode via subprocess, capturing output and handling errors/timeouts. Directly invoked by the handler.def _run_lldb_script( commands: list[str], target: str | None = None, working_dir: str | None = None, timeout: int = 60, ) -> dict[str, Any]: """ Execute multiple LLDB commands in sequence. """ cmd = [LLDB_EXECUTABLE] if target: cmd.extend(["--file", target]) cmd.append("--batch") for command in commands: cmd.extend(["-o", command]) try: result = subprocess.run( cmd, capture_output=True, text=True, timeout=timeout, cwd=working_dir or os.getcwd() ) return { "success": result.returncode == 0, "output": result.stdout, "error": result.stderr if result.returncode != 0 else None, "return_code": result.returncode, } except subprocess.TimeoutExpired: return { "success": False, "output": "", "error": f"Commands timed out after {timeout} seconds", "return_code": -1, } except Exception as e: return {"success": False, "output": "", "error": str(e), "return_code": -1}