Skip to content

Commit

Permalink
Review comments: call it IndexSectionId
Browse files Browse the repository at this point in the history
  • Loading branch information
jameysharp committed May 24, 2024
1 parent cdb9d39 commit bae25f8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 73 deletions.
22 changes: 11 additions & 11 deletions src/read/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::read::{
Abbreviations, AbbreviationsCache, AbbreviationsCacheStrategy, AttributeValue, DebugAbbrev,
DebugAddr, DebugAranges, DebugCuIndex, DebugInfo, DebugInfoUnitHeadersIter, DebugLine,
DebugLineStr, DebugLoc, DebugLocLists, DebugRanges, DebugRngLists, DebugStr, DebugStrOffsets,
DebugTuIndex, DebugTypes, DebugTypesUnitHeadersIter, DebuggingInformationEntry, DwoSectionId,
EntriesCursor, EntriesRaw, EntriesTree, Error, IncompleteLineProgram, LocListIter,
DebugTuIndex, DebugTypes, DebugTypesUnitHeadersIter, DebuggingInformationEntry, EntriesCursor,
EntriesRaw, EntriesTree, Error, IncompleteLineProgram, IndexSectionId, LocListIter,
LocationLists, Range, RangeLists, RawLocListIter, RawRngListIter, Reader, ReaderOffset,
ReaderOffsetId, Result, RngListIter, Section, UnitHeader, UnitIndex, UnitIndexSectionIterator,
UnitOffset, UnitType,
Expand Down Expand Up @@ -1014,39 +1014,39 @@ impl<R: Reader> DwarfPackage<R> {
let mut types_size = 0;
for section in sections {
match section.section {
DwoSectionId::DebugAbbrev => {
IndexSectionId::DebugAbbrev => {
abbrev_offset = section.offset;
abbrev_size = section.size;
}
DwoSectionId::DebugInfo => {
IndexSectionId::DebugInfo => {
info_offset = section.offset;
info_size = section.size;
}
DwoSectionId::DebugLine => {
IndexSectionId::DebugLine => {
line_offset = section.offset;
line_size = section.size;
}
DwoSectionId::DebugLoc => {
IndexSectionId::DebugLoc => {
loc_offset = section.offset;
loc_size = section.size;
}
DwoSectionId::DebugLocLists => {
IndexSectionId::DebugLocLists => {
loclists_offset = section.offset;
loclists_size = section.size;
}
DwoSectionId::DebugStrOffsets => {
IndexSectionId::DebugStrOffsets => {
str_offsets_offset = section.offset;
str_offsets_size = section.size;
}
DwoSectionId::DebugRngLists => {
IndexSectionId::DebugRngLists => {
rnglists_offset = section.offset;
rnglists_size = section.size;
}
DwoSectionId::DebugTypes => {
IndexSectionId::DebugTypes => {
types_offset = section.offset;
types_size = section.size;
}
DwoSectionId::DebugMacro | DwoSectionId::DebugMacinfo => {
IndexSectionId::DebugMacro | IndexSectionId::DebugMacinfo => {
// These are valid but we can't parse these yet.
}
}
Expand Down
124 changes: 62 additions & 62 deletions src/read/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub struct UnitIndex<R: Reader> {
hash_ids: R,
hash_rows: R,
// Only `section_count` values are valid.
sections: [DwoSectionId; SECTION_COUNT_MAX as usize],
sections: [IndexSectionId; SECTION_COUNT_MAX as usize],
offsets: R,
sizes: R,
}
Expand All @@ -144,7 +144,7 @@ impl<R: Reader> UnitIndex<R> {
slot_count: 0,
hash_ids: input.clone(),
hash_rows: input.clone(),
sections: [DwoSectionId::DebugAbbrev; SECTION_COUNT_MAX as usize],
sections: [IndexSectionId::DebugAbbrev; SECTION_COUNT_MAX as usize],
offsets: input.clone(),
sizes: input.clone(),
});
Expand Down Expand Up @@ -173,33 +173,33 @@ impl<R: Reader> UnitIndex<R> {
let hash_ids = input.split(R::Offset::from_u64(u64::from(slot_count) * 8)?)?;
let hash_rows = input.split(R::Offset::from_u64(u64::from(slot_count) * 4)?)?;

let mut sections = [DwoSectionId::DebugAbbrev; SECTION_COUNT_MAX as usize];
let mut sections = [IndexSectionId::DebugAbbrev; SECTION_COUNT_MAX as usize];
if section_count > SECTION_COUNT_MAX.into() {
return Err(Error::InvalidIndexSectionCount);
}
for i in 0..section_count {
let section = input.read_u32()?;
sections[i as usize] = if version == 2 {
match constants::DwSectV2(section) {
constants::DW_SECT_V2_INFO => DwoSectionId::DebugInfo,
constants::DW_SECT_V2_TYPES => DwoSectionId::DebugTypes,
constants::DW_SECT_V2_ABBREV => DwoSectionId::DebugAbbrev,
constants::DW_SECT_V2_LINE => DwoSectionId::DebugLine,
constants::DW_SECT_V2_LOC => DwoSectionId::DebugLoc,
constants::DW_SECT_V2_STR_OFFSETS => DwoSectionId::DebugStrOffsets,
constants::DW_SECT_V2_MACINFO => DwoSectionId::DebugMacinfo,
constants::DW_SECT_V2_MACRO => DwoSectionId::DebugMacro,
constants::DW_SECT_V2_INFO => IndexSectionId::DebugInfo,
constants::DW_SECT_V2_TYPES => IndexSectionId::DebugTypes,
constants::DW_SECT_V2_ABBREV => IndexSectionId::DebugAbbrev,
constants::DW_SECT_V2_LINE => IndexSectionId::DebugLine,
constants::DW_SECT_V2_LOC => IndexSectionId::DebugLoc,
constants::DW_SECT_V2_STR_OFFSETS => IndexSectionId::DebugStrOffsets,
constants::DW_SECT_V2_MACINFO => IndexSectionId::DebugMacinfo,
constants::DW_SECT_V2_MACRO => IndexSectionId::DebugMacro,
section => return Err(Error::UnknownIndexSectionV2(section)),
}
} else {
match constants::DwSect(section) {
constants::DW_SECT_INFO => DwoSectionId::DebugInfo,
constants::DW_SECT_ABBREV => DwoSectionId::DebugAbbrev,
constants::DW_SECT_LINE => DwoSectionId::DebugLine,
constants::DW_SECT_LOCLISTS => DwoSectionId::DebugLocLists,
constants::DW_SECT_STR_OFFSETS => DwoSectionId::DebugStrOffsets,
constants::DW_SECT_MACRO => DwoSectionId::DebugMacro,
constants::DW_SECT_RNGLISTS => DwoSectionId::DebugRngLists,
constants::DW_SECT_INFO => IndexSectionId::DebugInfo,
constants::DW_SECT_ABBREV => IndexSectionId::DebugAbbrev,
constants::DW_SECT_LINE => IndexSectionId::DebugLine,
constants::DW_SECT_LOCLISTS => IndexSectionId::DebugLocLists,
constants::DW_SECT_STR_OFFSETS => IndexSectionId::DebugStrOffsets,
constants::DW_SECT_MACRO => IndexSectionId::DebugMacro,
constants::DW_SECT_RNGLISTS => IndexSectionId::DebugRngLists,
section => return Err(Error::UnknownIndexSection(section)),
}
};
Expand Down Expand Up @@ -305,7 +305,7 @@ impl<R: Reader> UnitIndex<R> {
/// An iterator over the section offsets and sizes for a row in a `UnitIndex`.
#[derive(Debug, Clone)]
pub struct UnitIndexSectionIterator<'index, R: Reader> {
sections: slice::Iter<'index, DwoSectionId>,
sections: slice::Iter<'index, IndexSectionId>,
offsets: R,
sizes: R,
}
Expand All @@ -330,7 +330,7 @@ impl<'index, R: Reader> Iterator for UnitIndexSectionIterator<'index, R> {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct UnitIndexSection {
/// The section kind.
pub section: DwoSectionId,
pub section: IndexSectionId,
/// The base offset of the unit's contribution to the section.
pub offset: u32,
/// The size of the unit's contribution to the section.
Expand All @@ -339,7 +339,7 @@ pub struct UnitIndexSection {

/// Section kinds which are permitted in a `.dwo` file.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DwoSectionId {
pub enum IndexSectionId {
/// The `.debug_abbrev.dwo` section.
DebugAbbrev,
/// The `.debug_info.dwo` section.
Expand All @@ -362,20 +362,20 @@ pub enum DwoSectionId {
DebugTypes,
}

impl DwoSectionId {
impl IndexSectionId {
/// Returns the ELF section name for this kind, when found in a .dwo or .dwp file.
pub fn dwo_name(self) -> &'static str {
let section_id = match self {
DwoSectionId::DebugAbbrev => SectionId::DebugAbbrev,
DwoSectionId::DebugInfo => SectionId::DebugInfo,
DwoSectionId::DebugLine => SectionId::DebugLine,
DwoSectionId::DebugLoc => SectionId::DebugLoc,
DwoSectionId::DebugLocLists => SectionId::DebugLocLists,
DwoSectionId::DebugMacro => SectionId::DebugMacro,
DwoSectionId::DebugMacinfo => SectionId::DebugMacinfo,
DwoSectionId::DebugRngLists => SectionId::DebugRngLists,
DwoSectionId::DebugStrOffsets => SectionId::DebugStrOffsets,
DwoSectionId::DebugTypes => SectionId::DebugTypes,
IndexSectionId::DebugAbbrev => SectionId::DebugAbbrev,
IndexSectionId::DebugInfo => SectionId::DebugInfo,
IndexSectionId::DebugLine => SectionId::DebugLine,
IndexSectionId::DebugLoc => SectionId::DebugLoc,
IndexSectionId::DebugLocLists => SectionId::DebugLocLists,
IndexSectionId::DebugMacro => SectionId::DebugMacro,
IndexSectionId::DebugMacinfo => SectionId::DebugMacinfo,
IndexSectionId::DebugRngLists => SectionId::DebugRngLists,
IndexSectionId::DebugStrOffsets => SectionId::DebugStrOffsets,
IndexSectionId::DebugTypes => SectionId::DebugTypes,
};
section_id.dwo_name().unwrap()
}
Expand Down Expand Up @@ -481,26 +481,26 @@ mod tests {
assert_eq!(
index.sections,
[
DwoSectionId::DebugInfo,
DwoSectionId::DebugTypes,
DwoSectionId::DebugAbbrev,
DwoSectionId::DebugLine,
DwoSectionId::DebugLoc,
DwoSectionId::DebugStrOffsets,
DwoSectionId::DebugMacinfo,
DwoSectionId::DebugMacro,
IndexSectionId::DebugInfo,
IndexSectionId::DebugTypes,
IndexSectionId::DebugAbbrev,
IndexSectionId::DebugLine,
IndexSectionId::DebugLoc,
IndexSectionId::DebugStrOffsets,
IndexSectionId::DebugMacinfo,
IndexSectionId::DebugMacro,
]
);
#[rustfmt::skip]
let expect = [
UnitIndexSection { section: DwoSectionId::DebugInfo, offset: 11, size: 21 },
UnitIndexSection { section: DwoSectionId::DebugTypes, offset: 12, size: 22 },
UnitIndexSection { section: DwoSectionId::DebugAbbrev, offset: 13, size: 23 },
UnitIndexSection { section: DwoSectionId::DebugLine, offset: 14, size: 24 },
UnitIndexSection { section: DwoSectionId::DebugLoc, offset: 15, size: 25 },
UnitIndexSection { section: DwoSectionId::DebugStrOffsets, offset: 16, size: 26 },
UnitIndexSection { section: DwoSectionId::DebugMacinfo, offset: 17, size: 27 },
UnitIndexSection { section: DwoSectionId::DebugMacro, offset: 18, size: 28 },
UnitIndexSection { section: IndexSectionId::DebugInfo, offset: 11, size: 21 },
UnitIndexSection { section: IndexSectionId::DebugTypes, offset: 12, size: 22 },
UnitIndexSection { section: IndexSectionId::DebugAbbrev, offset: 13, size: 23 },
UnitIndexSection { section: IndexSectionId::DebugLine, offset: 14, size: 24 },
UnitIndexSection { section: IndexSectionId::DebugLoc, offset: 15, size: 25 },
UnitIndexSection { section: IndexSectionId::DebugStrOffsets, offset: 16, size: 26 },
UnitIndexSection { section: IndexSectionId::DebugMacinfo, offset: 17, size: 27 },
UnitIndexSection { section: IndexSectionId::DebugMacro, offset: 18, size: 28 },
];
let mut sections = index.sections(1).unwrap();
for section in &expect {
Expand Down Expand Up @@ -536,24 +536,24 @@ mod tests {
assert_eq!(
index.sections[..7],
[
DwoSectionId::DebugInfo,
DwoSectionId::DebugAbbrev,
DwoSectionId::DebugLine,
DwoSectionId::DebugLocLists,
DwoSectionId::DebugStrOffsets,
DwoSectionId::DebugMacro,
DwoSectionId::DebugRngLists,
IndexSectionId::DebugInfo,
IndexSectionId::DebugAbbrev,
IndexSectionId::DebugLine,
IndexSectionId::DebugLocLists,
IndexSectionId::DebugStrOffsets,
IndexSectionId::DebugMacro,
IndexSectionId::DebugRngLists,
]
);
#[rustfmt::skip]
let expect = [
UnitIndexSection { section: DwoSectionId::DebugInfo, offset: 11, size: 21 },
UnitIndexSection { section: DwoSectionId::DebugAbbrev, offset: 12, size: 22 },
UnitIndexSection { section: DwoSectionId::DebugLine, offset: 13, size: 23 },
UnitIndexSection { section: DwoSectionId::DebugLocLists, offset: 14, size: 24 },
UnitIndexSection { section: DwoSectionId::DebugStrOffsets, offset: 15, size: 25 },
UnitIndexSection { section: DwoSectionId::DebugMacro, offset: 16, size: 26 },
UnitIndexSection { section: DwoSectionId::DebugRngLists, offset: 17, size: 27 },
UnitIndexSection { section: IndexSectionId::DebugInfo, offset: 11, size: 21 },
UnitIndexSection { section: IndexSectionId::DebugAbbrev, offset: 12, size: 22 },
UnitIndexSection { section: IndexSectionId::DebugLine, offset: 13, size: 23 },
UnitIndexSection { section: IndexSectionId::DebugLocLists, offset: 14, size: 24 },
UnitIndexSection { section: IndexSectionId::DebugStrOffsets, offset: 15, size: 25 },
UnitIndexSection { section: IndexSectionId::DebugMacro, offset: 16, size: 26 },
UnitIndexSection { section: IndexSectionId::DebugRngLists, offset: 17, size: 27 },
];
let mut sections = index.sections(1).unwrap();
for section in &expect {
Expand Down

0 comments on commit bae25f8

Please sign in to comment.