// ice.rsfn main() { // Minimal code that triggers the ICE}
2
Compile with backtrace
# Set environment variableexport RUST_BACKTRACE=1# Compile the test caserustc ice.rs# Or with your stage 1 compiler./build/x86_64-unknown-linux-gnu/stage1/bin/rustc ice.rs
3
Get detailed backtrace
# Full backtrace with RUST_BACKTRACE=fullRUST_BACKTRACE=full rustc ice.rs# With additional loggingRUSTC_LOG=debug rustc ice.rs 2>&1 | tee debug.log
# Start rustc under GDBgdb --args ./build/stage1/bin/rustc ice.rs# In GDB:(gdb) run# Wait for crash(gdb) backtrace(gdb) info locals(gdb) frame 3(gdb) print variable_name
gdb --args rustc ice.rs# Set breakpoint on function(gdb) break rustc_middle::ty::context::TyCtxt::create_and_enter(gdb) run# Set breakpoint on panic(gdb) break rust_panic(gdb) run# Conditional breakpoint(gdb) break file.rs:123 if variable == 5
# Use rr for record and replayrr record ./build/stage1/bin/rustc ice.rsrr replay# In replay mode, you can reverse-execute(rr) reverse-continue(rr) reverse-step
# Enable all debug logsRUSTC_LOG=debug rustc file.rs# Specific moduleRUSTC_LOG=rustc_middle::ty=debug rustc file.rs# Multiple modulesRUSTC_LOG=rustc_borrowck=debug,rustc_mir=trace rustc file.rs
# Log all queriesRUSTC_LOG=rustc_query_impl=debug rustc file.rs# Log specific queryRUSTC_LOG=rustc_query_impl::queries::type_of=trace rustc file.rs# With timestampsRUSTC_LOG_COLOR=always RUSTC_LOG=debug rustc file.rs
# Only errors and warningsRUSTC_LOG=warn rustc file.rs# Everything except noiseRUSTC_LOG=debug,rustc_metadata=info rustc file.rs# Save to fileRUSTC_LOG=debug rustc file.rs 2>&1 | tee debug.log
# Dump MIR before and after optimizationsrustc -Z dump-mir=all -Z dump-mir-dir=mir file.rs# Disable MIR optimizationsrustc -Z mir-opt-level=0 file.rs# Specific MIR passRUSTC_LOG=rustc_mir_transform=debug rustc file.rs
# Single codegen unitrustc -C codegen-units=1 file.rs# List codegen unitsrustc -Z print-mono-items=lazy file.rs
# Run UI tests./x.py test tests/ui# Find specific test./x.py test tests/ui --test-args my-test
2
Run with verbose output
# Verbose test output./x.py test tests/ui/my-test.rs --test-args --verbose# Show compiler output./x.py test tests/ui/my-test.rs --test-args --nocapture
3
Debug the test
# Get the rustc command from test output# Then run it manually:RUST_BACKTRACE=1 ./build/stage1/bin/rustc tests/ui/my-test.rs# Or under GDB:gdb --args ./build/stage1/bin/rustc tests/ui/my-test.rs
# Set backtraceexport RUST_BACKTRACE=1# Enable panic loggingexport RUSTC_LOG=debug# Run under debuggergdb --args ./build/stage1/bin/rustc file.rs(gdb) break rust_panic(gdb) run
Debugging why compilation is slow
# Time each passrustc -Z time-passes file.rs# Self-profilerustc -Z self-profile file.rs# Analyze with measuremecargo install measuremecrox file-pid.mm_profdata
Debugging a type error
# Enable type loggingRUSTC_LOG=rustc_hir_analysis::check=debug rustc file.rs# Dump type informationrustc -Z print-type-sizes file.rs