Skip to main content
Glama

gdb_call_function

Execute any accessible function in a debugged program's context to test logic, verify state, or invoke cleanup routines during a GDB session.

Instructions

Call a function in the target process. WARNING: This is a privileged operation that executes code in the debugged program. It can call any function accessible in the current context, including: - Standard library functions: printf, malloc, free, etc. - Program functions: any function defined in the program - System calls via wrappers The function executes with full privileges of the debugged process. Use with caution as it may have side effects and modify program state. Examples: 'printf("debug: x=%d\n", x)', 'my_cleanup_func()', 'strlen(str)'. Requires session_id parameter (obtained from gdb_start_session).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYesSession ID from gdb_start_session
function_callYesFunction call expression (e.g., 'printf("hello\n")' or 'my_func(arg1, arg2)')

Implementation Reference

  • Tool registration for gdb_call_function - defines the tool name, description, and input schema.
    Tool(
        name="gdb_call_function",
        description=(
            "Call a function in the target process. "
            "WARNING: This is a privileged operation that executes code in the debugged program. "
            "It can call any function accessible in the current context, including: "
            "- Standard library functions: printf, malloc, free, etc. "
            "- Program functions: any function defined in the program "
            "- System calls via wrappers "
            "The function executes with full privileges of the debugged process. "
            "Use with caution as it may have side effects and modify program state. "
            "Examples: 'printf(\"debug: x=%d\\n\", x)', 'my_cleanup_func()', 'strlen(str)'. "
            "Requires session_id parameter (obtained from gdb_start_session)."
        ),
        inputSchema=CallFunctionArgs.model_json_schema(),
    ),
  • Input schema for gdb_call_function - defines the session_id and function_call parameters.
    class CallFunctionArgs(BaseModel):
        session_id: int = Field(..., description="Session ID from gdb_start_session")
        function_call: str = Field(
            ...,
            description="Function call expression (e.g., 'printf(\"hello\\n\")' or 'my_func(arg1, arg2)')",
        )
  • Handler dispatch for gdb_call_function - parses arguments and delegates to GDBSession.call_function().
    elif name == "gdb_call_function":
        call_args: CallFunctionArgs = CallFunctionArgs(**arguments)
        result = session.call_function(function_call=call_args.function_call)
  • Actual implementation in GDBSession.call_function() - builds the GDB 'call' command and sends it via the MI interpreter.
    def call_function(
        self, function_call: str, timeout_sec: int = DEFAULT_TIMEOUT_SEC
    ) -> dict[str, Any]:
        """
        Call a function in the target process.
    
        This is a privileged operation that executes the GDB 'call' command,
        which invokes a function in the debugged program. This can execute
        arbitrary code in the target process and may have side effects.
    
        WARNING: Use with caution as this can modify program state.
    
        Args:
            function_call: Function call expression (e.g., "printf(\\"hello\\n\\")"
                          or "my_function(arg1, arg2)")
            timeout_sec: Timeout for command execution
    
        Returns:
            Dict with the function's return value or error
        """
        if not self.controller:
            return {"status": "error", "message": "No active GDB session"}
    
        if not self._is_gdb_alive():
            return {
                "status": "error",
                "message": "GDB process has exited - cannot execute call",
            }
    
        # Build the call command
        command = f"call {function_call}"
    
        # Escape for MI command
        escaped_command = command.replace("\\", "\\\\").replace('"', '\\"')
        mi_command = f'-interpreter-exec console "{escaped_command}"'
    
        result = self._send_command_and_wait_for_prompt(mi_command, timeout_sec)
    
        if "error" in result:
            return {
                "status": "error",
                "message": result["error"],
                "function_call": function_call,
            }
    
        if result.get("timed_out"):
            return {
                "status": "error",
                "message": f"Timeout waiting for call to complete after {timeout_sec}s",
                "function_call": function_call,
            }
    
        parsed = self._parse_responses(result.get("command_responses", []))
        console_output = "".join(parsed.get("console", []))
    
        return {
            "status": "success",
            "function_call": function_call,
            "result": console_output.strip() if console_output else "(no return value)",
        }
Behavior5/5

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

With no annotations provided, the description fully discloses that this is a privileged operation executing code in the debugged process, with side effects and state modification. It lists examples of callable functions and warns of full privileges.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and well-structured: it starts with the purpose, includes a warning, provides examples, and states prerequisite. Every sentence adds value without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite no output schema, the description covers purpose, prerequisites, examples, and warnings, making it complete for a privileged function-call tool. The return value is not critical as the tool's action is the main point.

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

Parameters4/5

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

Schema coverage is 100%, so baseline is 3. The description adds context by explaining the source of session_id and giving examples of function_call expressions, enhancing understanding beyond the schema.

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 it calls a function in the target process, with specific examples and warning about it being a privileged operation. It distinguishes from siblings like gdb_evaluate_expression by focusing on function calls and side effects.

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

Usage Guidelines4/5

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

The description explains when to use (to call functions in the debugged process) and prerequisites (session_id from gdb_start_session). It does not explicitly contrast with siblings like gdb_evaluate_expression or gdb_execute_command, but the specialization is clear enough.

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/airfloats/gdb_mcp'

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