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 LineConvert #745

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions src/read/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,31 @@ impl<R: Reader> Dwarf<R> {
}
}

/// Return an attribute value as a string slice.
///
/// This only handles forms that are usable without an associated unit.
philipc marked this conversation as resolved.
Show resolved Hide resolved
///
/// If the attribute value is one of:
///
/// - an inline `DW_FORM_string` string
/// - a `DW_FORM_strp` reference to an offset into the `.debug_str` section
/// - a `DW_FORM_strp_sup` reference to an offset into a supplementary
/// object file
/// - a `DW_FORM_line_strp` reference to an offset into the `.debug_line_str`
/// section
///
/// 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_line_string(&self, attr: AttributeValue<R>) -> Result<R> {
match attr {
AttributeValue::String(string) => Ok(string),
AttributeValue::DebugStrRef(offset) => self.string(offset),
AttributeValue::DebugStrRefSup(offset) => self.sup_string(offset),
AttributeValue::DebugLineStrRef(offset) => self.line_string(offset),
_ => Err(Error::ExpectedStringAttributeValue),
}
}

/// Return the address at the given index.
pub fn address(&self, unit: &Unit<R>, index: DebugAddrIndex<R::Offset>) -> Result<u64> {
self.debug_addr
Expand Down
2 changes: 1 addition & 1 deletion src/read/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,7 @@ where
///
/// Note: For DWARF v5 files this may return an empty attribute that
/// indicates that no source code is available, which this function
/// represents as Some(<zero-length attr>).
/// represents as `Some(<zero-length attr>)`.
pub fn source(&self) -> Option<AttributeValue<R, Offset>> {
self.source.clone()
}
Expand Down
14 changes: 12 additions & 2 deletions src/write/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use alloc::vec::Vec;

use crate::common::Encoding;
use crate::write::{
AbbreviationTable, LineProgram, LineStringTable, Result, Sections, StringTable, Unit,
UnitTable, Writer,
AbbreviationTable, LineProgram, LineString, LineStringTable, Result, Sections, StringTable,
Unit, UnitTable, Writer,
};

/// Writable DWARF information for more than one unit.
Expand Down Expand Up @@ -48,6 +48,11 @@ impl Dwarf {
}
Ok(())
}

/// Get a reference to the data for a line string.
pub fn get_line_string<'a>(&'a self, string: &'a LineString) -> &'a [u8] {
string.get(&self.strings, &self.line_strings)
}
}

/// Writable DWARF information for a single unit.
Expand Down Expand Up @@ -102,6 +107,11 @@ impl DwarfUnit {
abbrevs.write(&mut sections.debug_abbrev)?;
Ok(())
}

/// Get a reference to the data for a line string.
pub fn get_line_string<'a>(&'a self, string: &'a LineString) -> &'a [u8] {
string.get(&self.strings, &self.line_strings)
}
}

#[cfg(feature = "read")]
Expand Down
Loading
Loading