Skip to content

Commit

Permalink
only do DW_LNCT_LLVM_source for now
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrmaxmeier committed Jun 28, 2024
1 parent c5062fd commit b360964
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,9 @@ DwLnct(u16) {
DW_LNCT_timestamp = 0x3,
DW_LNCT_size = 0x4,
DW_LNCT_MD5 = 0x5,
DW_LNCT_source = 0x6,
// DW_LNCT_source = 0x6,
DW_LNCT_lo_user = 0x2000,
// LLVM project extensions.
// We currently only implement the LLVM embedded source code extension for DWARF v5.
DW_LNCT_LLVM_source = 0x2001,
DW_LNCT_hi_user = 0x3fff,
});
Expand Down
42 changes: 15 additions & 27 deletions src/read/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,13 @@ where
.any(|x| x.content_type == constants::DW_LNCT_MD5)
}

/// Return true if the file name entry format contains an source field.
pub fn file_has_source(&self) -> bool {
self.file_name_entry_format
.iter()
.any(|x| x.content_type == constants::DW_LNCT_LLVM_source)
}

/// Get the list of source files that appear in this header's line program.
pub fn file_names(&self) -> &[FileEntry<R, Offset>] {
&self.file_names[..]
Expand Down Expand Up @@ -1672,33 +1679,14 @@ where
}

/// The source code of this file. (UTF-8 source text string with "\n" line
/// endings). Note that this may return an empty attribute that indicates
/// that no source code is available. The `FileEntry::source` function
/// handles this automatically.
/// endings).
///
/// This is an accepted proposal for DWARFv6 (Issue 180201.1: DWARF and
/// source text embedding)
pub fn source_attr(&self) -> Option<AttributeValue<R, Offset>> {
/// 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>).
pub fn source(&self) -> Option<AttributeValue<R, Offset>> {
self.source.clone()
}

/// The source code of this file. (UTF-8 source text string with "\n" line
/// endings)
pub fn source(&self, unit: &crate::UnitRef<'_, R>) -> crate::Result<Option<R>> {
match self.source {
Some(ref source) => {
let res = unit.attr_string(source.clone())?;
// Empty source strings (missing mandatory line ending) indicate
// that no source was provided for this file
if res.is_empty() {
Ok(None)
} else {
Ok(Some(res))
}
}
None => Ok(None),
}
}
}

/// The format of a component of an include directory or file name entry.
Expand Down Expand Up @@ -1793,7 +1781,7 @@ fn parse_file_v5<R: Reader>(
}
}
}
constants::DW_LNCT_source | constants::DW_LNCT_LLVM_source => {
constants::DW_LNCT_LLVM_source => {
source = Some(value);
}
// Ignore unknown content types.
Expand Down Expand Up @@ -3026,7 +3014,7 @@ mod tests {
.uleb(constants::DW_FORM_data1.0 as u64)
.uleb(constants::DW_LNCT_MD5.0 as u64)
.uleb(constants::DW_FORM_data16.0 as u64)
.uleb(constants::DW_LNCT_source.0 as u64)
.uleb(constants::DW_LNCT_LLVM_source.0 as u64)
.uleb(constants::DW_FORM_string.0 as u64)
// File count.
.D8(2)
Expand Down Expand Up @@ -3091,7 +3079,7 @@ mod tests {
form: constants::DW_FORM_data16,
},
FileEntryFormat {
content_type: constants::DW_LNCT_source,
content_type: constants::DW_LNCT_LLVM_source,
form: constants::DW_FORM_string,
}
]
Expand Down
7 changes: 4 additions & 3 deletions src/write/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ impl LineProgram {
w.write_uleb128(constants::DW_FORM_data16.0.into())?;
}
if self.file_has_source {
w.write_uleb128(u64::from(constants::DW_LNCT_source.0))?;
w.write_uleb128(u64::from(constants::DW_LNCT_LLVM_source.0))?;
w.write_uleb128(constants::DW_FORM_string.0.into())?;
}

Expand Down Expand Up @@ -1031,7 +1031,7 @@ mod convert {
timestamp: comp_file.timestamp(),
size: comp_file.size(),
md5: *comp_file.md5(),
source: match comp_file.source_attr() {
source: match comp_file.source() {
Some(source) => Some(LineString::from(
source,
dwarf,
Expand Down Expand Up @@ -1081,6 +1081,7 @@ mod convert {
program.file_has_timestamp = from_header.file_has_timestamp();
program.file_has_size = from_header.file_has_size();
program.file_has_md5 = from_header.file_has_md5();
program.file_has_source = from_header.file_has_source();
for from_file in from_header.file_names().iter().skip(file_skip) {
let from_name =
LineString::from(from_file.path_name(), dwarf, line_strings, strings)?;
Expand All @@ -1093,7 +1094,7 @@ mod convert {
timestamp: from_file.timestamp(),
size: from_file.size(),
md5: *from_file.md5(),
source: match from_file.source_attr() {
source: match from_file.source() {
Some(source) => {
Some(LineString::from(source, dwarf, line_strings, strings)?)
}
Expand Down

0 comments on commit b360964

Please sign in to comment.