Skip to main content
Glama

AI向けGDB CLI

PyPI version Python License CI

English | 한국어 | 中文 | 日本語 | Español | Tiếng Việt | Português | Русский | Türkçe | Deutsch | Français | Italiano

AIエージェント(Claude Codeなど)向けに設計されたGDBデバッグツールです。「シンクライアントCLI + GDB組み込みPython RPCサーバー」アーキテクチャを採用しており、Bashを通じてステートフルなGDBデバッグを可能にします。

機能

  • コアダンプ解析: メモリ上に常駐するシンボルを使用してコアダンプを読み込み、ミリ秒単位の応答を実現

  • ライブアタッチデバッグ: ノンストップモードをサポートし、実行中のプロセスにアタッチ可能

  • 構造化JSON出力: すべてのコマンドがJSONを出力し、自動的な切り詰め/ページネーションおよび操作ヒントを提供

  • セキュリティメカニズム: コマンドのホワイトリスト、ハートビートタイムアウトによる自動クリーンアップ、冪等性の保証

  • データベース最適化: スケジューラーロック、ラージオブジェクトのページネーション、マルチスレッドでの切り詰め

Related MCP server: GDB MCP Server

要件

  • Python: 3.6.8以上

  • GDB: 9.0以上(Pythonサポートが有効であること

  • OS: Linux

GDBのPythonサポートを確認する

# Check if GDB has Python support
gdb -nx -q -batch -ex "python print('OK')"

# If system GDB lacks Python, check GCC Toolset (RHEL/CentOS)
/opt/rh/gcc-toolset-13/root/usr/bin/gdb -nx -q -batch -ex "python print('OK')"

インストール

# Install from PyPI
pip install gdb-cli

# Or install from GitHub
pip install git+https://github.com/Cerdore/gdb-cli.git

# Or clone and install locally
git clone https://github.com/Cerdore/gdb-cli.git
cd gdb-cli
pip install -e .

環境チェック

gdb-cli env-check


## Quick Start

### 1. Load Core Dump

```bash
gdb-cli load --binary ./my_program --core ./core.12345

出力:

{
  "session_id": "f465d650",
  "mode": "core",
  "binary": "./my_program",
  "core": "./core.12345",
  "gdb_pid": 12345,
  "status": "loading"
}

巨大なバイナリやコアファイルを読み込む際は、セッションが準備完了になるまでポーリングします:

gdb-cli status -s f465d650
{
  "session_id": "f465d650",
  "state": "ready",
  "mode": "core",
  "binary": "./my_program"
}

システムのデフォルトGDBにPythonサポートがない場合は、--gdb-pathで指定してください:

gdb-cli load --binary ./my_program --core ./core.12345 \
  --gdb-path /opt/rh/gcc-toolset-13/root/usr/bin/gdb

2. デバッグ操作

すべての操作で--session / -sを使用してセッションIDを指定します:

SESSION="f465d650"

# List threads
gdb-cli threads -s $SESSION

# Get backtrace (default: current thread)
gdb-cli bt -s $SESSION

# Get backtrace for a specific thread
gdb-cli bt -s $SESSION --thread 3

# Evaluate C/C++ expressions
gdb-cli eval-cmd -s $SESSION "my_struct->field"

# Access array elements
gdb-cli eval-element -s $SESSION "my_array" --index 5

# View local variables
gdb-cli locals-cmd -s $SESSION

# Execute raw GDB commands
gdb-cli exec -s $SESSION "info registers"

# Check session status
gdb-cli status -s $SESSION

3. セッション管理

# List all active sessions
gdb-cli sessions

# Stop a session
gdb-cli stop -s $SESSION

4. ライブアタッチデバッグ

# Attach to a running process (default: scheduler-locking + non-stop)
gdb-cli attach --pid 9876

# Attach with symbol file
gdb-cli attach --pid 9876 --binary ./my_program

# Allow memory modification and function calls
gdb-cli attach --pid 9876 --allow-write --allow-call

全コマンドリファレンス

load — コアダンプの読み込み

gdb-cli load --binary <path> --core <path> [options]

  --binary, -b      Executable file path (required)
  --core, -c        Core dump file path (required)
  --sysroot         sysroot path (for cross-machine debugging)
  --solib-prefix    Shared library prefix
  --source-dir      Source code directory
  --timeout         Heartbeat timeout in seconds (default: 600)
  --gdb-path        GDB executable path (default: "gdb")

loadは、RPCサーバーが到達可能になると直ちに"status": "loading"を返します。詳細な調査コマンドを実行する前に、gdb-cli status -s <session>を使用して"state": "ready"になるまで待機してください。

attach — プロセスへのアタッチ

gdb-cli attach --pid <pid> [options]

  --pid, -p               Process PID (required)
  --binary                Executable file path (optional)
  --scheduler-locking     Enable scheduler-locking (default: true)
  --non-stop              Enable non-stop mode (default: true)
  --timeout               Heartbeat timeout in seconds (default: 600)
  --allow-write           Allow memory modification
  --allow-call            Allow function calls

threads — スレッド一覧

gdb-cli threads -s <session> [options]

  --range           Thread range, e.g., "3-10"
  --limit           Maximum return count (default: 20)
  --filter-state    Filter by state ("running" / "stopped")

bt — バックトレース

gdb-cli bt -s <session> [options]

  --thread, -t      Specify thread ID
  --limit           Maximum frame count (default: 30)
  --full            Include local variables
  --range           Frame range, e.g., "5-15"

eval-cmd — 式の評価

gdb-cli eval-cmd -s <session> <expr> [options]

  --max-depth       Recursion depth limit (default: 3)
  --max-elements    Array element limit (default: 50)

eval-element — 配列/コンテナ要素へのアクセス

gdb-cli eval-element -s <session> <expr> --index <N>

exec — 生のGDBコマンドの実行

gdb-cli exec -s <session> <command>

  --safety-level    Safety level (readonly / readwrite / full)

thread-apply — バッチスレッド操作

gdb-cli thread-apply -s <session> <command> --all
gdb-cli thread-apply -s <session> <command> --threads "1,3,5"

出力例

threads

{
  "threads": [
    {"id": 1, "global_id": 1, "state": "stopped"},
    {"id": 2, "global_id": 2, "state": "stopped"}
  ],
  "total_count": 5,
  "truncated": true,
  "current_thread": {"id": 1, "global_id": 1, "state": "stopped"},
  "hint": "use 'threads --range START-END' for specific threads"
}

eval-cmd

{
  "expression": "(int)5+3",
  "value": 8,
  "type": "int",
  "size": 4
}

bt

{
  "frames": [
    {"number": 0, "function": "crash_thread", "address": "0x400a1c", "file": "test.c", "line": 42},
    {"number": 1, "function": "start_thread", "address": "0x7f3fa2e13fa"}
  ],
  "total_count": 2,
  "truncated": false
}

セキュリティメカニズム

コマンドホワイトリスト(アタッチモード)

安全レベル

許可されるコマンド

readonly (デフォルト)

bt, info, print, threads, locals, frame

readwrite

+ set variable

full

+ call, continue, step, next

quit, kill, shell, signalは常にブロックされます。

ハートビートタイムアウト

デフォルトでは、10分間操作がないと自動的にデタッチして終了します。--timeoutで設定可能です。

冪等性

PIDまたはコアファイルごとに1つのセッションのみが許可されます。繰り返しload/attachを実行すると、既存のsession_idが返されます。

マシン間でのコアダンプデバッグ

他のマシンからコアダンプを解析する場合、共有ライブラリのパスが異なることがあります:

# Set sysroot (path prefix replacement)
gdb-cli load --binary ./my_program --core ./core.1234 \
  --sysroot /path/to/target/rootfs

# Set source directory (for source-level debugging)
gdb-cli load --binary ./my_program --core ./core.1234 \
  --source-dir /path/to/source

開発

プロジェクト構造

src/gdb_cli/
├── cli.py              # CLI entry point (Click)
├── client.py           # Unix Socket client
├── launcher.py         # GDB process launcher
├── session.py          # Session metadata management
├── safety.py           # Command whitelist filter
├── formatters.py       # JSON output formatting
├── env_check.py        # Environment check
├── errors.py           # Error classification
└── gdb_server/
    ├── gdb_rpc_server.py   # RPC Server core
    ├── handlers.py         # Command handlers
    ├── value_formatter.py  # gdb.Value serialization
    └── heartbeat.py         # Heartbeat timeout management

skills/
└── gdb-cli/               # Claude Code skill for intelligent debugging
    ├── SKILL.md            # Skill definition
    └── evals/              # Test cases for skill evaluation

テストの実行

pip install -e ".[dev]"
pytest tests/ -v

エンドツーエンドテスト

Pythonサポート付きのGDBが必要です。tests/crash_test/にあるクラッシュテストプログラムを使用してください:

# Compile test program
cd tests/crash_test
gcc -g -pthread -o crash_test crash_test_c.c

# Generate coredump
ulimit -c unlimited
./crash_test  # Will SIGSEGV

# Find core file
ls /path/to/core_dumps/core-crash_test-*

# Run E2E test
gdb-cli load --binary ./crash_test --core /path/to/core \
  --gdb-path /opt/rh/gcc-toolset-13/root/usr/bin/gdb

既知の制限事項

  • target remoteのサポートなし(リモートデバッグにはSSHを使用してください。下記参照)

  • マルチインフェリアデバッグのサポートなし

  • GDB 12.xのGuileプリティプリンタはスレッドセーフではありません。format_string(raw=True)で回避してください

  • GDB組み込みのPythonバージョンが古い場合(例: 3.6.8)があります。コードには互換性処理が含まれています

SSH経由のリモートデバッグ

リモートマシンにインストールして1コマンドで実行:

ssh user@remote-host "pip install git+https://github.com/Cerdore/gdb-cli.git && gdb-cli load --binary ./my_program --core ./core.12345"

または、先にインストールしてからデバッグ:

# Install on remote
ssh user@remote-host "pip install git+https://github.com/Cerdore/gdb-cli.git"

# Run debugging
ssh user@remote-host "gdb-cli load --binary ./my_program --core ./core.12345"

Claude Codeスキル

本プロジェクトには、Claude Code用のgdb-cliスキルが含まれています。ソースコード解析と実行時の状態検査を組み合わせることで、インテリジェントなデバッグ支援を提供します。

スキルのインストール

bunx skills add https://github.com/Cerdore/gdb-cli --skill=gdb-cli

Claude Codeでの使用方法

/gdb-cli

# Or describe your debugging need:
I have a core dump at ./core.1234 and binary at ./myapp. Help me debug it.

機能

  • ソースコード相関: クラッシュポイント周辺のソースファイルを自動的に読み込みます

  • デッドロック検出: マルチスレッドプログラムにおける循環待機パターンを特定します

  • 安全警告: ライブプロセスにアタッチする際、本番環境のリスクについて警告します

  • 構造化レポート: 根本原因の仮説と次のステップを含む解析結果を生成します

詳細はskills/README.mdを参照してください。

ライセンス

Apache License 2.0

A
license - permissive license
Not graded
quality - not tested
B
maintenance

Maintenance

Maintainers
6dResponse time
2wRelease cycle
3Releases (12mo)
Commit activity
Issues opened vs closed

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    B
    quality
    C
    maintenance
    Provides GDB debugging functionality for use with Claude or other AI assistants, allowing users to manage debugging sessions, set breakpoints, examine variables, and execute GDB commands through natural language.
    16
    56
    158
    MIT
  • A
    license
    C
    quality
    D
    maintenance
    Enables LLM clients to interact with the GNU Debugger (GDB) for comprehensive debugging and binary analysis. It provides a wide range of tools for program execution control, memory examination, stack analysis, and disassembly.
    13
    71
    GPL 3.0
  • F
    license
    A
    quality
    D
    maintenance
    Enables AI agents to debug embedded systems by providing a comprehensive interface for GDB operations across multiple architectures like ARM and x86. It supports remote debugging via gdbserver or QEMU, allowing for detailed inspection of memory, registers, stack frames, and variables.
    31
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables AI agents to interact with GDB for debugging via the MCP protocol. Supports setting breakpoints, stepping through code, inspecting memory and registers, and more.
    85
    MIT

View all related MCP servers

Related MCP Connectors

  • Shared debugging memory for AI coding agents

  • Agent Replay Debugger MCP — record every agent step + deterministic replay. Step-debugger for

  • Live browser debugging for AI assistants — DOM, console, network via MCP.

View all MCP Connectors

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/Cerdore/gdb-cli'

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