stackdump_trace/type_value_tree/
mod.rs

1use self::{value::Value, variable_type::VariableType};
2use stackdump_core::device_memory::MemoryReadError;
3use std::{fmt::Debug, ops::Range};
4use thiserror::Error;
5
6pub mod rendering;
7pub mod value;
8pub mod variable_type;
9
10pub type TypeValueNode<ADDR> = trees::Node<TypeValue<ADDR>>;
11pub type TypeValueTree<ADDR> = trees::Tree<TypeValue<ADDR>>;
12
13#[derive(Debug, Clone)]
14pub struct TypeValue<ADDR: funty::Integral> {
15    pub name: String,
16    pub variable_type: VariableType,
17    pub bit_range: Range<u64>,
18    pub variable_value: Result<Value<ADDR>, VariableDataError>,
19}
20
21impl<ADDR: funty::Integral> TypeValue<ADDR> {
22    pub fn bit_length(&self) -> u64 {
23        self.bit_range.end - self.bit_range.start
24    }
25
26    pub fn bit_range_usize(&self) -> Range<usize> {
27        self.bit_range.start as usize..self.bit_range.end as usize
28    }
29}
30
31impl<ADDR: funty::Integral> Default for TypeValue<ADDR> {
32    fn default() -> Self {
33        Self {
34            name: Default::default(),
35            variable_type: Default::default(),
36            bit_range: Default::default(),
37            variable_value: Err(VariableDataError::Unknown),
38        }
39    }
40}
41
42#[derive(Error, Debug, Clone, PartialEq)]
43pub enum VariableDataError {
44    #[error("Data has invalid size of {bits} bits")]
45    InvalidSize { bits: usize },
46    #[error("Unsupported base type {base_type}. Data: {data:X?}")]
47    UnsupportedBaseType {
48        base_type: gimli::DwAte,
49        data: bitvec::prelude::BitVec<u8, bitvec::order::Lsb0>,
50    },
51    #[error("Pointer data is invalid")]
52    InvalidPointerData,
53    #[error("nullptr")]
54    NullPointer,
55    #[error("Some memory could not be read: {0}")]
56    MemoryReadError(#[from] MemoryReadError),
57    #[error("Data not available")]
58    NoDataAvailable,
59    #[error("Data not available: {0}")]
60    NoDataAvailableAt(String),
61    #[error("Optimized away")]
62    OptimizedAway,
63    #[error("Required step of location evaluation logic not implemented: {0}")]
64    UnimplementedLocationEvaluationStep(String),
65    #[error("Unknown")]
66    Unknown,
67    #[error("An operation is not implemented yet. Please open an issue at 'https://github.com/tweedegolf/stackdump': @ {file}:{line} => '{operation}'")]
68    OperationNotImplemented {
69        operation: String,
70        file: &'static str,
71        line: u32,
72    },
73}