一键导入
debugging
Systematic debugging methodology for finding and fixing bugs. Use when investigating issues, tracing errors, or fixing production problems.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Systematic debugging methodology for finding and fixing bugs. Use when investigating issues, tracing errors, or fixing production problems.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
RESTful API design best practices. Use when designing endpoints, request/response schemas, error handling, and API versioning.
Perform thorough code reviews with security, performance, and quality checks. Use when reviewing PRs, auditing code changes, or finding potential bugs.
Database design and optimization. Use for schema design, queries, migrations, indexing, and performance tuning.
Docker and containerization best practices. Use for Dockerfile creation, docker-compose, multi-stage builds, and container optimization.
Technical documentation best practices. Use for writing READMEs, API docs, code comments, and project documentation.
Git and GitHub workflow best practices. Use for commits, branches, PRs, merging, and version control operations.
| name | debugging |
| description | Systematic debugging methodology for finding and fixing bugs. Use when investigating issues, tracing errors, or fixing production problems. |
Methodical problem-solving approach for identifying and resolving bugs efficiently.
Before fixing, confirm you can reproduce:
**Reproduction Steps:**
1. Navigate to /dashboard
2. Click "Create New" button
3. Fill form with empty values
4. Click submit
5. **Expected**: Validation error shown
6. **Actual**: Page crashes with error
┌─────────────────────────────────────────┐
│ Is the bug in frontend or backend? │
│ ↓ │
│ Which component/function? │
│ ↓ │
│ What input triggers it? │
│ ↓ │
│ What's the expected vs actual? │
└─────────────────────────────────────────┘
Based on symptoms, hypothesize potential causes:
Add targeted logging or use debugger to verify:
// Add strategic logging
log.Printf("[DEBUG] Handler input: %+v", input)
log.Printf("[DEBUG] Database result: %+v, err: %v", result, err)
log.Printf("[DEBUG] Response: %+v", response)
// ❌ Bug: Nil pointer dereference
func (h *Handler) GetName(user *User) string {
return user.Name // Crashes if user is nil
}
// ✅ Fix: Check for nil
func (h *Handler) GetName(user *User) string {
if user == nil {
return ""
}
return user.Name
}
// ❌ Bug: Index out of bounds
for i := 0; i <= len(items); i++ {
process(items[i])
}
// ✅ Fix: Correct boundary
for i := 0; i < len(items); i++ {
process(items[i])
}
// ❌ Bug: Data race
var counter int
go func() { counter++ }()
go func() { counter++ }()
// ✅ Fix: Use sync primitives
var counter int64
go func() { atomic.AddInt64(&counter, 1) }()
go func() { atomic.AddInt64(&counter, 1) }()
// ❌ Bug: Event listener not cleaned up
useEffect(() => {
window.addEventListener('resize', handleResize);
}, []);
// ✅ Fix: Cleanup on unmount
useEffect(() => {
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);
// ❌ Bug: Missing await
async function fetchData() {
const response = fetch('/api/data'); // Missing await
return response.json(); // Error: response is a Promise
}
// ✅ Fix: Proper async handling
async function fetchData() {
const response = await fetch('/api/data');
return response.json();
}
# Install
go install github.com/go-delve/delve/cmd/dlv@latest
# Debug
dlv debug ./cmd/main.go
# Set breakpoint
(dlv) break main.go:42
(dlv) continue
(dlv) print variableName
(dlv) next
(dlv) step
import "github.com/davecgh/go-spew/spew"
// Pretty print complex structures
spew.Dump(complexObject)
// Or use JSON for readability
data, _ := json.MarshalIndent(obj, "", " ")
log.Printf("Object: %s", data)
import _ "net/http/pprof"
// Start pprof server
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
// Access: http://localhost:6060/debug/pprof/
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
function App() {
return (
<QueryClientProvider client={queryClient}>
<MyApp />
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
);
}
// Group related logs
console.group('Form Submission');
console.log('Form data:', formData);
console.log('Validation result:', validationResult);
console.groupEnd();
// Trace execution path
console.trace('How did we get here?');
// Measure performance
console.time('API Call');
await fetchData();
console.timeEnd('API Call');
**Problem**: User cannot login
1. Why? → Login API returns 500 error
2. Why? → Database query fails
3. Why? → Connection pool exhausted
4. Why? → Connections not being released
5. Why? → Missing defer db.Close() in handler
**Root Cause**: Resource leak due to missing cleanup
**Fix**: Add proper connection release
# Use git bisect to find the commit that introduced the bug
git bisect start
git bisect bad HEAD # Current version is broken
git bisect good v1.0.0 # v1.0.0 was working
# Git will checkout middle commit, test it, then:
git bisect good # or
git bisect bad
# Continue until culprit is found
git bisect reset # When done
import "go.uber.org/zap"
logger, _ := zap.NewProduction()
defer logger.Sync()
logger.Info("request processed",
zap.String("method", r.Method),
zap.String("path", r.URL.Path),
zap.Int("status", status),
zap.Duration("duration", time.Since(start)),
zap.String("request_id", requestID),
)
✅ Do Log:
❌ Don't Log: