16 releases

0.8.0 Jun 8, 2022
0.7.0 Mar 2, 2021
0.6.0 Mar 18, 2020
0.5.0 Jun 28, 2019
0.1.3 Mar 12, 2017

#102 in Debugging

Download history 4483/week @ 2024-06-22 5922/week @ 2024-06-29 5977/week @ 2024-07-06 6079/week @ 2024-07-13 7245/week @ 2024-07-20 7889/week @ 2024-07-27 7058/week @ 2024-08-03 8092/week @ 2024-08-10 6038/week @ 2024-08-17 6325/week @ 2024-08-24 7353/week @ 2024-08-31 6315/week @ 2024-09-07 6870/week @ 2024-09-14 9378/week @ 2024-09-21 8119/week @ 2024-09-28 6966/week @ 2024-10-05

32,393 downloads per month
Used in 37 crates (18 directly)

MIT/Apache

475KB
9K SLoC

pdb

Build Status

This is a Rust library that parses Microsoft PDB (Program Database) files. These files contain debugging information produced by most compilers that target Windows, including information about symbols, types, modules, and so on.

The PDB format is not documented per sé, but Microsoft has published information in the form of C++ code relating to its use. The PDB format is full of... history, including support for debugging 16-bit executables, COBOL user-defined types, and myriad other features. pdb does not understand everything about the PDB format, but it does cover enough to be useful for typical programs compiled today.

Documentation on docs.rs.

Design

pdb's design objectives are similar to gimli:

  • pdb works with the original data as it's formatted on-disk as long as possible.

  • pdb parses only what you ask.

  • pdb can read PDBs anywhere. There's no dependency on Windows, on the DIA SDK, or on the target's native byte ordering.

Usage Example

use pdb::FallibleIterator;
use std::fs::File;

fn main() -> pdb::Result<()> {
    let file = File::open("fixtures/self/foo.pdb")?;
    let mut pdb = pdb::PDB::open(file)?;

    let symbol_table = pdb.global_symbols()?;
    let address_map = pdb.address_map()?;

    let mut symbols = symbol_table.iter();
    while let Some(symbol) = symbols.next()? {
        match symbol.parse() {
            Ok(pdb::SymbolData::Public(data)) if data.function => {
                // we found the location of a function!
                let rva = data.offset.to_rva(&address_map).unwrap_or_default
                println!("{} is {}", rva, data.name);
            }
            _ => {}
        }
    }

    Ok(())
}

Example Programs

Run with cargo run --release --example <name>:

  • pdb_symbols is a toy program that prints the name and location of every function and data value defined in the symbol table.

  • pdb2hpp is a somewhat larger program that prints an approximation of a C++ header file for a requested type given only a PDB.

  • pdb_lines outputs line number information for every symbol in every module contained in a PDB.

Real-world examples:

  • mstange/pdb-addr2line resolves addresses to function names, and to file name and line number information, with the help of a PDB file. Inline stacks are supported.

  • getsentry/symbolic is a high-level symbolication library supporting most common debug file formats, demangling, and more.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~410KB