home / skills / enoch-robinson / agent-skill-collection / debug-helper

debug-helper skill

/skills/development/debug-helper

This skill guides systematic debugging to reproduce, collect data, narrow down causes, and verify fixes across logs, environment, and code.

npx playbooks add skill enoch-robinson/agent-skill-collection --skill debug-helper

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.9 KB
---
name: debug-helper
description: 调试助手技能。当用户遇到 Bug、错误信息、程序异常、性能问题需要排查,或需要分析日志、定位问题根因时使用此技能。
---

# Debug Helper

系统化的调试方法论,帮助快速定位和解决问题。

## 调试流程

1. **复现问题**:确认问题可稳定复现
2. **收集信息**:错误信息、日志、环境
3. **缩小范围**:二分法定位问题区域
4. **分析根因**:找到真正原因而非表象
5. **验证修复**:确认问题已解决

## 信息收集清单

### 必要信息
- 完整错误信息和堆栈跟踪
- 复现步骤(最小化)
- 环境信息(OS、语言版本、依赖版本)
- 最近的代码变更

### 日志分析
```bash
# 查找错误日志
grep -i "error\|exception\|fail" app.log

# 查看特定时间段
grep "2024-01-15 10:" app.log

# 追踪请求 ID
grep "req-123456" app.log
```

## 常见问题类型

### 🔴 运行时错误
- NullPointerException → 检查空值处理
- IndexOutOfBounds → 检查数组/列表边界
- TypeError → 检查类型转换

### 🟡 逻辑错误
- 条件判断错误 → 检查边界条件
- 循环问题 → 检查终止条件
- 状态管理 → 检查状态变更时机

### 🟠 性能问题
- 响应慢 → 检查 N+1 查询、循环内IO
- 内存泄漏 → 检查未释放资源
- CPU 高 → 检查死循环、低效算法

## 调试技巧

### 二分法定位
```
1. 在中间位置添加日志
2. 确定问题在前半还是后半
3. 重复直到定位到具体行
```

### 橡皮鸭调试
向他人(或自己)解释代码逻辑,往往能发现问题。

### 最小化复现
移除无关代码,构建最小可复现案例。

## 输出格式

```markdown
## 问题诊断报告

### 问题描述
[简述问题现象]

### 根因分析
[问题的真正原因]

### 解决方案
[具体的修复步骤]

### 预防措施
[如何避免类似问题]
```

Overview

This skill is a Debug Helper that provides a systematic methodology to find and fix bugs, errors, exceptions, and performance issues. It guides you through reproducibility, targeted information collection, scope reduction, root-cause analysis, and verification of fixes. It produces a concise diagnostic report template to communicate findings and preventive measures.

How this skill works

The skill inspects error messages, stack traces, logs, environment and recent code changes to build a clear problem picture. It recommends targeted commands and patterns for log analysis, uses divide-and-conquer (binary search) to localize faults, and suggests minimal reproducible cases and rubber-duck debugging to expose logic errors. Finally, it outlines verification steps and a report format for remediation and prevention.

When to use it

  • When you encounter runtime errors, crashes, or uncaught exceptions.
  • When performance is degraded (slow responses, high CPU or memory).
  • When logs are noisy and you need to trace request or error origins.
  • When a bug is intermittent and you must establish reproducible steps.
  • When you need a clear remediation plan and preventive actions.

Best practices

  • Start by reproducing the issue and capturing a minimal test case.
  • Collect full error messages, stack traces, environment and dependency versions.
  • Use binary search (log/feature toggles) to narrow the failing region quickly.
  • Analyze logs with focused grep/time filters and follow request IDs.
  • Validate fixes with tests and a repeatable verification procedure.

Example use cases

  • Investigating a null reference or index-out-of-range runtime exception in production.
  • Tracing a slow API to an N+1 database query or blocking I/O inside a loop.
  • Locating memory leak sources by comparing heap usage across deployments.
  • Building a minimal reproducible example to share with teammates or issue trackers.
  • Generating a concise problem diagnostic report for postmortem or release notes.

FAQ

What information is essential to start debugging?

Provide the full error and stack trace, minimal reproducible steps, environment details (OS, language and dependency versions), and recent code changes.

How do I narrow down where the bug lives?

Apply a binary search strategy: add logging or toggles at midpoints, determine which half contains the fault, and iterate until you isolate the offending code line or module.