Skip to content

Commit

Permalink
Implement BitOr for DwEhPe
Browse files Browse the repository at this point in the history
Unlike other DWARF constants, these values are subfields
that need combining.
  • Loading branch information
philipc committed Apr 10, 2024
1 parent 1aa8a0a commit 5c2f5ae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
16 changes: 12 additions & 4 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#![allow(non_upper_case_globals)]
#![allow(missing_docs)]

use core::fmt;
use core::{fmt, ops};

// The `dw!` macro turns this:
//
Expand Down Expand Up @@ -1342,6 +1342,14 @@ const DW_EH_PE_FORMAT_MASK: u8 = 0b0000_1111;
// Ignores indirection bit.
const DW_EH_PE_APPLICATION_MASK: u8 = 0b0111_0000;

impl ops::BitOr for DwEhPe {
type Output = DwEhPe;

fn bitor(self, rhs: DwEhPe) -> DwEhPe {
DwEhPe(self.0 | rhs.0)
}
}

impl DwEhPe {
/// Get the pointer encoding's format.
#[inline]
Expand Down Expand Up @@ -1397,13 +1405,13 @@ mod tests {

#[test]
fn test_dw_eh_pe_format() {
let encoding = DwEhPe(DW_EH_PE_pcrel.0 | DW_EH_PE_uleb128.0);
let encoding = DW_EH_PE_pcrel | DW_EH_PE_uleb128;
assert_eq!(encoding.format(), DW_EH_PE_uleb128);
}

#[test]
fn test_dw_eh_pe_application() {
let encoding = DwEhPe(DW_EH_PE_pcrel.0 | DW_EH_PE_uleb128.0);
let encoding = DW_EH_PE_pcrel | DW_EH_PE_uleb128;
assert_eq!(encoding.application(), DW_EH_PE_pcrel);
}

Expand All @@ -1415,7 +1423,7 @@ mod tests {

#[test]
fn test_dw_eh_pe_is_valid_encoding_ok() {
let encoding = DwEhPe(DW_EH_PE_uleb128.0 | DW_EH_PE_pcrel.0);
let encoding = DW_EH_PE_uleb128 | DW_EH_PE_pcrel;
assert!(encoding.is_valid_encoding());
assert!(DW_EH_PE_absptr.is_valid_encoding());
assert!(DW_EH_PE_omit.is_valid_encoding());
Expand Down
32 changes: 11 additions & 21 deletions src/read/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7168,9 +7168,8 @@ mod tests {
cie.format = Format::Dwarf32;
cie.version = 1;
cie.augmentation = Some(Augmentation::default());
cie.augmentation.as_mut().unwrap().lsda = Some(constants::DwEhPe(
constants::DW_EH_PE_funcrel.0 | constants::DW_EH_PE_absptr.0,
));
cie.augmentation.as_mut().unwrap().lsda =
Some(constants::DW_EH_PE_funcrel | constants::DW_EH_PE_absptr);

let mut fde = FrameDescriptionEntry {
offset: 0,
Expand Down Expand Up @@ -7369,8 +7368,7 @@ mod tests {
#[test]
fn test_parse_pointer_encoding_ok() {
use crate::endianity::NativeEndian;
let expected =
constants::DwEhPe(constants::DW_EH_PE_uleb128.0 | constants::DW_EH_PE_pcrel.0);
let expected = constants::DW_EH_PE_uleb128 | constants::DW_EH_PE_pcrel;
let input = [expected.0, 1, 2, 3, 4];
let input = &mut EndianSlice::new(&input, NativeEndian);
assert_eq!(parse_pointer_encoding(input), Ok(expected));
Expand Down Expand Up @@ -7602,8 +7600,7 @@ mod tests {

#[test]
fn test_parse_encoded_pointer_uleb128() {
let encoding =
constants::DwEhPe(constants::DW_EH_PE_absptr.0 | constants::DW_EH_PE_uleb128.0);
let encoding = constants::DW_EH_PE_absptr | constants::DW_EH_PE_uleb128;
let expected_rest = [1, 2, 3, 4];

let input = Section::with_endian(Endian::Little)
Expand All @@ -7628,8 +7625,7 @@ mod tests {

#[test]
fn test_parse_encoded_pointer_udata2() {
let encoding =
constants::DwEhPe(constants::DW_EH_PE_absptr.0 | constants::DW_EH_PE_udata2.0);
let encoding = constants::DW_EH_PE_absptr | constants::DW_EH_PE_udata2;
let expected_rest = [1, 2, 3, 4];

let input = Section::with_endian(Endian::Little)
Expand All @@ -7654,8 +7650,7 @@ mod tests {

#[test]
fn test_parse_encoded_pointer_udata4() {
let encoding =
constants::DwEhPe(constants::DW_EH_PE_absptr.0 | constants::DW_EH_PE_udata4.0);
let encoding = constants::DW_EH_PE_absptr | constants::DW_EH_PE_udata4;
let expected_rest = [1, 2, 3, 4];

let input = Section::with_endian(Endian::Little)
Expand All @@ -7680,8 +7675,7 @@ mod tests {

#[test]
fn test_parse_encoded_pointer_udata8() {
let encoding =
constants::DwEhPe(constants::DW_EH_PE_absptr.0 | constants::DW_EH_PE_udata8.0);
let encoding = constants::DW_EH_PE_absptr | constants::DW_EH_PE_udata8;
let expected_rest = [1, 2, 3, 4];

let input = Section::with_endian(Endian::Little)
Expand All @@ -7706,8 +7700,7 @@ mod tests {

#[test]
fn test_parse_encoded_pointer_sleb128() {
let encoding =
constants::DwEhPe(constants::DW_EH_PE_textrel.0 | constants::DW_EH_PE_sleb128.0);
let encoding = constants::DW_EH_PE_textrel | constants::DW_EH_PE_sleb128;
let expected_rest = [1, 2, 3, 4];

let input = Section::with_endian(Endian::Little)
Expand All @@ -7732,8 +7725,7 @@ mod tests {

#[test]
fn test_parse_encoded_pointer_sdata2() {
let encoding =
constants::DwEhPe(constants::DW_EH_PE_absptr.0 | constants::DW_EH_PE_sdata2.0);
let encoding = constants::DW_EH_PE_absptr | constants::DW_EH_PE_sdata2;
let expected_rest = [1, 2, 3, 4];
let expected = 0x111_i16;

Expand All @@ -7759,8 +7751,7 @@ mod tests {

#[test]
fn test_parse_encoded_pointer_sdata4() {
let encoding =
constants::DwEhPe(constants::DW_EH_PE_absptr.0 | constants::DW_EH_PE_sdata4.0);
let encoding = constants::DW_EH_PE_absptr | constants::DW_EH_PE_sdata4;
let expected_rest = [1, 2, 3, 4];
let expected = 0x111_1111_i32;

Expand All @@ -7786,8 +7777,7 @@ mod tests {

#[test]
fn test_parse_encoded_pointer_sdata8() {
let encoding =
constants::DwEhPe(constants::DW_EH_PE_absptr.0 | constants::DW_EH_PE_sdata8.0);
let encoding = constants::DW_EH_PE_absptr | constants::DW_EH_PE_sdata8;
let expected_rest = [1, 2, 3, 4];
let expected = -0x11_1111_1222_2222_i64;

Expand Down
14 changes: 5 additions & 9 deletions src/write/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,16 +913,12 @@ mod tests {
frames.add_fde(cie2_id, fde4.clone());

let mut cie3 = CommonInformationEntry::new(encoding, 1, 8, X86_64::RA);
cie3.fde_address_encoding = constants::DwEhPe(
constants::DW_EH_PE_pcrel.0 | constants::DW_EH_PE_sdata4.0,
);
cie3.lsda_encoding = Some(constants::DwEhPe(
constants::DW_EH_PE_pcrel.0 | constants::DW_EH_PE_sdata4.0,
));
cie3.fde_address_encoding =
constants::DW_EH_PE_pcrel | constants::DW_EH_PE_sdata4;
cie3.lsda_encoding =
Some(constants::DW_EH_PE_pcrel | constants::DW_EH_PE_sdata4);
cie3.personality = Some((
constants::DwEhPe(
constants::DW_EH_PE_pcrel.0 | constants::DW_EH_PE_sdata4.0,
),
constants::DW_EH_PE_pcrel | constants::DW_EH_PE_sdata4,
Address::Constant(0x1235),
));
cie3.signal_trampoline = true;
Expand Down

0 comments on commit 5c2f5ae

Please # to comment.