How it works
Source mapping relies on DWARF debug symbols embedded in your contractβs WASM:1
Compile with debug symbols
Build your contract with debug information included in the WASM binary.
2
DWARF parsing
Erst reads the
.debug_info and .debug_line sections from the WASM.3
Instruction mapping
When a trap occurs, Erst maps the WASM instruction offset to source location.
4
Display source context
The exact file, line, and column are displayed in the trace.
Enabling debug symbols
Compile your Soroban contract with debug symbols:Using Cargo features
Add debug features to your contract build:Cargo.toml
Alternative: Debug profile
Build with the debug profile:Debug symbols increase WASM file size significantly. Only use them for development and debugging.
Verify debug symbols
Check if your WASM contains debug information:Using source mapping
When debugging with source-mapped WASM, Erst automatically shows source locations:Output with source mapping
When a failure occurs, youβll see:Output without source mapping
Without debug symbols, you only see:Source mapping in the interactive viewer
The interactive trace viewer shows source locations at each step:GitHub link generation
When in a Git repository, Erst automatically generates clickable GitHub links:1
Git repository detection
Erst detects if youβre in a Git repository.
2
Remote URL extraction
Reads the GitHub remote URL from
.git/config.3
Commit hash
Gets the current commit hash to create a permanent link.
4
Line number
Appends
#L<line> to the URL for direct navigation.Split-pane source view
View trace and source code side by side:The split-pane view highlights the exact line where execution is or where an error occurred.
Source mapping architecture
Erstβs source mapping implementation consists of:DWARF parser
Location:internal/dwarf/parser.go (Go) and src/source_mapper.rs (Rust)
- Parses
.debug_infosections for compilation units - Reads
.debug_linesections for instruction-to-line mappings - Handles optimized code and inlined functions
Source mapper
Location:internal/trace/sourcemap.go
- Maps WASM instruction offsets to source locations
- Caches mappings for performance
- Provides graceful fallback when debug info is missing
Source context loader
Location:internal/trace/splitpane.go
- Reads source files from disk
- Extracts context lines around the target line
- Handles missing files gracefully
Debug symbol format
DWARF sections
Erst reads these DWARF sections from WASM:Optimization handling
Optimized builds present challenges:- Inlining: Functions may be inlined, making the call stack shallow
- Dead code elimination: Some code may not exist in the WASM
- Register allocation: Variables may not have stable locations
For the most accurate source mapping during debugging, use unoptimized builds. For production, optimize without debug symbols.
Local variable inspection
With debug symbols, you can inspect local variables at trap points:Source mapping in error suggestions
The error suggestion engine uses source locations to provide context:Troubleshooting
No source locations shown
1
Check debug symbols
Verify your WASM has debug sections:
2
Rebuild with debug
Add
debug = true to your Cargo.toml and rebuild.3
Check WASM size
Debug symbols increase size significantly. If size is similar to release build, debug info may be missing.
Wrong line numbers
1
Verify build
Ensure the WASM youβre debugging matches your source code.
2
Check optimization
Highly optimized builds can have imprecise line mappings.
3
Use dev profile
Build with
--profile dev for best accuracy.Missing source files
1
Check file paths
DWARF sections contain absolute or relative paths to source files.
2
Run from repo root
Erst looks for source files relative to the current directory.
3
Check Git status
Ensure source files exist at the expected locations.
Best practices
Development builds
For debugging and development:Cargo.toml
Production builds
For deployment to mainnet:Cargo.toml
CI/CD
Create separate build jobs:.github/workflows/build.yml
Future enhancements
Upcoming source mapping features:- Full stack trace with source locations for all frames
- Instruction-level stepping through source code
- Source-aware breakpoints in interactive viewer
- Integration with IDEs for click-through debugging
- Support for other debug formats beyond DWARF
Next steps
- Use the Interactive trace viewer to navigate source-mapped traces
- Enable Performance profiling to see source locations in flamegraphs
- Learn about Transaction debugging workflows