mcpField
C
core-dumps

core-dumps

github.com/mohitmishra786開発269784 回インストール18 週間前に更新
リポジトリ

core-dumps について

コアダンプによるクラッシュ調査を支援するエージェント向けスキルです。取得の有効化から GDB、LLDB での解析、シンボル不足時の対応や簡易レポート作成まで扱います。

主な機能

  1. 01Linux と macOS でのコアダンプ有効化
  2. 02coredumpctl による systemd ダンプ確認
  3. 03GDB と LLDB によるダンプ解析
  4. 04debuginfod による不足シンボル取得
  5. 05非対話型クラッシュレポートの生成

活用シーン

  1. 01プログラムを再実行せず本番クラッシュを調査
  2. 02シンボルのないコアファイルを確認
  3. 03coredumpctl でクラッシュ情報を収集・確認

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill core-dumps

インストール後、Claude Code で/core-dumpsを入力して読み込まれたか確認します。

同梱ファイルreferences/cheatsheet.md

詳細

コアダンプ

目的

不具合のあるプログラムを再実行せずに、クラッシュ後の調査のためにコアダンプを有効化、収集、分析する手順をエージェントに案内します。

トリガー

  • 「本番環境でプログラムがクラッシュしました。コアを分析するにはどうすればよいですか?」
  • 「Linux でコアダンプを有効にするにはどうすればよいですか?」
  • 「コアファイルはありますが、シンボル/ソースがありません」
  • 「コアのシンボルを取得するために debuginfod を使うにはどうすればよいですか?」
  • 「coredumpctl でクラッシュを表示してください」

ワークフロー

1. コアダンプを有効にする(Linux)
# Per-session (lost on logout)
ulimit -c unlimited

# Persistent (add to /etc/security/limits.conf)
*   soft   core   unlimited
*   hard   core   unlimited

# Check current limit
ulimit -c

# Set core pattern (where and how cores are named)
# Default: 'core' in CWD — often not useful
sudo sysctl -w kernel.core_pattern=/tmp/core-%e-%p-%t
# %e = executable, %p = PID, %t = timestamp

# Persistent (add to /etc/sysctl.d/99-core.conf)
kernel.core_pattern=/tmp/core-%e-%p-%t
kernel.core_uses_pid=1
2. systemd/coredumpctl(最新の Linux)

systemd がコアダンプを管理している場合(Ubuntu 20 以降、Fedora、Arch で一般的です):

# List recent crashes
coredumpctl list

# Show details of the latest crash
coredumpctl info

# Load latest crash in GDB
coredumpctl gdb

# Load specific PID crash
coredumpctl gdb 12345

# Export core file
coredumpctl dump -o myapp.core PID

コアの保存場所:/var/lib/systemd/coredump/。

3. コアダンプを有効にする(macOS)
# macOS uses /cores by default (must be root-writable)
ulimit -c unlimited

# Check
ls /cores/

# launchd-launched services: set in plist
# <key>HardResourceLimits</key>
# <dict><key>Core</key><integer>9223372036854775807</integer></dict>
4. GDB でコアを分析する
# Load binary and core
gdb ./prog core.12345

# If the binary was stripped, provide the unstripped copy
gdb ./prog-with-symbols core.12345

# Essential first commands
(gdb) bt                    # call stack
(gdb) bt full               # stack + locals
(gdb) info registers        # CPU state at crash
(gdb) frame 2               # jump to interesting frame
(gdb) info locals           # local variables in frame
(gdb) print ptr             # inspect a pointer

# All threads (multi-threaded crash)
(gdb) thread apply all bt full
5. LLDB でコアを分析する
lldb ./prog -c core.12345

# Or
lldb
(lldb) target create ./prog --core core.12345

# Commands
(lldb) bt
(lldb) thread backtrace all
(lldb) frame select 2
(lldb) frame variable
6. シンボルが不足している場合:debuginfod

debuginfod は中央サーバーからデバッグシンボルを提供し、ビルド ID を DWARF データに対応付けます。

# Install client (Debian/Ubuntu)
sudo apt install debuginfod

# Enable (add to ~/.bashrc or /etc/environment)
export DEBUGINFOD_URLS="https://debuginfod.ubuntu.com https://debuginfod.elfutils.org"

# GDB auto-fetches symbols when DEBUGINFOD_URLS is set
gdb ./prog core

# Manually query
debuginfod-find debuginfo <build-id>
debuginfod-find source <build-id> /path/to/file.c
7. シンボルが不足している場合:手動での方法
# Check if binary has a build ID
readelf -n ./prog | grep Build

# Find the correct debug package
# Debian: apt install prog-dbg or prog-dbgsym
# RPM: dnf install prog-debuginfo

# Point GDB to debug symbols directory
(gdb) set debug-file-directory /usr/lib/debug

# Or use eu-readelf to dump build ID, then find .debug file
eu-readelf -n ./prog
find /usr/lib/debug -name "*.debug" | xargs eu-readelf -n 2>/dev/null | grep <build-id>
8. バイナリをストリップしてシンボルを保持する

ベストプラクティス:シンボル付きでビルドし、配布用にストリップして、ストリップしていないコピーを保持します。

# Build
gcc -g -O2 -o prog main.c

# Separate debug info
objcopy --only-keep-debug prog prog.debug
objcopy --strip-debug prog prog.stripped

# Add a debuglink so GDB finds the debug file automatically
objcopy --add-gnu-debuglink=prog.debug prog.stripped

# Deploy prog.stripped; keep prog.debug in a symbols store indexed by build-id
9. 完全なデバッグセッションなしでコアから迅速にトリアージする
# Print backtrace non-interactively
gdb -batch -ex 'bt full' -ex 'thread apply all bt full' ./prog core 2>&1 | tee crash.txt

# Print registers
gdb -batch -ex 'info registers' ./prog core

# Check signal that caused crash
gdb -batch -ex 'info signal' ./prog core

コアパターントークン、coredumpctl、GDB/LLDB コマンド、debuginfod サーバー、ストリップとシンボルのワークフローを網羅したチートシートについては、references/cheatsheet.md を参照してください。

関連スキル

  • GDB セッションの詳細については skills/debuggers/gdb を使用してください
  • LLDB ベースの分析には skills/debuggers/lldb を使用してください
  • 不具合が本番環境に到達する前に検出するには skills/runtimes/sanitizers を使用してください
  • readelf、ビルド ID、バイナリ検査については skills/binaries/elf-inspection を使用してください

コメント