install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/nginx-c-module-debug" ~/.claude/skills/comeonoliver-skillshub-nginx-c-module-debug && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/nginx-c-module-debug/SKILL.mdsource content
nginx.org C Module Debugging Best Practices
Comprehensive debugging guide for nginx C modules, derived from the official nginx development documentation and production debugging experience. Contains 45 rules across 8 categories, prioritized by impact to guide systematic diagnosis of crashes, memory bugs, and behavioral issues in nginx modules.
Companion skills: This skill complements nginx-c-modules (correctness) and nginx-c-module-perf-reliability (performance). This skill covers debugging and diagnosis.
When to Apply
Reference these guidelines when:
- Diagnosing nginx worker crashes (segfaults, SIGABRT, SIGSEGV)
- Finding memory bugs (use-after-free, leaks, pool corruption, buffer overruns)
- Setting up GDB and core dump analysis for nginx
- Tracing request flow through phases, subrequests, and filter chains
- Instrumenting nginx modules with debug logging and dynamic tracing tools
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Crash Diagnosis & Signals | CRITICAL | |
| 2 | Memory Bug Detection | CRITICAL | |
| 3 | GDB & Core Dump Analysis | HIGH | |
| 4 | Request Flow Tracing | HIGH | |
| 5 | Debug Logging Patterns | MEDIUM-HIGH | |
| 6 | State & Lifecycle Debugging | MEDIUM | |
| 7 | Dynamic Tracing Tools | MEDIUM | |
| 8 | Build & Sanitizer Configuration | LOW-MEDIUM | |
Quick Reference
1. Crash Diagnosis & Signals (CRITICAL)
- Identify Segfault Crash Signature from Signal and Addresscrash-segfault-signature
- Recognize NULL Pointer Dereference Patterns in nginx Modulescrash-null-deref-pattern
- Diagnose Double Finalize Crashes from Request Reference Countcrash-double-free-finalize
- Detect Stack Overflow from Recursive Subrequest or Filter Chainscrash-stack-overflow
- Extract Crash Context from Worker Exit Log Messagescrash-worker-exit-log
- Avoid Crashes from error_page Internal Redirect Context Invalidationcrash-error-page-redirect
2. Memory Bug Detection (CRITICAL)
- Detect Use-After-Free from Pool Destruction Timingmemdbg-use-after-free
- Identify Pool Memory Leak Patterns from Growing Worker RSSmemdbg-pool-leak-pattern
- Diagnose Shared Memory Slab Corruption from Multi-Worker Crashesmemdbg-slab-corruption
- Detect Resource Leaks from Missing Pool Cleanup Handlersmemdbg-cleanup-handler-leak
- Find Buffer Overrun from ngx_pnalloc Size Miscalculationmemdbg-buffer-overrun
- Avoid Storing Long-Lived Pointers in Temporary Poolsmemdbg-temp-pool-misuse
- Use Valgrind Pool-Level Tracing to Find Leaked Allocationsmemdbg-valgrind-pool-trace
3. GDB & Core Dump Analysis (HIGH)
- Configure Core Dump Generation for nginx Worker Crashesgdb-coredump-setup
- Attach GDB to a Running nginx Worker Processgdb-attach-worker
- Read nginx Backtrace to Identify Crash Module and Phasegdb-backtrace-read
- Inspect ngx_http_request_t Fields in GDB for Request Stategdb-inspect-request
- Extract Debug Log from Memory Buffer Using GDB Scriptgdb-memory-buffer-extract
- Use GDB Watchpoints to Catch Memory Corruption at Write Timegdb-watchpoint-corruption
4. Request Flow Tracing (HIGH)
- Trace Request Through HTTP Phase Handlerstrace-phase-handler-flow
- Map Subrequest Parent-Child Relationships for Debuggingtrace-subrequest-tree
- Trace Filter Chain Execution Order and Data Flowtrace-filter-chain-order
- Trace Upstream Callback Sequence for Proxy Debuggingtrace-upstream-callback-seq
- Trace Event Handler Execution for Connection Debuggingtrace-event-handler-chain
- Trace Configuration Inheritance Through Server and Location Blockstrace-config-inheritance
5. Debug Logging Patterns (MEDIUM-HIGH)
- Use Correct Debug Mask for Targeted Log Filteringdbglog-debug-mask
- Use debug_connection to Isolate Single-Client Debug Outputdbglog-debug-connection
- Use Memory Buffer Logging to Capture Debug Output Without Disk I/Odbglog-memory-buffer
- Set Log Action String for Context in Error Messagesdbglog-log-action-string
- Format ngx_str_t Correctly in Debug Log Messagesdbglog-format-ngx-str
6. State & Lifecycle Debugging (MEDIUM)
- Track Connection State Transitions for Lifecycle Debuggingstate-connection-lifecycle
- Debug Upstream Module State by Logging Transition Pointsstate-upstream-state-machine
- Detect Timer Leaks from Events Not Removed Before Pool Destructionstate-timer-leak
- Inspect Event Flags to Debug Unexpected Handler Invocationstate-event-flag-debug
- Track Request Reference Count to Debug Premature Destructionstate-request-count-track
7. Dynamic Tracing Tools (MEDIUM)
- Use strace to Trace System Call Patterns in nginx Workersprobe-strace-syscall
- Trace Request Processing with DTrace pid Providerprobe-dtrace-request
- Trace Memory Pool Allocations with SystemTapprobe-systemtap-pool
- Measure Per-Function Latency with eBPF Probesprobe-ebpf-latency
- Detect File Descriptor Leaks with strace and /procprobe-strace-fd-leak
8. Build & Sanitizer Configuration (LOW-MEDIUM)
- Compile nginx with Full Debug Symbols and No Optimizationbuild-debug-flags
- Build nginx with AddressSanitizer for Memory Error Detectionbuild-asan-configure
- Use Single-Process Mode for Simplified Debuggingbuild-single-process
- Use nginx Valgrind Suppressions to Reduce False Positivesbuild-valgrind-suppressions
- Enable NGX_DEBUG_PALLOC for Fine-Grained Pool Allocation Trackingbuild-debug-palloc
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |