Skip to content

Commit

Permalink
read: rename DwarfUnit to Unit
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Feb 5, 2019
1 parent 2204db4 commit 7ea675b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 34 deletions.
20 changes: 10 additions & 10 deletions examples/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ where
let process_unit =
|unit: CompilationUnitHeader<R, R::Offset>, buf: &mut Vec<u8>| -> Result<()> {
let offset = unit.offset().0;
let unit = match gimli::DwarfUnit::new(dwarf, unit) {
let unit = match gimli::Unit::new(dwarf, unit) {
Ok(unit) => unit,
Err(err) => {
writeln!(
Expand Down Expand Up @@ -935,7 +935,7 @@ fn dump_types<R: Reader, W: Write>(
)?;

let offset = unit.offset().0;
let unit = match gimli::DwarfUnit::new_type_unit(dwarf, unit) {
let unit = match gimli::Unit::new_type_unit(dwarf, unit) {
Ok(unit) => unit,
Err(err) => {
writeln!(
Expand Down Expand Up @@ -968,7 +968,7 @@ fn spaces(buf: &mut String, len: usize) -> &str {
fn dump_entries<R: Reader, W: Write>(
w: &mut W,
offset: R::Offset,
unit: gimli::DwarfUnit<R>,
unit: gimli::Unit<R>,
dwarf: &gimli::Dwarf<R>,
flags: &Flags,
) -> Result<()> {
Expand Down Expand Up @@ -1031,7 +1031,7 @@ fn dump_entries<R: Reader, W: Write>(
fn dump_attr_value<R: Reader, W: Write>(
w: &mut W,
attr: &gimli::Attribute<R>,
unit: &gimli::DwarfUnit<R>,
unit: &gimli::Unit<R>,
dwarf: &gimli::Dwarf<R>,
) -> Result<()> {
let value = attr.value();
Expand Down Expand Up @@ -1259,7 +1259,7 @@ fn dump_type_signature<W: Write>(w: &mut W, signature: gimli::DebugTypeSignature
fn dump_file_index<R: Reader, W: Write>(
w: &mut W,
file: u64,
unit: &gimli::DwarfUnit<R>,
unit: &gimli::Unit<R>,
dwarf: &gimli::Dwarf<R>,
) -> Result<()> {
if file == 0 {
Expand Down Expand Up @@ -1300,7 +1300,7 @@ fn dump_file_index<R: Reader, W: Write>(
fn dump_exprloc<R: Reader, W: Write>(
w: &mut W,
data: &gimli::Expression<R>,
unit: &gimli::DwarfUnit<R>,
unit: &gimli::Unit<R>,
) -> Result<()> {
let mut pc = data.0.clone();
let mut space = false;
Expand Down Expand Up @@ -1503,7 +1503,7 @@ fn dump_op<R: Reader, W: Write>(
fn dump_loc_list<R: Reader, W: Write>(
w: &mut W,
offset: gimli::LocationListsOffset<R::Offset>,
unit: &gimli::DwarfUnit<R>,
unit: &gimli::Unit<R>,
dwarf: &gimli::Dwarf<R>,
) -> Result<()> {
let raw_locations = dwarf.locations.raw_locations(offset, unit.encoding())?;
Expand Down Expand Up @@ -1621,7 +1621,7 @@ fn dump_loc_list<R: Reader, W: Write>(
fn dump_range_list<R: Reader, W: Write>(
w: &mut W,
offset: gimli::RangeListsOffset<R::Offset>,
unit: &gimli::DwarfUnit<R>,
unit: &gimli::Unit<R>,
dwarf: &gimli::Dwarf<R>,
) -> Result<()> {
let raw_ranges = dwarf.ranges.raw_ranges(offset, unit.encoding())?;
Expand Down Expand Up @@ -1736,7 +1736,7 @@ fn dump_line<R: Reader, W: Write>(w: &mut W, dwarf: &gimli::Dwarf<R>) -> Result<
"\n.debug_line: line number info for unit at .debug_info offset 0x{:08x}",
unit.offset().0
)?;
let unit = match gimli::DwarfUnit::new(dwarf, unit) {
let unit = match gimli::Unit::new(dwarf, unit) {
Ok(unit) => unit,
Err(err) => {
writeln!(
Expand All @@ -1762,7 +1762,7 @@ fn dump_line<R: Reader, W: Write>(w: &mut W, dwarf: &gimli::Dwarf<R>) -> Result<

fn dump_line_program<R: Reader, W: Write>(
w: &mut W,
unit: &gimli::DwarfUnit<R>,
unit: &gimli::Unit<R>,
dwarf: &gimli::Dwarf<R>,
) -> Result<()> {
if let Some(program) = unit.line_program.clone() {
Expand Down
43 changes: 20 additions & 23 deletions src/read/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<R: Reader> Dwarf<R> {
#[inline]
pub fn string_offset(
&self,
unit: &DwarfUnit<R>,
unit: &Unit<R>,
index: DebugStrOffsetsIndex<R::Offset>,
) -> Result<DebugStrOffset<R::Offset>> {
self.debug_str_offsets
Expand Down Expand Up @@ -123,11 +123,7 @@ impl<R: Reader> Dwarf<R> {
///
/// then return the attribute's string value. Returns an error if the attribute
/// value does not have a string form, or if a string form has an invalid value.
pub fn attr_string(
&self,
unit: &DwarfUnit<R>,
attr: AttributeValue<R, R::Offset>,
) -> Result<R> {
pub fn attr_string(&self, unit: &Unit<R>, attr: AttributeValue<R, R::Offset>) -> Result<R> {
match attr {
AttributeValue::String(string) => Ok(string),
AttributeValue::DebugStrRef(offset) => self.debug_str.get_str(offset),
Expand All @@ -146,15 +142,15 @@ impl<R: Reader> Dwarf<R> {
}

/// Return the address at the given index.
pub fn address(&self, unit: &DwarfUnit<R>, index: DebugAddrIndex<R::Offset>) -> Result<u64> {
pub fn address(&self, unit: &Unit<R>, index: DebugAddrIndex<R::Offset>) -> Result<u64> {
self.debug_addr
.get_address(unit.encoding().address_size, unit.addr_base, index)
}

/// Return the range list offset at the given index.
pub fn ranges_offset(
&self,
unit: &DwarfUnit<R>,
unit: &Unit<R>,
index: DebugRngListsIndex<R::Offset>,
) -> Result<RangeListsOffset<R::Offset>> {
self.ranges
Expand All @@ -164,7 +160,7 @@ impl<R: Reader> Dwarf<R> {
/// Iterate over the `RangeListEntry`s starting at the given offset.
pub fn ranges(
&self,
unit: &DwarfUnit<R>,
unit: &Unit<R>,
offset: RangeListsOffset<R::Offset>,
) -> Result<RngListIter<R>> {
self.ranges.ranges(
Expand All @@ -187,7 +183,7 @@ impl<R: Reader> Dwarf<R> {
/// Returns `None` for other forms.
pub fn attr_ranges_offset(
&self,
unit: &DwarfUnit<R>,
unit: &Unit<R>,
attr: AttributeValue<R, R::Offset>,
) -> Result<Option<RangeListsOffset<R::Offset>>> {
match attr {
Expand All @@ -208,7 +204,7 @@ impl<R: Reader> Dwarf<R> {
/// Returns `None` for other forms.
pub fn attr_ranges(
&self,
unit: &DwarfUnit<R>,
unit: &Unit<R>,
attr: AttributeValue<R, R::Offset>,
) -> Result<Option<RngListIter<R>>> {
match self.attr_ranges_offset(unit, attr)? {
Expand All @@ -220,7 +216,7 @@ impl<R: Reader> Dwarf<R> {
/// Return the location list offset at the given index.
pub fn locations_offset(
&self,
unit: &DwarfUnit<R>,
unit: &Unit<R>,
index: DebugLocListsIndex<R::Offset>,
) -> Result<LocationListsOffset<R::Offset>> {
self.locations
Expand All @@ -230,7 +226,7 @@ impl<R: Reader> Dwarf<R> {
/// Iterate over the `LocationListEntry`s starting at the given offset.
pub fn locations(
&self,
unit: &DwarfUnit<R>,
unit: &Unit<R>,
offset: LocationListsOffset<R::Offset>,
) -> Result<LocListIter<R>> {
self.locations.locations(
Expand All @@ -253,7 +249,7 @@ impl<R: Reader> Dwarf<R> {
/// Returns `None` for other forms.
pub fn attr_locations_offset(
&self,
unit: &DwarfUnit<R>,
unit: &Unit<R>,
attr: AttributeValue<R, R::Offset>,
) -> Result<Option<LocationListsOffset<R::Offset>>> {
match attr {
Expand All @@ -276,7 +272,7 @@ impl<R: Reader> Dwarf<R> {
/// Returns `None` for other forms.
pub fn attr_locations(
&self,
unit: &DwarfUnit<R>,
unit: &Unit<R>,
attr: AttributeValue<R, R::Offset>,
) -> Result<Option<LocListIter<R>>> {
match self.attr_locations_offset(unit, attr)? {
Expand All @@ -286,9 +282,10 @@ impl<R: Reader> Dwarf<R> {
}
}

/// All of the commonly used information for a DWARF unit.
/// All of the commonly used information for a unit in the `.debug_info` or `.debug_types`
/// sections.
#[derive(Debug)]
pub struct DwarfUnit<R: Reader> {
pub struct Unit<R: Reader> {
/// The section offset of the unit.
pub offset: UnitSectionOffset<R::Offset>,

Expand Down Expand Up @@ -323,8 +320,8 @@ pub struct DwarfUnit<R: Reader> {
pub line_program: Option<IncompleteLineProgram<R, R::Offset>>,
}

impl<R: Reader> DwarfUnit<R> {
/// Construct a new `DwarfUnit` from the given compilation unit header.
impl<R: Reader> Unit<R> {
/// Construct a new `Unit` from the given compilation unit header.
#[inline]
pub fn new(dwarf: &Dwarf<R>, header: CompilationUnitHeader<R, R::Offset>) -> Result<Self> {
Self::new_internal(
Expand All @@ -334,7 +331,7 @@ impl<R: Reader> DwarfUnit<R> {
)
}

/// Construct a new `DwarfUnit` from the given type unit header.
/// Construct a new `Unit` from the given type unit header.
#[inline]
pub fn new_type_unit(dwarf: &Dwarf<R>, header: TypeUnitHeader<R, R::Offset>) -> Result<Self> {
Self::new_internal(
Expand All @@ -350,7 +347,7 @@ impl<R: Reader> DwarfUnit<R> {
header: UnitHeader<R, R::Offset>,
) -> Result<Self> {
let abbreviations = header.abbreviations(&dwarf.debug_abbrev)?;
let mut unit = DwarfUnit {
let mut unit = Unit {
offset,
header,
abbreviations,
Expand Down Expand Up @@ -476,7 +473,7 @@ impl<T: ReaderOffset> UnitSectionOffset<T> {
/// Convert an offset to be relative to the start of the given unit,
/// instead of relative to the start of the section.
/// Returns `None` if the offset is not within the unit entries.
pub fn to_unit_offset<R>(&self, unit: &DwarfUnit<R>) -> Option<UnitOffset<T>>
pub fn to_unit_offset<R>(&self, unit: &Unit<R>) -> Option<UnitOffset<T>>
where
R: Reader<Offset = T>,
{
Expand Down Expand Up @@ -505,7 +502,7 @@ impl<T: ReaderOffset> UnitSectionOffset<T> {
impl<T: ReaderOffset> UnitOffset<T> {
/// Convert an offset to be relative to the start of the .debug_info section,
/// instead of relative to the start of the given compilation unit.
pub fn to_unit_section_offset<R>(&self, unit: &DwarfUnit<R>) -> UnitSectionOffset<T>
pub fn to_unit_section_offset<R>(&self, unit: &Unit<R>) -> UnitSectionOffset<T>
where
R: Reader<Offset = T>,
{
Expand Down
2 changes: 1 addition & 1 deletion src/write/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ mod tests {
assert_eq!(unit1.address_size(), read_unit1.address_size());
assert_eq!(unit1.format(), read_unit1.format());

let read_unit1 = read::DwarfUnit::new(&dwarf, read_unit1).unwrap();
let read_unit1 = read::Unit::new(&dwarf, read_unit1).unwrap();
let mut read_entries = read_unit1.entries();

let root = unit1.get(unit1.root());
Expand Down

0 comments on commit 7ea675b

Please sign in to comment.