Skip to main content

ud_debug/
lib.rs

1//! Debug-info reader: turns `.debug_info` (DWARF) into typed function
2//! signatures the decompiler can attach to its `FnDecl` AST nodes.
3//!
4//! v0 scope: x86-64 ELF, DWARF 4/5. Subprogram DIEs yield names,
5//! addresses, and parameter / return types. Type recovery covers
6//! DW_TAG_base_type (primitives) and DW_TAG_pointer_type (recursively
7//! resolved); other tags produce [`ud_ast::Type::Unknown`].
8//!
9//! Pluggable parsers for PDB, stabs, and Mach-O `.dSYM` will land in
10//! this same crate as additional modules.
11
12#![allow(clippy::cast_possible_truncation)]
13
14mod dwarf;
15
16pub use dwarf::{DebugError, DebugFunction};
17
18use std::collections::HashMap;
19
20use ud_format::elf::Elf64File;
21
22/// Read every supported debug-info section from `elf` and return a
23/// map keyed by function start address. Empty when no debug info is
24/// present.
25///
26/// Today this only consults `.debug_info` (DWARF). It will grow as
27/// other formats come online.
28pub fn read_debug_info(elf: &Elf64File) -> Result<HashMap<u64, DebugFunction>, DebugError> {
29    let mut by_addr = HashMap::new();
30    for f in dwarf::read_subprograms(elf)? {
31        by_addr.insert(f.addr, f);
32    }
33    Ok(by_addr)
34}