Skip to main content
Glama

lldb_backtrace

Read-onlyIdempotent

Analyze program crashes by retrieving stack traces showing function calls, source locations, and frame details for debugging C/C++ applications.

Instructions

Get a stack backtrace showing the call chain.

The backtrace shows:
- Frame numbers (0 is current frame)
- Function names and addresses
- Source file and line numbers (if available)
- Module/library names

Args:
    params: BacktraceInput with executable and stopping point

Returns:
    str: Stack backtrace with frame information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for 'lldb_backtrace' tool, including the @mcp.tool decorator. It sets up LLDB commands to load target, set breakpoint if needed, run to breakpoint or use core, get backtrace with options for all threads and limit, execute via _run_lldb_script, parse if JSON, format output.
    @mcp.tool(
        name="lldb_backtrace",
        annotations={
            "title": "Get Backtrace",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": False,
        },
    )
    async def lldb_backtrace(params: BacktraceInput) -> str:
        """Get a stack backtrace showing the call chain.
    
        The backtrace shows:
        - Frame numbers (0 is current frame)
        - Function names and addresses
        - Source file and line numbers (if available)
        - Module/library names
    
        Args:
            params: BacktraceInput with executable and stopping point
    
        Returns:
            str: Stack backtrace with frame information
        """
        commands = []
    
        if params.core_file:
            commands.append(f"target create {params.executable} --core {params.core_file}")
        else:
            commands.append(f"target create {params.executable}")
            if params.breakpoint:
                commands.append(f"breakpoint set --name {params.breakpoint}")
                commands.append("run" + (" " + " ".join(params.args) if params.args else ""))
    
        bt_cmd = "thread backtrace"
        if params.all_threads:
            bt_cmd = "thread backtrace all"
        bt_cmd += f" -c {params.limit}"
    
        commands.append(bt_cmd)
    
        if not params.core_file:
            commands.append("quit")
    
        result = _run_lldb_script(commands)
    
        if params.response_format == ResponseFormat.JSON:
            frames = _parse_backtrace(result["output"])
            return json.dumps(
                {"success": result["success"], "frames": frames, "raw_output": result["output"]},
                indent=2,
            )
    
        lines = ["## Stack Backtrace", "", "```", result["output"].strip(), "```"]
    
        return "\n".join(lines)
  • Pydantic input schema for the lldb_backtrace tool defining parameters like executable path, breakpoint, core dump, thread options, frame limit, args, and output format.
    class BacktraceInput(BaseModel):
        """Input for getting a backtrace."""
    
        model_config = ConfigDict(str_strip_whitespace=True)
    
        executable: str = Field(..., description="Path to the executable", min_length=1)
        breakpoint: str | None = Field(
            default=None, description="Breakpoint location to stop at (or use with core file)"
        )
        core_file: str | None = Field(
            default=None, description="Path to core dump file for post-mortem analysis"
        )
        all_threads: bool = Field(default=False, description="Show backtraces for all threads")
        limit: int = Field(default=50, description="Maximum number of frames to show", ge=1, le=1000)
        args: list[str] | None = Field(
            default=None, description="Command-line arguments to pass to the program"
        )
        response_format: ResponseFormat = Field(
            default=ResponseFormat.MARKDOWN, description="Output format"
        )
  • MCP tool registration decorator specifying the name 'lldb_backtrace' and annotations for tool behavior.
    @mcp.tool(
        name="lldb_backtrace",
        annotations={
            "title": "Get Backtrace",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": False,
        },
    )
  • Helper function that parses raw LLDB backtrace output into a structured list of frame dictionaries, used when response_format is JSON.
    def _parse_backtrace(output: str) -> list[dict[str, Any]]:
        """Parse LLDB backtrace output into structured data."""
        frames = []
        frame_pattern = re.compile(
            r"frame #(\d+): (0x[0-9a-fA-F]+) (.+?)(?:`(.+?))?(?:\s+\+\s+(\d+))?(?:\s+at\s+(.+):(\d+))?"
        )
    
        for line in output.split("\n"):
            match = frame_pattern.search(line)
            if match:
                frames.append(
                    {
                        "frame_number": int(match.group(1)),
                        "address": match.group(2),
                        "module": match.group(3).strip() if match.group(3) else None,
                        "function": match.group(4).strip() if match.group(4) else None,
                        "offset": int(match.group(5)) if match.group(5) else None,
                        "file": match.group(6) if match.group(6) else None,
                        "line": int(match.group(7)) if match.group(7) else None,
                    }
                )
    
        return frames
  • Core helper function to execute a sequence of LLDB commands in batch mode via subprocess, capturing output and handling errors/timeouts. Used by the handler to run the backtrace commands.
    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}
Behavior4/5

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

Annotations already declare readOnlyHint=true, idempotentHint=true, and destructiveHint=false, indicating a safe, repeatable read operation. The description adds valuable behavioral context by detailing what the backtrace output includes (frame numbers, function names, source lines, module names) and mentioning availability conditions ('if available'), which goes beyond the annotations. No contradictions exist.

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 well-structured and appropriately sized. It front-loads the purpose, then details output content, and ends with parameter and return summaries. Every sentence adds value, though the 'Args' and 'Returns' sections are somewhat redundant given the schema and output schema.

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?

Given the tool's moderate complexity, rich annotations (readOnlyHint, idempotentHint), and the presence of an output schema (implied by 'Returns: str'), the description is mostly complete. It explains what the tool does and what the output contains, though it lacks usage guidelines and deeper parameter context, which are minor gaps.

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

Parameters3/5

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

The schema description coverage is 0%, but the description compensates by explaining that 'params' is a 'BacktraceInput with executable and stopping point.' However, it doesn't detail the semantics of individual parameters like 'executable', 'breakpoint', or 'core_file' beyond what the schema's property descriptions already provide. The baseline is 3 since the schema does heavy lifting with well-described properties.

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 clearly states the tool's purpose: 'Get a stack backtrace showing the call chain.' It specifies the exact resource (stack backtrace) and verb (get), and distinguishes it from siblings like lldb_disassemble or lldb_examine_variables by focusing on call chain visualization rather than code disassembly or variable inspection.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to prefer lldb_backtrace over lldb_threads (which might show thread states) or lldb_analyze_crash (for crash analysis), nor does it specify prerequisites like needing a running/debuggable process. Usage context is implied but not explicit.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/benpm/claude_lldb_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server