Skip to content

Commit

Permalink
Log section-relative offsets of DIEs
Browse files Browse the repository at this point in the history
For easier correlation to llvm-dwarfdump's output.
  • Loading branch information
SingleAccretion committed Nov 6, 2024
1 parent 7351bb7 commit 17ffc4d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
21 changes: 16 additions & 5 deletions crates/cranelift/src/debug/transform/debug_transform_logging.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::debug::Reader;
use core::fmt;
use gimli::{write, AttributeValue, DebuggingInformationEntry, Dwarf, LittleEndian, Unit};
use gimli::{
write, AttributeValue, DebuggingInformationEntry, Dwarf, LittleEndian, Unit, UnitSectionOffset,
};

macro_rules! dbi_log {
($($tt:tt)*) => {
Expand All @@ -18,7 +20,7 @@ pub struct CompileUnitSummary<'a> {
impl<'a> fmt::Debug for CompileUnitSummary<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let unit = self.unit;
let offs: usize = unit.header.offset().as_debug_info_offset().unwrap().0;
let offs = get_offset_value(unit.header.offset());
write!(f, "0x{offs:08x} [")?;
let comp_dir = match unit.comp_dir {
Some(dir) => &dir.to_string_lossy(),
Expand Down Expand Up @@ -51,7 +53,7 @@ pub fn log_begin_input_die(
) {
dbi_log!(
"=== Begin DIE at 0x{:08x} (depth = {}):\n{:?}",
die.offset().0,
get_offset_value(die.offset().to_unit_section_offset(unit)),
depth,
DieDetailedSummary { dwarf, unit, die }
);
Expand Down Expand Up @@ -210,14 +212,15 @@ impl<'a> fmt::Debug for OutDieDetailedSummary<'a> {

pub fn log_end_output_die(
input_die: &DebuggingInformationEntry<Reader<'_>>,
input_unit: &Unit<Reader<'_>, usize>,
die_id: write::UnitEntryId,
unit: &write::Unit,
strings: &write::StringTable,
depth: isize,
) {
dbi_log!(
"=== End DIE at 0x{:08x} (depth = {}):\n{:?}",
input_die.offset().0,
get_offset_value(input_die.offset().to_unit_section_offset(input_unit)),
depth,
OutDieDetailedSummary {
die_id,
Expand All @@ -229,13 +232,21 @@ pub fn log_end_output_die(

pub fn log_end_output_die_skipped(
input_die: &DebuggingInformationEntry<Reader<'_>>,
input_unit: &Unit<Reader<'_>, usize>,
reason: &str,
depth: isize,
) {
dbi_log!(
"=== End DIE at 0x{:08x} (depth = {}):\n Skipped as {}\n",
input_die.offset().0,
get_offset_value(input_die.offset().to_unit_section_offset(input_unit)),
depth,
reason
);
}

fn get_offset_value(offset: UnitSectionOffset) -> usize {
match offset {
UnitSectionOffset::DebugInfoOffset(offs) => offs.0,
UnitSectionOffset::DebugTypesOffset(offs) => offs.0,
}
}
19 changes: 13 additions & 6 deletions crates/cranelift/src/debug/transform/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ pub(crate) fn clone_unit(
let (wp_die_id, vmctx_die_id) =
add_internal_types(out_unit, out_root_id, out_strings, memory_offset);

log_end_output_die(entry, out_root_id, out_unit, out_strings, 0);
log_end_output_die(entry, unit, out_root_id, out_unit, out_strings, 0);
stack.push(out_root_id);
(
out_unit,
Expand Down Expand Up @@ -376,7 +376,7 @@ pub(crate) fn clone_unit(
// if D is below B continue to skip
if new_depth > 0 {
skip_at_depth = Some((new_depth, cached));
log_end_output_die_skipped(entry, "unreachable", current_depth);
log_end_output_die_skipped(entry, unit, "unreachable", current_depth);
continue;
}
// otherwise process D with `depth_delta` being the difference from A to D
Expand All @@ -395,7 +395,7 @@ pub(crate) fn clone_unit(
// Here B = C so `depth` is 0. A is the previous node so `cached` =
// `depth_delta`.
skip_at_depth = Some((0, depth_delta));
log_end_output_die_skipped(entry, "unreachable", current_depth);
log_end_output_die_skipped(entry, unit, "unreachable", current_depth);
continue;
}

Expand Down Expand Up @@ -448,7 +448,7 @@ pub(crate) fn clone_unit(
if entry.tag() == gimli::DW_TAG_pointer_type || entry.tag() == gimli::DW_TAG_reference_type
{
// Wrap pointer types.
let pointer_kind = match entry.tag() {
let pointer_kind: WebAssemblyPtrKind = match entry.tag() {
gimli::DW_TAG_pointer_type => WebAssemblyPtrKind::Pointer,
gimli::DW_TAG_reference_type => WebAssemblyPtrKind::Reference,
_ => panic!(),
Expand All @@ -467,7 +467,7 @@ pub(crate) fn clone_unit(
stack.push(die_id);
assert_eq!(stack.len(), new_stack_len);
die_ref_map.insert(entry.offset(), die_id);
log_end_output_die(entry, die_id, out_unit, out_strings, current_depth);
log_end_output_die(entry, unit, die_id, out_unit, out_strings, current_depth);
continue;
}

Expand Down Expand Up @@ -524,7 +524,14 @@ pub(crate) fn clone_unit(
)?;
}

log_end_output_die(entry, out_die_id, out_unit, out_strings, current_depth);
log_end_output_die(
entry,
unit,
out_die_id,
out_unit,
out_strings,
current_depth,
);
}
die_ref_map.patch(pending_die_refs, out_unit);
Ok(Some((out_unit_id, die_ref_map, pending_di_refs)))
Expand Down

0 comments on commit 17ffc4d

Please sign in to comment.