stackdump_trace/
error.rs

1//! All error types of the crate
2
3use std::rc::Rc;
4
5use gimli::EvaluationResult;
6use stackdump_core::device_memory::{MemoryReadError, MissingRegisterError};
7use thiserror::Error;
8
9use crate::{type_value_tree::VariableDataError, DefaultReader};
10
11/// The main error type during the tracing procedure
12#[allow(missing_docs)]
13#[derive(Error, Debug, Clone)]
14#[non_exhaustive]
15pub enum TraceError {
16    #[error("The elf file does not contain the required `{0}` section")]
17    MissingElfSection(String),
18    #[error("The elf file could not be read: {0}")]
19    ObjectReadError(#[from] addr2line::object::Error),
20    #[error("An IO error occured: {0}")]
21    IOError(Rc<std::io::Error>),
22    #[error("Some memory could not be read: {0}")]
23    MemoryReadError(#[from] MemoryReadError),
24    #[error("Some debug information could not be parsed: {0}")]
25    DebugParseError(#[from] gimli::Error),
26    #[error("An entry ({entry_tag} (@ .debug_info offset {entry_debug_info_offset:X?})) is missing an expected attribute: {attribute_name}")]
27    MissingAttribute {
28        entry_debug_info_offset: Option<u64>,
29        entry_tag: String,
30        attribute_name: String,
31    },
32    #[error("An attribute ({attribute_name}) has the wrong value type. Expected: {expected_type_name}, gotten: {gotten_value}")]
33    WrongAttributeValueType {
34        attribute_name: String,
35        expected_type_name: &'static str,
36        gotten_value: String,
37    },
38    #[error("The given debug info offset of {debug_info_offset:X} could not be linked with a known compilation unit")]
39    DebugInfoOffsetUnitNotFound { debug_info_offset: usize },
40    #[error("We got redirected to another unit for the second time while the first redirection should have worked")]
41    UnitNotFoundAgain,
42    #[error("The tag `{tag_name}` @`{entry_debug_info_offset:#X}` has not been implemented yet")]
43    TagNotImplemented {
44        tag_name: String,
45        entry_debug_info_offset: usize,
46    },
47    #[error("An operation is not implemented yet. Please open an issue at 'https://github.com/tweedegolf/stackdump': @ {file}:{line} => '{operation}'")]
48    OperationNotImplemented {
49        operation: String,
50        file: &'static str,
51        line: u32,
52    },
53    #[error("A child was expected for {entry_tag}, but it was not there")]
54    ExpectedChildNotPresent { entry_tag: String },
55    #[error("The frame base is not known yet")]
56    UnknownFrameBase,
57    #[error("The dwarf unit for a `pc` of {pc:#X} could not be found")]
58    DwarfUnitNotFound { pc: u64 },
59    #[error("A number could not be converted to another type")]
60    NumberConversionError,
61    #[error("Register {0:?} is required, but is not available in the device memory")]
62    MissingRegister(#[from] MissingRegisterError),
63    #[error("Memory was expected to be available at address {0:#X}, but wasn't")]
64    MissingMemory(u64),
65    #[error("{member_name} of {object_name} has unexpected tag {member_tag}")]
66    UnexpectedMemberTag {
67        object_name: String,
68        member_name: String,
69        member_tag: gimli::DwTag,
70    },
71    #[error(
72        "A pointer with the name {pointer_name} has an unexpected class value of {class_value}"
73    )]
74    UnexpectedPointerClass {
75        pointer_name: String,
76        class_value: gimli::DwAddr,
77    },
78    #[error(
79        "A required step of the location evaluation logic has not been implemented yet: {0:?}"
80    )]
81    LocationEvaluationStepNotImplemented(Rc<EvaluationResult<DefaultReader>>),
82    #[error("A variable couldn't be read: {0}")]
83    VariableDataError(#[from] VariableDataError),
84}
85
86impl From<std::io::Error> for TraceError {
87    fn from(e: std::io::Error) -> Self {
88        Self::IOError(Rc::new(e))
89    }
90}