Skip to content

Commit

Permalink
Support reading information from PDB files
Browse files Browse the repository at this point in the history
The new option '--pdbfile' can be used instead of '--elffile' in order to
read address and data type information from a PDB file.
This supports the "virtual ECU" use case, where some parts of a microcontroller
application are built on Windows and run inside a simulation environment.
  • Loading branch information
DanielT committed Dec 5, 2024
1 parent 3cc9e35 commit d4a2c73
Show file tree
Hide file tree
Showing 33 changed files with 2,414 additions and 777 deletions.
68 changes: 49 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ regex = "1"
indexmap = "2.2.0"
fxhash = "0.2.1"
argfile = { version ="0.2.0", features=["response"]}
pdb2 = "0.9.2"

[dev-dependencies]
tempfile = "3.13"
Expand Down
81 changes: 49 additions & 32 deletions src/datatype.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,53 @@
use crate::dwarf::{DwarfDataType, TypeInfo};
use crate::debuginfo::{DbgDataType, TypeInfo};
use a2lfile::DataType;

// map the datatypes from the elf_info to a2l datatypes
// the only really relevant cases are for the integer, floating point and enum types
// all other types cannot be sensibly measured / calibrated anyway
pub(crate) fn get_a2l_datatype(typeinfo: &TypeInfo) -> DataType {
match &typeinfo.datatype {
DwarfDataType::Uint8 => DataType::Ubyte,
DwarfDataType::Uint16 => DataType::Uword,
DwarfDataType::Uint32 => DataType::Ulong,
DwarfDataType::Uint64 => DataType::AUint64,
DwarfDataType::Sint8 => DataType::Sbyte,
DwarfDataType::Sint16 => DataType::Sword,
DwarfDataType::Sint32 => DataType::Slong,
DwarfDataType::Sint64 => DataType::AInt64,
DwarfDataType::Float => DataType::Float32Ieee,
DwarfDataType::Double => DataType::Float64Ieee,
DwarfDataType::Bitfield { basetype, .. } => get_a2l_datatype(basetype),
DwarfDataType::Pointer(size, _) => {
DbgDataType::Uint8 => DataType::Ubyte,
DbgDataType::Uint16 => DataType::Uword,
DbgDataType::Uint32 => DataType::Ulong,
DbgDataType::Uint64 => DataType::AUint64,
DbgDataType::Sint8 => DataType::Sbyte,
DbgDataType::Sint16 => DataType::Sword,
DbgDataType::Sint32 => DataType::Slong,
DbgDataType::Sint64 => DataType::AInt64,
DbgDataType::Float => DataType::Float32Ieee,
DbgDataType::Double => DataType::Float64Ieee,
DbgDataType::Bitfield { basetype, .. } => get_a2l_datatype(basetype),
DbgDataType::Pointer(size, _) => {
if *size == 8 {
DataType::AUint64
} else {
DataType::Ulong
}
}
DwarfDataType::Enum { size, .. } | DwarfDataType::Other(size) => match *size {
DbgDataType::Enum { size, signed, .. } => {
if *signed {
match *size {
8 => DataType::AInt64,
4 => DataType::Slong,
2 => DataType::Sword,
_ => DataType::Sbyte,
}
} else {
match *size {
8 => DataType::AUint64,
4 => DataType::Ulong,
2 => DataType::Uword,
_ => DataType::Ubyte,
}
}
}
DbgDataType::Other(size) => match *size {
8 => DataType::AUint64,
4 => DataType::Ulong,
2 => DataType::Uword,
_ => DataType::Ubyte,
},
DwarfDataType::Array { arraytype, .. } => get_a2l_datatype(arraytype),
DbgDataType::Array { arraytype, .. } => get_a2l_datatype(arraytype),
_ => DataType::Ubyte,
}
}
Expand All @@ -41,36 +58,36 @@ pub(crate) fn get_type_limits(
default_upper: f64,
) -> (f64, f64) {
let (new_lower_limit, new_upper_limit) = match &typeinfo.datatype {
DwarfDataType::Array { arraytype, .. } => {
DbgDataType::Array { arraytype, .. } => {
get_type_limits(arraytype, default_lower, default_upper)
}
DwarfDataType::Bitfield {
DbgDataType::Bitfield {
bit_size, basetype, ..
} => {
let raw_range: u64 = 1 << bit_size;
match &basetype.datatype {
DwarfDataType::Sint8
| DwarfDataType::Sint16
| DwarfDataType::Sint32
| DwarfDataType::Sint64 => {
DbgDataType::Sint8
| DbgDataType::Sint16
| DbgDataType::Sint32
| DbgDataType::Sint64 => {
let lower = -((raw_range / 2) as f64);
let upper = (raw_range / 2) as f64;
(lower, upper)
}
_ => (0f64, raw_range as f64),
}
}
DwarfDataType::Double => (f64::MIN, f64::MAX),
DwarfDataType::Float => (f64::from(f32::MIN), f64::from(f32::MAX)),
DwarfDataType::Uint8 => (f64::from(u8::MIN), f64::from(u8::MAX)),
DwarfDataType::Uint16 => (f64::from(u16::MIN), f64::from(u16::MAX)),
DwarfDataType::Uint32 => (f64::from(u32::MIN), f64::from(u32::MAX)),
DwarfDataType::Uint64 => (u64::MIN as f64, u64::MAX as f64),
DwarfDataType::Sint8 => (f64::from(i8::MIN), f64::from(i8::MAX)),
DwarfDataType::Sint16 => (f64::from(i16::MIN), f64::from(i16::MAX)),
DwarfDataType::Sint32 => (f64::from(i32::MIN), f64::from(i32::MAX)),
DwarfDataType::Sint64 => (i64::MIN as f64, i64::MAX as f64),
DwarfDataType::Enum { enumerators, .. } => {
DbgDataType::Double => (f64::MIN, f64::MAX),
DbgDataType::Float => (f64::from(f32::MIN), f64::from(f32::MAX)),
DbgDataType::Uint8 => (f64::from(u8::MIN), f64::from(u8::MAX)),
DbgDataType::Uint16 => (f64::from(u16::MIN), f64::from(u16::MAX)),
DbgDataType::Uint32 => (f64::from(u32::MIN), f64::from(u32::MAX)),
DbgDataType::Uint64 => (u64::MIN as f64, u64::MAX as f64),
DbgDataType::Sint8 => (f64::from(i8::MIN), f64::from(i8::MAX)),
DbgDataType::Sint16 => (f64::from(i16::MIN), f64::from(i16::MAX)),
DbgDataType::Sint32 => (f64::from(i32::MIN), f64::from(i32::MAX)),
DbgDataType::Sint64 => (i64::MIN as f64, i64::MAX as f64),
DbgDataType::Enum { enumerators, .. } => {
let lower = enumerators.iter().map(|val| val.1).min().unwrap_or(0) as f64;
let upper = enumerators.iter().map(|val| val.1).max().unwrap_or(0) as f64;
(lower, upper)
Expand Down
File renamed without changes.
Loading

0 comments on commit d4a2c73

Please sign in to comment.