Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change how bitfield masks are calculated #29

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 19 additions & 27 deletions src/dwarf/typereader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,33 +451,19 @@ impl<'elffile> DebugDataReader<'elffile> {
child_entry.offset().to_debug_info_offset(unit).unwrap().0;
if let Some(bit_offset) = get_bit_offset_attribute(child_entry) {
// Dwarf 2 / 3
if self.endian == Endianness::Big {
membertype = TypeInfo {
name: membertype.name.clone(),
unit_idx: membertype.unit_idx,
dbginfo_offset,
datatype: DwarfDataType::Bitfield {
basetype: Box::new(membertype),
bit_size: bit_size as u16,
bit_offset: bit_offset as u16,
},
};
} else {
// Endianness::Little
let type_size = membertype.get_size();
let type_size_bits = type_size * 8;
let bit_offset_le = type_size_bits - bit_offset - bit_size;
membertype = TypeInfo {
name: membertype.name.clone(),
unit_idx: membertype.unit_idx,
dbginfo_offset,
datatype: DwarfDataType::Bitfield {
basetype: Box::new(membertype),
bit_size: bit_size as u16,
bit_offset: bit_offset_le as u16,
},
};
}
let type_size = membertype.get_size();
let type_size_bits = type_size * 8;
let bit_offset_le = type_size_bits - bit_offset - bit_size;
membertype = TypeInfo {
name: membertype.name.clone(),
unit_idx: membertype.unit_idx,
dbginfo_offset,
datatype: DwarfDataType::Bitfield {
basetype: Box::new(membertype),
bit_size: bit_size as u16,
bit_offset: bit_offset_le as u16,
},
};
} else if let Some(mut data_bit_offset) =
get_data_bit_offset_attribute(child_entry)
{
Expand All @@ -491,6 +477,12 @@ impl<'elffile> DebugDataReader<'elffile> {
offset += (data_bit_offset / type_size_bits) * type_size;
data_bit_offset %= type_size_bits;
}
if self.endian == Endianness::Big {
// reverse the mask for big endian. Example
// In: type_size 32, offset: 5, size 4 -> 0000_0000_0000_0000_0000_0001_1110_0000
// Out: offset = 32 - 5 - 4 = 23 -> 0000_0111_1000_0000_0000_0000_0000_0000
data_bit_offset = type_size_bits - data_bit_offset - bit_size;
}
// these values should be independent of Endianness
membertype = TypeInfo {
name: membertype.name.clone(),
Expand Down