1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! `dwat` is a library for accessing [DWARF](https://dwarfstd.org/)
//! (v4/v5) debuging information.
//!
//! The library is primarily focused on making type information from DWARF more
//! accessible, enabling quick lookups and enumeration of type related DWARF
//! information.
//!
//! `dwat` also implements formatting methods for pretty pretting structs/unions
//! similar to the [pahole](https://github.com/acmel/dwarves) utility and the
//! gdb `ptype` command.

pub mod format;
pub mod parse;
pub mod dwarf;

pub use dwarf::Dwarf;
pub use parse::*;

pub mod prelude {
    //! Re-exports commonly needed traits
    pub use super::parse::NamedType;
    pub use super::parse::InnerType;
    pub use super::parse::HasMembers;
}

/// Error type for parsing/loading DWARF information
#[derive(thiserror::Error, Debug)]
pub enum Error {
    // Fatal
    #[error("failed to load dwarf info from file")]
    DwarfLoadError(String),

    #[error("object failed to parse file")]
    ObjectError(#[from] object::Error),

    #[error("failed when attempting to get offset of a UnitHeader")]
    HeaderOffsetError,

    #[error("failed when attempting to get some CU")]
    CUError(String),

    #[error("failed when attempting to get some DIE")]
    DIEError(String),

    #[error("failed due to unimplemented functionality")]
    UnimplementedError(String),

    // Non-Fatal
    #[error("failure when attempting to find a Name Attribute")]
    NameAttributeNotFound,

    #[error("failure when attempting to find a Type Attribute")]
    TypeAttributeNotFound,

    #[error("failure when attempting to find a ByteSize Attribute")]
    ByteSizeAttributeNotFound,

    #[error("failure when attempting to find a BitSize Attribute")]
    BitSizeAttributeNotFound,

    #[error("failure when attempting to find a MemberLocation Attribute")]
    MemberLocationAttributeNotFound,

    #[error("failure when attempting to find an Alignment Attribute")]
    AlignmentAttributeNotFound,
}