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

write: add EhFrame and DebugFrame to sections #492

Merged
merged 3 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions examples/dwarf-validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ where
'a: 'file,
{
let data = match file.section_by_name(S::section_name()) {
Some(ref section) => {
section.uncompressed_data().unwrap_or(Cow::Borrowed(&[][..]))
}
Some(ref section) => section
.uncompressed_data()
.unwrap_or(Cow::Borrowed(&[][..])),
None => Cow::Borrowed(&[][..]),
};
let data_ref = (*arena.alloc(data)).borrow();
Expand Down
12 changes: 7 additions & 5 deletions examples/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ fn writeln_error<W: Write, R: Reader>(
msg,
match err {
Error::GimliError(err) => dwarf.format_error(err),
Error::ObjectError(err) => format!("{}:{:?}", "An object error occurred while reading", err),
Error::ObjectError(err) =>
format!("{}:{:?}", "An object error occurred while reading", err),
Error::IoError => "An I/O error occurred while writing.".to_string(),
}
)
Expand All @@ -65,9 +66,9 @@ impl From<io::Error> for Error {
}

impl From<object::read::Error> for Error {
fn from(err: object::read::Error) -> Self {
Error::ObjectError(err)
}
fn from(err: object::read::Error) -> Self {
Error::ObjectError(err)
}
}

pub type Result<T> = result::Result<T, Error>;
Expand Down Expand Up @@ -171,7 +172,8 @@ fn add_relocations(
object::RelocationTarget::Symbol(symbol_idx) => {
match file.symbol_by_index(symbol_idx) {
Ok(symbol) => {
let addend = symbol.address().wrapping_add(relocation.addend() as u64);
let addend =
symbol.address().wrapping_add(relocation.addend() as u64);
relocation.set_addend(addend as i64);
}
Err(_) => {
Expand Down
6 changes: 3 additions & 3 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ fn dump_file(object: &object::File, endian: gimli::RunTimeEndian) -> Result<(),
// Load a section and return as `Cow<[u8]>`.
let load_section = |id: gimli::SectionId| -> Result<borrow::Cow<[u8]>, gimli::Error> {
match object.section_by_name(id.name()) {
Some(ref section) => {
Ok(section.uncompressed_data().unwrap_or(borrow::Cow::Borrowed(&[][..])))
}
Some(ref section) => Ok(section
.uncompressed_data()
.unwrap_or(borrow::Cow::Borrowed(&[][..]))),
None => Ok(borrow::Cow::Borrowed(&[][..])),
}
};
Expand Down
8 changes: 4 additions & 4 deletions examples/simple_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ fn dump_file(object: &object::File, endian: gimli::RunTimeEndian) -> Result<(),
// Load a section and return as `Cow<[u8]>`.
let load_section = |id: gimli::SectionId| -> Result<borrow::Cow<[u8]>, gimli::Error> {
match object.section_by_name(id.name()) {
Some(ref section) => {
Ok(section.uncompressed_data().unwrap_or(borrow::Cow::Borrowed(&[][..])))
}
Some(ref section) => Ok(section
.uncompressed_data()
.unwrap_or(borrow::Cow::Borrowed(&[][..]))),
None => Ok(borrow::Cow::Borrowed(&[][..])),
}
}
};
// Load a supplementary section. We don't have a supplementary object file,
// so always return an empty slice.
Expand Down
14 changes: 12 additions & 2 deletions src/write/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::vec::Vec;

use crate::common::SectionId;
use crate::write::{
DebugAbbrev, DebugInfo, DebugInfoReference, DebugLine, DebugLineStr, DebugLoc, DebugLocLists,
DebugRanges, DebugRngLists, DebugStr, Writer,
DebugAbbrev, DebugFrame, DebugInfo, DebugInfoReference, DebugLine, DebugLineStr, DebugLoc,
DebugLocLists, DebugRanges, DebugRngLists, DebugStr, EhFrame, Writer,
};

macro_rules! define_section {
Expand Down Expand Up @@ -85,6 +85,10 @@ pub struct Sections<W: Writer> {
pub debug_loclists: DebugLocLists<W>,
/// The `.debug_str` section.
pub debug_str: DebugStr<W>,
/// The `.debug_frame` section.
pub debug_frame: DebugFrame<W>,
/// The `.eh_frame` section.
pub eh_frame: EhFrame<W>,
/// Unresolved references in the `.debug_info` section.
pub(crate) debug_info_refs: Vec<DebugInfoReference>,
/// Unresolved references in the `.debug_loc` section.
Expand All @@ -106,6 +110,8 @@ impl<W: Writer + Clone> Sections<W> {
debug_loc: DebugLoc(section.clone()),
debug_loclists: DebugLocLists(section.clone()),
debug_str: DebugStr(section.clone()),
debug_frame: DebugFrame(section.clone()),
eh_frame: EhFrame(section.clone()),
debug_info_refs: Vec::new(),
debug_loc_refs: Vec::new(),
debug_loclists_refs: Vec::new(),
Expand Down Expand Up @@ -134,6 +140,8 @@ impl<W: Writer> Sections<W> {
f!(self.debug_loc)?;
f!(self.debug_loclists)?;
f!(self.debug_info)?;
f!(self.debug_frame)?;
f!(self.eh_frame)?;
Ok(())
}

Expand All @@ -157,6 +165,8 @@ impl<W: Writer> Sections<W> {
f!(self.debug_loc)?;
f!(self.debug_loclists)?;
f!(self.debug_info)?;
f!(self.debug_frame)?;
f!(self.eh_frame)?;
Ok(())
}
}
4 changes: 3 additions & 1 deletion src/write/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{slice, usize};

use crate::common::{
DebugAbbrevOffset, DebugInfoOffset, DebugLineOffset, DebugMacinfoOffset, DebugMacroOffset,
DebugStrOffset, DebugTypeSignature, Encoding, Format, SectionId, UnitSectionOffset,
DebugStrOffset, DebugTypeSignature, Encoding, Format, SectionId,
};
use crate::constants;
use crate::leb128::write::{sleb128_size, uleb128_size};
Expand Down Expand Up @@ -1471,6 +1471,7 @@ pub(crate) struct DebugInfoReference {
#[cfg(feature = "read")]
pub(crate) mod convert {
use super::*;
use crate::common::UnitSectionOffset;
use crate::read::{self, Reader};
use crate::write::{self, ConvertError, ConvertResult, LocationList, RangeList};
use std::collections::HashMap;
Expand Down Expand Up @@ -1911,6 +1912,7 @@ mod tests {
use super::*;
use crate::common::{
DebugAddrBase, DebugLocListsBase, DebugRngListsBase, DebugStrOffsetsBase, LineEncoding,
UnitSectionOffset,
};
use crate::constants;
use crate::read;
Expand Down