$ show gimli-rs/gimli
gimli is a Rust library for reading and writing the DWARF debugging format, used by debuggers, profilers, and binary analysis tools. It provides zero-copy, lazy parsing of all standard DWARF sections (e.g., .debug_info, .debug_line, .debug_frame, .debug_names) across versions 2–5, including split DWARF (DWO/DWP) and supplementary object files. The library is split into `read` and `write` modules, with a conversion pipeline to transform parsed debug data back into DWARF. It is designed to be `no_std` compatible (with alloc) and uses trait-based abstractions for readers/writers, allowing custom backing stores. Example CLI tools (dwarfdump, simple, convert) demonstrate real-world usage. The codebase is highly modular, with extensive unit tests, fuzzing, and benchmarks, and emphasizes correctness, performance, and cross-platform support (32/64-bit, little/big endian).
The LLM identified 4 files worth highlighting for reuse:
Implements LEB128 variable-length integer encoding and decoding (both unsigned and signed) with precomputed size functions. This is a standalone utility module with no internal crate dependencies, easily extractable for any binary format parsing. The code is clean, efficient, and handles edge cases correctly, demonstrating non-obvious optimization in size precomputation.
Provides Unicode case folding for the DWARF 5 name index, including a case-folding DJB hash function. The case folding data is generated from Unicode Standard 17.0.0 in `case_fold_data.rs`. This is a self-contained module that solves a recurring problem (case-insensitive string matching in debug info) and can be reused in any DWARF tool or other context requiring case folding.
Implements a zero-copy reader (`EndianReader`) over byte slices with compile-time or run-time endianness, providing methods for reading integers, offsets, LEB128, and addresses. It relies on the `Endianity` trait from `src/endianity.rs`, both of which are small and self-contained. This pattern is reusable for any binary format parsing that needs endian-aware, slice-based reading, and demonstrates a clean abstraction over endianness and backing storage.
Provides a high-level builder for DWARF location and value expressions (`Expression` and `Operation`), with size calculation, serialization, and a conversion module that transforms parsed read expressions into write form. This is a non-trivial pattern for round-trip DWARF manipulation, handling many opcodes, address sizes, and version variants. The code is well-structured and could be extracted to support expression generation in other DWARF tools.