Skip to content

Commit

Permalink
Merge pull request #392 from philipc/offsets
Browse files Browse the repository at this point in the history
Change default Offset to R::Offset
  • Loading branch information
fitzgen authored Feb 22, 2019
2 parents 2c7fcfe + 04bce75 commit 7c1b9e7
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 177 deletions.
4 changes: 2 additions & 2 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,15 +652,15 @@ mod cfi {
});
}

fn instrs_len<R: Reader>(fde: &FrameDescriptionEntry<EhFrame<R>, R, R::Offset>) -> usize {
fn instrs_len<R: Reader>(fde: &FrameDescriptionEntry<EhFrame<R>, R>) -> usize {
fde.instructions()
.fold(0, |count, _| count + 1)
.expect("fold over instructions OK")
}

fn get_fde_with_longest_cfi_instructions<R: Reader>(
eh_frame: &EhFrame<R>,
) -> FrameDescriptionEntry<EhFrame<R>, R, R::Offset> {
) -> FrameDescriptionEntry<EhFrame<R>, R> {
let bases = BaseAddresses::default()
.set_eh_frame(0)
.set_got(0)
Expand Down
2 changes: 1 addition & 1 deletion examples/dwarf-validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ fn validate_info<W, R>(
last_offset = u.offset().0 + u.length_including_self();
units.push(u);
}
let process_unit = |unit: CompilationUnitHeader<R, R::Offset>| -> UnitSummary {
let process_unit = |unit: CompilationUnitHeader<R>| -> UnitSummary {
let mut ret = UnitSummary {
internally_valid: false,
offset: unit.offset(),
Expand Down
63 changes: 31 additions & 32 deletions examples/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,44 +867,43 @@ where
writeln!(&mut BufWriter::new(out.lock()), "\n.debug_info")?;

let units = dwarf.units().collect::<Vec<_>>().unwrap();
let process_unit =
|header: CompilationUnitHeader<R, R::Offset>, buf: &mut Vec<u8>| -> Result<()> {
writeln!(
buf,
"\nUNIT<header overall offset = 0x{:08x}>:",
header.offset().0,
)?;

let unit = match dwarf.unit(header) {
Ok(unit) => unit,
Err(err) => {
writeln!(
buf,
"Failed to parse unit root entry: {}",
error::Error::description(&err)
)?;
return Ok(());
}
};
let process_unit = |header: CompilationUnitHeader<R>, buf: &mut Vec<u8>| -> Result<()> {
writeln!(
buf,
"\nUNIT<header overall offset = 0x{:08x}>:",
header.offset().0,
)?;

let entries_result = dump_entries(buf, unit, dwarf, flags);
if let Err(err) = entries_result {
let unit = match dwarf.unit(header) {
Ok(unit) => unit,
Err(err) => {
writeln!(
buf,
"Failed to dump entries: {}",
"Failed to parse unit root entry: {}",
error::Error::description(&err)
)?;
return Ok(());
}
if !flags
.match_units
.as_ref()
.map(|r| r.is_match(&buf))
.unwrap_or(true)
{
buf.clear();
}
Ok(())
};

let entries_result = dump_entries(buf, unit, dwarf, flags);
if let Err(err) = entries_result {
writeln!(
buf,
"Failed to dump entries: {}",
error::Error::description(&err)
)?;
}
if !flags
.match_units
.as_ref()
.map(|r| r.is_match(&buf))
.unwrap_or(true)
{
buf.clear();
}
Ok(())
};
// Don't use more than 16 cores even if available. No point in soaking hundreds
// of cores if you happen to have them.
parallel_output(16, units, process_unit)
Expand Down Expand Up @@ -1310,7 +1309,7 @@ fn dump_exprloc<R: Reader, W: Write>(
fn dump_op<R: Reader, W: Write>(
w: &mut W,
dwop: gimli::DwOp,
op: gimli::Operation<R, R::Offset>,
op: gimli::Operation<R>,
newpc: &R,
) -> Result<()> {
write!(w, "{}", dwop)?;
Expand Down
2 changes: 1 addition & 1 deletion src/read/abbrev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl AttributeSpecification {
///
/// Note that because some attributes are variably sized, the size cannot
/// always be known without parsing, in which case we return `None`.
pub fn size<R: Reader>(&self, header: &UnitHeader<R, R::Offset>) -> Option<usize> {
pub fn size<R: Reader>(&self, header: &UnitHeader<R>) -> Option<usize> {
match self.form {
constants::DW_FORM_addr => Some(header.address_size() as usize),

Expand Down
42 changes: 20 additions & 22 deletions src/read/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,9 @@ impl<'a, R: Reader + 'a> EhHdrTable<'a, R> {
bases: &BaseAddresses,
frame: EhFrame<R>,
cb: F,
) -> Result<FrameDescriptionEntry<EhFrame<R>, R, R::Offset>>
) -> Result<FrameDescriptionEntry<EhFrame<R>, R>>
where
F: FnMut(
EhFrameOffset<R::Offset>,
) -> Result<CommonInformationEntry<EhFrame<R>, R, R::Offset>>,
F: FnMut(EhFrameOffset<R::Offset>) -> Result<CommonInformationEntry<EhFrame<R>, R>>,
{
let fdeptr = self.lookup(address, bases)?;
let fdeptr = match fdeptr {
Expand Down Expand Up @@ -534,7 +532,7 @@ pub trait UnwindSection<R: Reader>: Clone + Debug + _UnwindSectionPrivate<R> {
&self,
bases: &'bases BaseAddresses,
offset: Self::Offset,
) -> Result<CommonInformationEntry<Self, R, R::Offset>> {
) -> Result<CommonInformationEntry<Self, R>> {
let offset = UnwindOffset::into(offset);
let input = &mut self.section().clone();
input.skip(offset)?;
Expand Down Expand Up @@ -1012,7 +1010,7 @@ where
Section: UnwindSection<R>,
{
/// This CFI entry is a `CommonInformationEntry`.
Cie(CommonInformationEntry<Section, R, R::Offset>),
Cie(CommonInformationEntry<Section, R>),
/// This CFI entry is a `FrameDescriptionEntry`, however fully parsing it
/// requires parsing its CIE first, so it is left in a partially parsed
/// state.
Expand Down Expand Up @@ -1205,7 +1203,7 @@ impl AugmentationData {
/// > Frame Description Entries. There is at least one CIE in every non-empty
/// > `.debug_frame` section.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CommonInformationEntry<Section, R, Offset = usize>
pub struct CommonInformationEntry<Section, R, Offset = <R as Reader>::Offset>
where
R: Reader<Offset = Offset>,
Offset: ReaderOffset,
Expand Down Expand Up @@ -1466,9 +1464,9 @@ where
/// You must provide a function get its associated CIE (either by parsing it
/// on demand, or looking it up in some table mapping offsets to CIEs that
/// you've already parsed, etc.)
pub fn parse<F>(&self, get_cie: F) -> Result<FrameDescriptionEntry<Section, R, R::Offset>>
pub fn parse<F>(&self, get_cie: F) -> Result<FrameDescriptionEntry<Section, R>>
where
F: FnMut(Section::Offset) -> Result<CommonInformationEntry<Section, R, R::Offset>>,
F: FnMut(Section::Offset) -> Result<CommonInformationEntry<Section, R>>,
{
FrameDescriptionEntry::parse_rest(
self.offset,
Expand All @@ -1485,7 +1483,7 @@ where

/// A `FrameDescriptionEntry` is a set of CFA instructions for an address range.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FrameDescriptionEntry<Section, R, Offset = usize>
pub struct FrameDescriptionEntry<Section, R, Offset = <R as Reader>::Offset>
where
R: Reader<Offset = Offset>,
Offset: ReaderOffset,
Expand Down Expand Up @@ -1547,7 +1545,7 @@ where
mut get_cie: F,
) -> Result<FrameDescriptionEntry<Section, R, Offset>>
where
F: FnMut(Section::Offset) -> Result<CommonInformationEntry<Section, R, R::Offset>>,
F: FnMut(Section::Offset) -> Result<CommonInformationEntry<Section, R>>,
{
{
let mut func = bases.eh_frame.func.borrow_mut();
Expand Down Expand Up @@ -1595,7 +1593,7 @@ where

fn parse_addresses(
input: &mut R,
cie: &CommonInformationEntry<Section, R, R::Offset>,
cie: &CommonInformationEntry<Section, R>,
bases: &BaseAddresses,
section: &Section,
) -> Result<(u64, u64)> {
Expand Down Expand Up @@ -1648,7 +1646,7 @@ where
}

/// Get a reference to this FDE's CIE.
pub fn cie(&self) -> &CommonInformationEntry<Section, R, R::Offset> {
pub fn cie(&self) -> &CommonInformationEntry<Section, R> {
&self.cie
}

Expand Down Expand Up @@ -1751,7 +1749,7 @@ where
/// /// Call `f` on each row in the given FDE's unwind table.
/// fn each_unwind_row<F>(
/// &mut self,
/// fde: &gimli::FrameDescriptionEntry<S, R, R::Offset>,
/// fde: &gimli::FrameDescriptionEntry<S, R>,
/// mut f: F,
/// ) -> gimli::Result<()>
/// where
Expand Down Expand Up @@ -1922,7 +1920,7 @@ where
/// `InitializedUnwindContext`.
pub fn initialize(
mut self,
cie: &CommonInformationEntry<Section, R, R::Offset>,
cie: &CommonInformationEntry<Section, R>,
) -> UnwindResult<InitializedUnwindContext<Section, R>, Self> {
self.0.assert_fully_uninitialized();

Expand Down Expand Up @@ -2166,14 +2164,14 @@ where
R: Reader,
Section: UnwindSection<R>,
{
cie: &'cie CommonInformationEntry<Section, R, R::Offset>,
cie: &'cie CommonInformationEntry<Section, R>,
next_start_address: u64,
returned_last_row: bool,
instructions: CallFrameInstructionIter<R>,
ctx: &'ctx mut UnwindContext<Section, R>,
// If this is `None`, then we are executing a CIE's initial_instructions. If
// this is `Some`, then we are executing an FDE's instructions.
fde: Option<&'fde FrameDescriptionEntry<Section, R, R::Offset>>,
fde: Option<&'fde FrameDescriptionEntry<Section, R>>,
}

/// # Signal Safe Methods
Expand All @@ -2189,7 +2187,7 @@ where
/// `FrameDescriptionEntry`'s CFI unwinding program.
pub fn new(
ctx: &'ctx mut InitializedUnwindContext<Section, R>,
fde: &'fde FrameDescriptionEntry<Section, R, R::Offset>,
fde: &'fde FrameDescriptionEntry<Section, R>,
) -> UnwindTable<'fde, 'fde, 'ctx, Section, R> {
assert!(ctx.0.is_initialized);
Self::new_internal(&mut ctx.0, fde.cie(), Some(fde))
Expand All @@ -2207,8 +2205,8 @@ where
{
fn new_internal(
ctx: &'ctx mut UnwindContext<Section, R>,
cie: &'cie CommonInformationEntry<Section, R, R::Offset>,
fde: Option<&'fde FrameDescriptionEntry<Section, R, R::Offset>>,
cie: &'cie CommonInformationEntry<Section, R>,
fde: Option<&'fde FrameDescriptionEntry<Section, R>>,
) -> UnwindTable<'cie, 'fde, 'ctx, Section, R> {
assert!(ctx.stack.len() >= 1);
let next_start_address = fde.map_or(0, |fde| fde.initial_address());
Expand Down Expand Up @@ -3339,12 +3337,12 @@ mod tests {
section: Section,
input: &mut R,
get_cie: F,
) -> Result<FrameDescriptionEntry<Section, R, R::Offset>>
) -> Result<FrameDescriptionEntry<Section, R>>
where
R: Reader,
Section: UnwindSection<R, Offset = O>,
O: UnwindOffset<R::Offset>,
F: FnMut(O) -> Result<CommonInformationEntry<Section, R, R::Offset>>,
F: FnMut(O) -> Result<CommonInformationEntry<Section, R>>,
{
let bases = Default::default();
match parse_cfi_entry(&bases, section, input) {
Expand Down
Loading

0 comments on commit 7c1b9e7

Please sign in to comment.