Types of Compiler Issues
ICE (Internal Compiler Error)
The compiler panicked - this is always a bug
Miscompilation
Incorrect code generation - produces wrong results
Compile-time Error
False positive or incorrect error message
Performance Regression
Compilation takes too long or uses too much memory
Setting Up for Debugging
Debugging Internal Compiler Errors (ICEs)
Reproducing an ICE
Using GDB with the Compiler
- Basic GDB
- Breakpoints
- Advanced
Debugging with LLDB
Debug Logging
Using RUSTC_LOG
The compiler has extensive debug logging:- Basic Logging
- Query Logging
- Filtering
Compiler Flags for Debugging
Debugging Specific Components
Borrow Checker
- NLL Debugging
- Borrow Errors
Type Checker
Code Generation
- LLVM Backend
- MIR Optimization
- Codegen Units
Debugging Tests
Running Individual Tests
Updating Test Expectations
Debugging Miscompilations
Isolating the Problem
Tools for Miscompilations
Miri
Detect undefined behavior:
Sanitizers
Detect memory errors:
Valgrind
Memory debugging:
cargo-bisect-rustc
Find regressions:
Advanced Debugging Techniques
Using LLVM Tools
- llvm-dis
- llvm-opt
- llvm-objdump
Query System Debugging
Memory Debugging
- Massif (Heap Profiler)
- DHAT (Heap Analyzer)
Common Debugging Scenarios
Debugging a panic in the compiler
Debugging a panic in the compiler
Debugging why compilation is slow
Debugging why compilation is slow
Debugging a type error
Debugging a type error
Debugging a borrow check error
Debugging a borrow check error
Debugging Checklist
Reproduce the issue
- Create minimal test case
- Verify it reproduces consistently
- Note exact compiler version
Isolate the problem
- Identify which compiler pass fails
- Check if it’s a recent regression
- Test with different flags
Debug
- Use appropriate debugging tool
- Set breakpoints at key locations
- Inspect relevant data structures
Resources
Debugging Chapter
Rustc dev guide debugging section
GDB Tutorial
GDB documentation
LLDB Tutorial
LLDB tutorial
Zulip #t-compiler
Ask for help on Zulip
Next Steps
Profiling
Learn about profiling the compiler
Compiler Development
Return to compiler development guide