20 releases

0.11.1 Oct 4, 2024
0.11.0 Dec 13, 2023
0.10.4 Nov 15, 2022
0.10.2 Jul 25, 2022
0.4.0 Jun 13, 2021

#73 in Debugging

Download history 4432/week @ 2024-08-19 4460/week @ 2024-08-26 4943/week @ 2024-09-02 4222/week @ 2024-09-09 4870/week @ 2024-09-16 7133/week @ 2024-09-23 6046/week @ 2024-09-30 5613/week @ 2024-10-07 5535/week @ 2024-10-14 5098/week @ 2024-10-21 4231/week @ 2024-10-28 3727/week @ 2024-11-04 4047/week @ 2024-11-11 3422/week @ 2024-11-18 3721/week @ 2024-11-25 4557/week @ 2024-12-02

15,903 downloads per month
Used in 18 crates (4 directly)

MIT/Apache

115KB
2K SLoC

crates.io page docs.rs page

pdb-addr2line

Resolve addresses to function names, and to file name and line number information, with the help of a PDB file. Inline stacks are supported.

The API of this crate is intended to be similar to the API of the addr2line crate; the two Context APIs have comparable functionality. This crate is for PDB files whereas addr2line is for DWARF data (which is used in ELF and mach-o binaries, for example).

This crate also has a TypeFormatter API which can be used to get function signature strings independently from a Context.

To create a Context, use ContextPdbData.

The implementation makes use of the excellent pdb crate.

Example

use pdb_addr2line::pdb; // (this is a re-export of the pdb crate)

fn look_up_addresses<'s, S: pdb::Source<'s> + 's>(stream: S, addresses: &[u32]) -> std::result::Result<(), pdb_addr2line::Error> {
    let pdb = pdb::PDB::open(stream)?;
    let context_data = pdb_addr2line::ContextPdbData::try_from_pdb(pdb)?;
    let context = context_data.make_context()?;

    for address in addresses {
        if let Some(procedure_frames) = context.find_frames(*address)? {
            eprintln!("0x{:x} - {} frames:", address, procedure_frames.frames.len());
            for frame in procedure_frames.frames {
                let line_str = frame.line.map(|l| format!("{}", l));
                eprintln!(
                    "     {} at {}:{}",
                    frame.function.as_deref().unwrap_or("<unknown>"),
                    frame.file.as_deref().unwrap_or("??"),
                    line_str.as_deref().unwrap_or("??"),
                )
            }
        } else {
            eprintln!("{:x} - no frames found", address);
        }
    }
    Ok(())
}

Command-line usage

This repository also contains a CLI executable modelled after addr2line. You can install it using cargo install:

cargo install --examples pdb-addr2line

Here are some example uses:

$ curl -o dcomp.pdb -L "https://msdl.microsoft.com/download/symbols/dcomp.pdb/648B8DD0780A4E22FA7FA89B84633C231/dcomp.pdb"
$ pdb-addr2line --exe dcomp.pdb -fC 0x59aa0 0x52340 0x13498
Windows::UI::Composition::Compositor::Api::CreateScalarKeyFrameAnimation(Windows::UI::Composition::IScalarKeyFrameAnimation**)
??:?
std::map<unsigned int, Windows::UI::Composition::AnimationLoggingManager::ReferencedObject, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, Windows::UI::Composition::AnimationLoggingManager::ReferencedObject> > >::_Try_emplace<unsigned int const&>(unsigned int const&)
??:?
DirectComposition::CDxDevice::RemoveGuardRect(ID3D11Texture2D*)
??:?
$ curl -o mozglue.pdb -L "https://github.com/mstange/profiler-get-symbols/raw/master/fixtures/win64-ci/mozglue.pdb"
$ pdb-addr2line -e mozglue.pdb -psfi 0x3b9fb
mozilla::JSONWriter::StartCollection(char const*, char const*, mozilla::JSONWriter::CollectionStyle) at JSONWriter.h:318
 (inlined by) mozilla::JSONWriter::StartArrayProperty(char const*, mozilla::JSONWriter::CollectionStyle) at JSONWriter.h:417
 (inlined by) mozilla::JSONWriter::StartArrayElement(mozilla::JSONWriter::CollectionStyle) at JSONWriter.h:422
 (inlined by) mozilla::baseprofiler::AutoArraySchemaWriter::AutoArraySchemaWriter(mozilla::baseprofiler::SpliceableJSONWriter&, mozilla::baseprofiler::UniqueJSONStrings&) at ProfileBufferEntry.cpp:141
 (inlined by) mozilla::baseprofiler::WriteSample(mozilla::baseprofiler::SpliceableJSONWriter&, mozilla::baseprofiler::UniqueJSONStrings&, mozilla::baseprofiler::ProfileSample const&) at ProfileBufferEntry.cpp:361
 (inlined by) mozilla::baseprofiler::ProfileBuffer::StreamSamplesToJSON::<unnamed-tag>::operator()(mozilla::ProfileChunkedBuffer::Reader*) const at ProfileBufferEntry.cpp:809

Performance

pdb-addr2line optimizes for speed over memory by caching parsed information. The debug information about inlines, files and line numbers is parsed lazily where possible.

License

Licensed under either of

at your option.

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

~1.5–2MB
~42K SLoC