This guide shows how to compile Soroban contracts with debug symbols for use with erst's source mapping feature.
- Rust toolchain
- Soroban CLI
- A Soroban contract project
Add or modify the profile settings in your contract's Cargo.toml:
[profile.release]
debug = true
debug-assertions = false
overflow-checks = false
lto = false
panic = "abort"
codegen-units = 1
opt-level = "z"# Build the contract with debug symbols
cargo build --target wasm32-unknown-unknown --release
# Or use soroban CLI
soroban contract buildCheck if your WASM contains debug symbols:
# Install wasm-objdump if not already installed
cargo install wasmprinter
# Check for debug sections
wasm-objdump -h target/wasm32-unknown-unknown/release/your_contract.wasm | grep debugYou should see sections like:
.debug_info.debug_line.debug_str.debug_abbrev
# Get the WASM file
cp target/wasm32-unknown-unknown/release/your_contract.wasm contract.wasm
# Convert to base64 for erst
base64 -w 0 contract.wasm > contract.wasm.b64Here's a simple contract that demonstrates source mapping:
#![no_std]
use soroban_sdk::{contract, contractimpl, Env, Symbol, symbol_short};
#[contract]
pub struct TokenContract;
#[contractimpl]
impl TokenContract {
pub fn transfer(env: Env, from: Symbol, to: Symbol, amount: i128) -> Result<(), Symbol> {
// Line 12: Check balance
let balance = Self::get_balance(&env, &from);
// Line 15: This line might fail - insufficient balance
if balance < amount {
return Err(symbol_short!("insufficient"));
}
// Line 20: Update balances
Self::set_balance(&env, &from, balance - amount);
let to_balance = Self::get_balance(&env, &to);
Self::set_balance(&env, &to, to_balance + amount);
Ok(())
}
fn get_balance(env: &Env, account: &Symbol) -> i128 {
env.storage().instance().get(account).unwrap_or(0)
}
fn set_balance(env: &Env, account: &Symbol, balance: i128) {
env.storage().instance().set(account, &balance);
}
}Once you have a contract with debug symbols:
- Deploy and execute the contract on Stellar
- If it fails, get the transaction hash
- Use
erst debug <transaction-hash>with the WASM file
The output will show:
Failed at line 15 in src/lib.rs
If erst reports no debug symbols:
- Verify debug symbols are present:
wasm-objdump -h contract.wasm | grep debug - Check Cargo.toml profile settings
- Ensure you're using the release build with debug=true
Debug symbols significantly increase WASM size:
- Without debug: ~50KB
- With debug: ~500KB+
This is normal and expected for development builds.
Some optimizations can make source mapping less accurate:
- Set
lto = falsefor better mapping - Use
opt-level = "z"instead of "s" for size optimization - Consider
codegen-units = 1for better debug info