Chuyển đến nội dung
Skillpedia
Kiểm thử48k · #4703

gdb-cli

Skill này làm gì

Giúp tìm và sửa lỗi trong các chương trình máy tính viết bằng C/C++. Nó phân tích trạng thái của chương trình khi bị sập hoặc treo, so sánh với mã nguồn để hiểu điều đã xảy ra.

Khi nào nên dùng

  • ✓Khi một chương trình bị sập và bạn có tệp 'crash dump'.
  • ✓Khi một chương trình đang chạy nhưng không phản hồi (bị treo).
  • ✓Khi muốn hiểu vì sao một chương trình bị sập hoặc dùng quá nhiều bộ nhớ.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/gdb-cli/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/gdb-cli/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Phân tích crash dump của chương trình 'my_app' nằm tại '/tmp/core.1234' và cho tôi biết lỗi nằm ở đâu.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Nó dùng công cụ GDB để xem trạng thái của chương trình tại thời điểm lỗi. Sau đó, nó so sánh thông tin tìm thấy với mã nguồn để đưa ra lời giải thích rõ ràng về vấn đề.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

GDB Debugging Assistant

Overview

A GDB debugging skill designed for AI agents. Combines source code analysis with runtime state inspection using gdb-cli to provide intelligent debugging assistance for C/C++ programs.

When to Use This Skill

  • Analyze core dumps or crash dumps
  • Debug running processes with GDB attach
  • Investigate crashes, deadlocks, or memory issues
  • Get intelligent debugging assistance with source code context
  • Debug multi-threaded applications

Do Not Use This Skill When

  • The task is unrelated to C/C++ debugging
  • The user needs general-purpose assistance without debugging
  • No GDB is available (GDB 9.0+ with Python support required)

Prerequisites

# Install gdb-cli
pip install gdb-cli

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

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

Requirements:

  • Python 3.6.8+
  • GDB 9.0+ with Python support enabled
  • Linux OS

How It Works

Step 1: Initialize Debug Session

For core dump analysis:

gdb-cli load --binary <binary_path> --core <core_path> [--gdb-path <gdb_path>]

For live process debugging:

gdb-cli attach --pid <pid> [--binary <binary_path>]

Output: A session_id like "session_id": "a1b2c3". Store this for subsequent commands.

Step 2: Gather Initial Information

SESSION="<session_id>"

# List all threads
gdb-cli threads -s $SESSION

# Get backtrace (with local variables)
gdb-cli bt -s $SESSION --full

# Get registers
gdb-cli registers -s $SESSION

Step 3: Correlate Source Code (CRITICAL)

For each frame in the backtrace:

  1. Extract frame info: {file}:{line} in {function}
  2. Read source context: Get ±20 lines around the crash point
  3. Get local variables: gdb-cli locals-cmd -s $SESSION --frame <N>
  4. Analyze: Correlate code logic with variable values

Example correlation:

Frame #0: process_data() at src/worker.c:87
Source code shows:
  85: Node* node = get_node(id);
  86: if (node == NULL) return;
  87: node->data = value;  <- Crash here

Variables show:
  node = 0x0 (NULL)

Analysis: The NULL check on line 86 didn't catch the issue.

Step 4: Deep Investigation

# Examine variables
gdb-cli eval-cmd -s $SESSION "variable_name"
gdb-cli eval-cmd -s $SESSION "ptr->field"
gdb-cli ptype -s $SESSION "struct_name"

# Memory inspection
gdb-cli memory -s $SESSION "0x7fffffffe000" --size 64

# Disassembly
gdb-cli disasm -s $SESSION --count 20

# Check all threads (for deadlock analysis)
gdb-cli thread-apply -s $SESSION bt --all

# View shared libraries
gdb-cli sharedlibs -s $SESSION

Step 5: Session Management

# List active sessions
gdb-cli sessions

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

# Stop session (cleanup)
gdb-cli stop -s $SESSION

Common Debugging Patterns

Pattern: Null Pointer Dereference

Indicators:

  • Crash on memory access instruction
  • Pointer variable is 0x0

Investigation:

gdb-cli registers -s $SESSION  # Check RIP
gdb-cli eval-cmd -s $SESSION "ptr"  # Check pointer value

Pattern: Deadlock

Indicators:

  • Multiple threads stuck in lock functions
  • pthread_mutex_lock in backtrace

Investigation:

gdb-cli thread-apply -s $SESSION bt --all
# Look for circular wait patterns

Pattern: Memory Corruption

Indicators:

  • Crash in malloc/free
  • Garbage values in variables

Investigation:

gdb-cli memory -s $SESSION "&variable" --size 128
gdb-cli registers -s $SESSION

Examples

Example 1: Core Dump Analysis

# Load core dump
gdb-cli load --binary ./myapp --core /tmp/core.1234

# Get crash location
gdb-cli bt -s a1b2c3 --full

# Examine crash frame
gdb-cli locals-cmd -s a1b2c3 --frame 0

Example 2: Live Process Debugging

# Attach to stuck server
gdb-cli attach --pid 12345

# Check all threads
gdb-cli threads -s b2c3d4

# Get all backtraces
gdb-cli thread-apply -s b2c3d4 bt --all

Best Practices

  • Always read source code before drawing conclusions from variable values
  • Use --range for pagination on large thread counts or deep backtraces
  • Use ptype to understand complex data structures before examining values
  • Check all threads for multi-threaded issues
  • Cross-reference types with source code definitions

Security & Safety Notes

  • This skill requires GDB access to processes and core dumps

…

Câu hỏi thường gặp

Tôi có cần cài đặt gì không?

Có, bạn cần cài GDB (công cụ gỡ lỗi) cũng như công cụ gdb-cli, một tiện ích bổ sung cho GDB.

Nó có hoạt động với mọi ngôn ngữ lập trình không?

Không, công cụ này chỉ dành cho chương trình viết bằng C và C++.

'Crash dump' là gì?

Đây là tệp mà hệ thống tự động tạo khi một chương trình bị sập, chứa thông tin về trạng thái của chương trình tại thời điểm đó.

Chi tiết

Mô tả gốc của tác giả

GDB debugging assistant for AI agents - analyze core dumps, debug live processes, investigate crashes and deadlocks with source code correlation

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#4703
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự