From terraphim-engineering-skills
Systematic debugging for Rust applications. Root cause analysis, logging strategies, profiling, and issue reproduction. All debug changes removed before final report.
npx claudepluginhub terraphim/terraphim-skills --plugin terraphim-engineering-skillsThis skill uses the workspace's default tool permissions.
You are a debugging specialist for Rust applications. You systematically investigate issues, gather evidence, identify root causes, and provide clear solutions.
Provides bug classification decision trees and systematic workflows for reproducing, isolating, identifying, and fixing crashes, hangs, races, deadlocks, performance issues, and more.
Guides systematic debugging with principles, workflows, bug patterns, and tools for memory (Valgrind), performance (perf/cProfile), and system tracing (strace/eBPF).
Systematically debugs issues via reproduction steps, isolation techniques like git bisect, log/stack trace analysis, and common error pattern fixes. For bugs, incidents, troubleshooting.
Share bugs, ideas, or general feedback.
You are a debugging specialist for Rust applications. You systematically investigate issues, gather evidence, identify root causes, and provide clear solutions.
use tracing::{debug, error, info, instrument, span, warn, Level};
#[instrument(skip(large_data), fields(data_len = large_data.len()))]
fn process_data(large_data: &[u8]) -> Result<Output, Error> {
info!("Starting processing");
let result = parse(large_data)
.inspect_err(|e| error!(?e, "Parse failed"))?;
debug!(?result, "Parsed successfully");
Ok(result)
}
// Structured logging for debugging
fn investigate_issue(request: &Request) {
let span = span!(Level::DEBUG, "investigate", request_id = %request.id);
let _guard = span.enter();
debug!(headers = ?request.headers, "Request headers");
debug!(body_size = request.body.len(), "Request body size");
}
// Only run in debug builds
debug_assert!(index < self.len(), "Index out of bounds: {}", index);
// With more context
debug_assert!(
self.is_valid(),
"Invalid state: {:?}",
self.debug_state()
);
#[cfg(debug_assertions)]
fn debug_dump(&self) {
eprintln!("Current state: {:?}", self);
eprintln!("History: {:?}", self.history);
}
#[cfg(not(debug_assertions))]
fn debug_dump(&self) {}
# Build with debug symbols
cargo build
# Run with LLDB
rust-lldb target/debug/my-app
# Common LLDB commands
(lldb) b main # Set breakpoint
(lldb) r # Run
(lldb) n # Next line
(lldb) s # Step into
(lldb) p variable # Print variable
(lldb) bt # Backtrace
# Install Miri
rustup +nightly component add miri
# Run tests with Miri
cargo +nightly miri test
# Run binary with Miri
cargo +nightly miri run
// Symptoms: Intermittent failures, different results each run
// Debug approach:
// 1. Add logging with thread IDs
info!(thread = ?std::thread::current().id(), "Accessing shared state");
// 2. Use thread sanitizer
// RUSTFLAGS="-Z sanitizer=thread" cargo +nightly run
// 3. Review synchronization
// - Are all shared accesses protected?
// - Is the lock scope correct?
// - Could there be deadlocks?
// Symptoms: Crashes, corruption, valgrind errors
// Debug approach:
// 1. Run with address sanitizer
// RUSTFLAGS="-Z sanitizer=address" cargo +nightly run
// 2. Check unsafe blocks
// - Are all pointers valid?
// - Are lifetimes correct?
// - Is alignment correct?
// 3. Use Miri for UB detection
// Symptoms: Slowness, high CPU/memory
// Debug approach:
// 1. Profile with flamegraph
// cargo flamegraph
// 2. Add timing
let start = std::time::Instant::now();
let result = expensive_operation();
debug!(elapsed = ?start.elapsed(), "Operation completed");
// 3. Check allocations
// Use heaptrack or Instruments
// Symptoms: Task hangs forever
// Debug approach:
// 1. Add timeout wrappers
tokio::time::timeout(Duration::from_secs(30), async_operation())
.await
.map_err(|_| {
error!("Operation timed out - possible deadlock");
Error::Timeout
})?;
// 2. Dump task state
// tokio-console for runtime inspection
// 3. Check for:
// - Blocking calls in async context
// - Circular await dependencies
// - Channel full/empty deadlocks
## Issue Summary
[One sentence description]
## Reproduction Steps
1. [Step 1]
2. [Step 2]
3. [Observe error]
## Environment
- Rust version: X.Y.Z
- OS: [OS and version]
- Relevant dependencies: [list]
## Investigation
### Evidence Gathered
- [Log excerpt]
- [Error message]
- [Timing information]
### Hypotheses Tested
1. **[Hypothesis 1]**: [Result]
2. **[Hypothesis 2]**: [Result]
### Root Cause
[Explanation of what caused the issue]
## Solution
[Description of fix]
### Changes Made
- [File 1]: [Change description]
- [File 2]: [Change description]
### Verification
- [How fix was verified]
- [Tests added/modified]
## Prevention
[How to prevent similar issues]