debug_crash
Debug crashing programs by analyzing stack traces to identify root causes of failures in HPC environments.
Instructions
Debug crashing program and return the stack trace.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| target | Yes | ||
| args | Yes |
Implementation Reference
- src/debug.py:9-15 (handler)The main handler function for the 'debug_crash' tool. It generates a GDB command, executes it via subprocess, parses the backtrace from the output, and returns it.def debug_crash(target: str, args: list[str]) -> str: """Debug crashing program and return the stack trace.""" debug_cmd = generate_debug_cmd(target, args) debug_output = subprocess.run(shlex.split(debug_cmd), capture_output=True) backtrace_text = parse_backtrace(debug_output) return backtrace_text
- src/debug.py:9-9 (schema)Function signature providing input/output type hints serving as the tool schema: target (str), args (list[str]) -> str.def debug_crash(target: str, args: list[str]) -> str:
- src/debug.py:8-8 (registration)Decorator registering the debug_crash function as an MCP tool.@mcp.tool
- src/debug.py:18-25 (helper)Helper function to construct the GDB command for batch mode execution, backtrace, and quit.def generate_debug_cmd(target: str, args: list[str]) -> str: """Generate a debug command for the target program with args.""" crash_script = shlex.split("--batch -ex b _exit -ex run -ex bt -ex quit") general_gdb_config = "-q" debug_cmd = shlex.join( ["gdb", general_gdb_config] + crash_script + ["--args", target] + args ) return debug_cmd
- src/debug.py:28-34 (helper)Helper function to extract backtrace lines (starting with '#') from GDB output.def parse_backtrace(debug_output: subprocess.CompletedProcess[bytes]) -> str: """Parse the backtrace from the output of gdb.""" raw_text = debug_output.stdout.decode("utf-8") backtrace = "\n".join( line for line in raw_text.splitlines() if line.startswith("#") ) return backtrace