Run the following sequence.
This skill is the debugging commander, not a reference note. Follow the workflow order strictly. Use the command toolbox only inside the relevant phase, especially Instrument and Feedback Loop. Do not run random commands before reproduction and hypotheses are clear.
Switch to caveman communication for this session: drop all filler, articles, and pleasantries. Keep full technical accuracy. Stay in caveman mode until the user says "stop caveman" or "normal mode".
Go up a layer of abstraction. Give a map of all relevant modules and callers in the area related to the current problem, using the project's domain glossary vocabulary. If no CONTEXT.md exists, infer domain terms from the codebase.
When relevant, identify:
Run the full diagnosis discipline.
Try in order:
Do not proceed to Phase 2 without a loop you believe in.
Confirm the loop produces the exact failure the user described. Wrong bug = wrong fix.
Document:
Generate 3–5 ranked falsifiable hypotheses before testing any. Show ranked list to user before proceeding.
Format every hypothesis as:
> If X is the cause, then changing Y will make the bug disappear.
One variable at a time. Tag all debug logs [DEBUG-xxxx] for easy cleanup. Prefer debugger/REPL over log spam. For perf regressions: measure first, fix second.
Use the command toolbox below only when it matches the current hypothesis.
# Node.js debugger
node --inspect-brk app.js
# Chrome DevTools: chrome://inspect
# Console debugging
console.log(JSON.stringify(obj, null, 2))
console.trace("Call stack here")
console.time("perf"); /* code */ console.timeEnd("perf")
# Memory leaks
node --expose-gc --max-old-space-size=4096 app.js
# Built-in debugger
python -m pdb script.py
# Breakpoint in code
breakpoint()
# Verbose tracing
python -X tracemalloc script.py
# Profile
python -m cProfile -s cumulative script.py
# LLDB debugging
lldb ./MyApp
(lldb) breakpoint set --name main
(lldb) run
(lldb) po myVariable
# Xcode: Product -> Profile (Instruments)
* { outline: 1px solid red !important; }
.debug { background: rgba(255,0,0,0.1) !important; }
# HTTP debugging
curl -v https://api.example.com/endpoint
curl -w "@curl-format.txt" -o /dev/null -s https://example.com
# DNS
dig example.com
nslookup example.com
# Ports
lsof -i :3000
netstat -tlnp
git bisect start
git bisect bad
git bisect good abc1234
# Test checked-out commit, then mark it:
git bisect good
# or:
git bisect bad
git bisect reset
# What's using this port?
lsof -i :PORT
# What's this process doing?
ps aux | grep PROCESS
# Watch file changes
fswatch -r ./src
# Disk space
df -h
# System resource usage
top -l 1 | head -10
| Error | Likely cause | First check |
|---|---|---|
| ------- | -------------- | ------------- |
Cannot read property of undefined | Missing null check or wrong data shape | Validate input shape and caller contract |
ENOENT | File or directory does not exist | Check path, working directory, and creation step |
CORS error | Backend missing CORS headers | Check allowed origins and middleware order |
Module not found | Missing dependency or wrong import path | Check package install and path alias config |
Hydration mismatch | Server/client rendered different HTML | Check client-only state and deterministic rendering |
Segmentation fault | Memory corruption or invalid pointer | Check array bounds, pointer validity, native dependency |
Connection refused | Service not running on expected port | Check process, port, host, container mapping |
Permission denied | File or network permission issue | Check ownership, chmod, sandbox, firewall |
Write the regression test before the fix, but only at a correct seam. If no correct seam exists, that is the finding; note it.
Apply the minimal correct fix. Do not refactor while debugging unless refactor is required to expose the correct seam.
Remove all [DEBUG-...] logs. Confirm original repro no longer reproduces. State the winning hypothesis in the commit message or handoff note.
When the user signals they are done or the session is wrapping up, generate a handoff document summarising:
Save the handoff document to the OS temp directory.
共 2 个版本