Skip to content

Commit

Permalink
dwarf dump: Fix padding handling within tag children
Browse files Browse the repository at this point in the history
  • Loading branch information
encounter committed Nov 22, 2023
1 parent c8a2d48 commit e3d6ef8
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/util/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,20 +373,19 @@ impl Tag {
pub fn children<'a>(&self, tags: &'a TagMap) -> Vec<&'a Tag> {
let sibling = self.next_sibling(tags);
let mut children = Vec::new();
let (_, mut child) = match tags.range(self.key + 1..).next() {
let mut child = match self.next_tag(tags) {
Some(child) => child,
None => return children,
};
if child.kind == TagKind::Padding {
return children;
}
loop {
if let Some(end) = sibling {
if child.key == end.key {
break;
}
}
children.push(child);
if child.kind != TagKind::Padding {
children.push(child);
}
match child.next_sibling(tags) {
Some(next) => child = next,
None => break,
Expand All @@ -395,15 +394,18 @@ impl Tag {
children
}

/// Returns the next sibling tag, if any
pub fn next_sibling<'a>(&self, tags: &'a TagMap) -> Option<&'a Tag> {
if let Some(key) = self.reference_attribute(AttributeKind::Sibling) {
if let Some(next) = tags.get(&key) {
if next.kind != TagKind::Padding {
return Some(next);
}
}
tags.get(&key)
} else {
self.next_tag(tags)
}
None
}

/// Returns the next tag sequentially, if any
pub fn next_tag<'a>(&self, tags: &'a TagMap) -> Option<&'a Tag> {
tags.range(self.key + 1..).next().map(|(_, tag)| tag)
}
}

Expand Down

0 comments on commit e3d6ef8

Please sign in to comment.