lldb_set_breakpoint
Set breakpoints in C/C++ programs to pause execution at specific functions, lines, or addresses for debugging purposes.
Instructions
Set a breakpoint in a program.
Breakpoints can be set by:
- Function name: 'main', 'MyClass::method'
- File and line: 'main.cpp:42'
- Address: '0x400500'
- Regex: Use 'breakpoint set -r pattern'
Args:
params: SetBreakpointInput with location and optional condition
Returns:
str: Confirmation of breakpoint creation with details
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- lldb_mcp_server.py:606-648 (handler)The handler function implementing the lldb_set_breakpoint tool. It constructs LLDB commands to create a breakpoint based on the provided location (function, file:line, or address), optionally adds a condition, executes the commands using _run_lldb_script, and returns formatted success or error output.async def lldb_set_breakpoint(params: SetBreakpointInput) -> str: """Set a breakpoint in a program. Breakpoints can be set by: - Function name: 'main', 'MyClass::method' - File and line: 'main.cpp:42' - Address: '0x400500' - Regex: Use 'breakpoint set -r pattern' Args: params: SetBreakpointInput with location and optional condition Returns: str: Confirmation of breakpoint creation with details """ commands = [f"target create {params.executable}"] # Determine breakpoint type from location format if ":" in params.location and not params.location.startswith("0x"): # File:line format parts = params.location.rsplit(":", 1) bp_cmd = f"breakpoint set --file {parts[0]} --line {parts[1]}" elif params.location.startswith("0x"): # Address bp_cmd = f"breakpoint set --address {params.location}" else: # Function name bp_cmd = f"breakpoint set --name {params.location}" if params.condition: bp_cmd += f" --condition '{params.condition}'" commands.append(bp_cmd) commands.append("breakpoint list") result = _run_lldb_script(commands, working_dir=params.working_dir) if result["success"]: return f"**Breakpoint set successfully**\n\n```\n{result['output']}\n```" else: return ( f"**Error setting breakpoint:** {result.get('error')}\n\n```\n{result['output']}\n```" )
- lldb_mcp_server.py:596-605 (registration)MCP tool registration decorator that registers the lldb_set_breakpoint handler with the specified name and annotations indicating its behavior (not read-only, not idempotent, etc.).@mcp.tool( name="lldb_set_breakpoint", annotations={ "title": "Set Breakpoint", "readOnlyHint": False, "destructiveHint": False, "idempotentHint": False, "openWorldHint": False, }, )
- lldb_mcp_server.py:208-223 (schema)Pydantic BaseModel defining the input schema for the lldb_set_breakpoint tool, validating executable path, breakpoint location, optional condition, and working directory.class SetBreakpointInput(BaseModel): """Input for setting breakpoints.""" model_config = ConfigDict(str_strip_whitespace=True) executable: str = Field(..., description="Path to the executable", min_length=1) location: str = Field( ..., description="Breakpoint location: function name (e.g., 'main'), file:line (e.g., 'main.cpp:42'), or address (e.g., '0x1234')", min_length=1, ) condition: str | None = Field( default=None, description="Conditional expression for the breakpoint (e.g., 'i > 10')" ) working_dir: str | None = Field(default=None, description="Working directory for the session")
- lldb_mcp_server.py:118-156 (helper)Helper function used by the handler to execute the sequence of LLDB commands via subprocess, capturing output and handling errors/timeouts.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}