cdefmt_parser/
lib.rs

1use gimli::{DwAte, DwTag, SectionId};
2
3mod dwarf;
4
5pub mod metadata;
6pub mod parser;
7pub mod r#type;
8
9pub use parser::Parser;
10
11#[derive(Debug, thiserror::Error)]
12pub enum Error {
13    #[error("Gimli error: {0}")]
14    Gimli(#[from] gimli::Error),
15    #[error("The provided elf is missing the '.cdefmt' section.")]
16    MissingSection,
17    #[error("DIE is missing attribute {0}")]
18    NoAttribute(gimli::DwAt),
19    #[error("Unable to find requested compilation unit ({0}).")]
20    NoCompilationUnit(String),
21    #[error("The log at id [{0}] has no null terminator!, error: {1}")]
22    NoNullTerm(usize, std::ffi::FromBytesUntilNulError),
23    #[error("The elf is missing the following section: {0:?}")]
24    NoSection(SectionId),
25    #[error("Unable to find requested type ({0}).")]
26    NoType(String),
27    #[error("Provided log at ID [{0}] metadata exceeds the '.cdefmt' section [{1}]")]
28    OutOfBounds(usize, usize),
29    #[error("Failed extract data from the '.cdefmt' section, error: {0}")]
30    SectionData(#[from] object::Error),
31    #[error("The log at id [{0}] is malformed, error: {1}")]
32    Utf8(usize, std::str::Utf8Error),
33    #[error("Encountered an unsupported base type, encoding: {0}, size: {1}")]
34    UnsupportedBaseType(DwAte, u64),
35    #[error("Encountered an unsupported pointer size: {0}")]
36    UnsupportedPointerSize(u64),
37    #[error("Encountered an unexpected tag: {0}")]
38    UnexpectedTag(DwTag),
39    #[error("Encountered an attribute with bad type")]
40    BadAttribute,
41    #[error("There is no DIE at the given offset: {0}")]
42    NoDIE(u64),
43    #[error("Unsupported schema version: {0}")]
44    SchemaVersion(u32),
45    #[error("{0}")]
46    Custom(&'static str),
47}
48
49pub type Result<T> = std::result::Result<T, Error>;