gdb_stop_session
Stop an active GDB debugging session and release associated resources using the session ID obtained from starting a session.
Instructions
Stop the current GDB session and clean up resources. Requires session_id parameter (obtained from gdb_start_session).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | Session ID from gdb_start_session |
Implementation Reference
- src/gdb_mcp/server.py:423-430 (registration)Tool registration for gdb_stop_session in the list_tools() function. Defines the tool name, description, and input schema (SessionIdArgs).
Tool( name="gdb_stop_session", description=( "Stop the current GDB session and clean up resources. " "Requires session_id parameter (obtained from gdb_start_session)." ), inputSchema=SessionIdArgs.model_json_schema(), ), - src/gdb_mcp/server.py:181-184 (schema)Input schema (SessionIdArgs) used by gdb_stop_session. Requires only a session_id integer.
class SessionIdArgs(BaseModel): """Arguments for tools that only need session_id.""" session_id: int = Field(..., description="Session ID from gdb_start_session") - src/gdb_mcp/server.py:565-567 (handler)Handler logic for gdb_stop_session: calls session.stop() and then removes the session from the session manager.
elif name == "gdb_stop_session": result = session.stop() session_manager.remove_session(session_id) - GDBSession.stop() method: terminates the GDB controller process, resets session state, and restores the original working directory if changed.
def stop(self) -> dict[str, Any]: """Stop the GDB session.""" if not self.controller: return {"status": "error", "message": "No active session"} try: self.controller.exit() self.controller = None self.is_running = False self.target_loaded = False # Restore original working directory if it was changed during start() if self.original_cwd: os.chdir(self.original_cwd) logger.info(f"Restored working directory to: {self.original_cwd}") self.original_cwd = None return {"status": "success", "message": "GDB session stopped"} except Exception as e: logger.error(f"Failed to stop GDB session: {e}") # Still try to restore working directory even if stop failed if self.original_cwd: try: os.chdir(self.original_cwd) logger.info(f"Restored working directory after error: {self.original_cwd}") self.original_cwd = None except Exception as cwd_error: logger.warning(f"Failed to restore working directory: {cwd_error}") return {"status": "error", "message": str(e)} - src/gdb_mcp/server.py:63-77 (helper)SessionManager.remove_session() method: removes the session from the internal sessions dict under a thread lock.
def remove_session(self, session_id: int) -> bool: """ Remove a GDB session by its ID. Args: session_id: The session ID to remove Returns: True if session was removed, False if it didn't exist """ with self._lock: if session_id in self._sessions: del self._sessions[session_id] return True return False