Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Debugging Techniques

When transpilation produces incorrect output or the pipeline fails, systematic debugging pinpoints the issue faster than guesswork. This chapter provides an overview of the debugging toolkit.

Debugging Workflow

┌────────────────┐
│ Observe failure │
└───────┬────────┘
        │
        ▼
┌────────────────┐     ┌────────────────┐
│ Check logs     │────>│ Found error?   │──Yes──> Fix
│ (RUST_LOG)     │     │                │
└───────┬────────┘     └───────┬────────┘
        │                      │ No
        ▼                      ▼
┌────────────────┐     ┌────────────────┐
│ Compare traces │────>│ Found diff?    │──Yes──> Fix
│ (renacer)      │     │                │
└───────┬────────┘     └───────┬────────┘
        │                      │ No
        ▼                      ▼
┌────────────────┐     ┌────────────────┐
│ Inspect state  │────>│ Found corrupt  │──Yes──> Fix
│ (.batuta/)     │     │ state?         │
└────────────────┘     └────────────────┘

Available Tools

ToolPurposeWhen to Use
RUST_LOGStructured loggingFirst step for any failure
renacerSyscall tracing and diffBehavioral differences between original and transpiled
.batuta/ statePipeline phase inspectionPipeline stuck or producing wrong output
gdb / lldbStep-through debuggingCrash investigation, segfaults in unsafe code
cargo expandMacro expansionUnexpected behavior from macros

Quick Diagnostic Commands

# Enable verbose logging for a specific module
RUST_LOG=batuta::pipeline=debug batuta transpile --source ./src

# Trace a run and save output
renacer trace --output trace.json -- batuta validate ./rust_out

# Inspect pipeline state
ls -la .batuta/
cat .batuta/pipeline_state.json

# Check the last error
batuta status --verbose

Environment Variables for Debug Output

VariableEffectModule
RUST_LOGControls log verbosityAll
REALIZE_TRACEEnables forward pass tracingrealizar inference
REALIZE_DEBUGEnables APR loading debug outputrealizar model loading
REALIZAR_DEBUG_FORWARDGGUF forward pass tracingrealizar GGUF
APR_TRACE_LAYERSPer-layer inference tracingrealizar GGUF
CPU_DEBUGCPU inference debug outputrealizar GGUF cached

Binary Debugging

For crashes or memory corruption (common in FFI migrations):

# Build with debug symbols in release mode
cargo build --release
# (debug symbols are included by default in Cargo.toml debug = true)

# Run under gdb
gdb ./target/release/batuta
(gdb) run transpile --source ./src
(gdb) bt   # backtrace on crash

See Log Analysis, Trace Comparison, and State Inspection for detailed guidance on each technique.


Navigate: Table of Contents