From 807dc6a44095e5fcef7c4503afbd5a1035790f26 Mon Sep 17 00:00:00 2001 From: Chippy <57328807+1superchip@users.noreply.github.com> Date: Tue, 20 Feb 2024 21:56:49 -0600 Subject: [PATCH] Rename and output GCC extensions (#40) Outputs GCC Source Info extensions Add asm language to support DWARF emitted by MWCC MIPS assembler Update MwOverlayBranch handling --- src/cmd/dwarf.rs | 10 ++++++++++ src/util/dwarf.rs | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/cmd/dwarf.rs b/src/cmd/dwarf.rs index 972fd51..c5e4526 100644 --- a/src/cmd/dwarf.rs +++ b/src/cmd/dwarf.rs @@ -208,6 +208,16 @@ where if let (Some(start), Some(end)) = (unit.start_address, unit.end_address) { writeln!(w, " Code range: {:#010X} -> {:#010X}", start, end)?; } + if let Some(gcc_srcfile_name_offset) = unit.gcc_srcfile_name_offset { + writeln!( + w, + " GCC Source File Name Offset: {:#010X}", + gcc_srcfile_name_offset + )?; + } + if let Some(gcc_srcinfo_offset) = unit.gcc_srcinfo_offset { + writeln!(w, " GCC Source Info Offset: {:#010X}", gcc_srcinfo_offset)?; + } writeln!(w, "*/")?; let children = tag.children(&info.tags); diff --git a/src/util/dwarf.rs b/src/util/dwarf.rs index 863c2c2..0e63b65 100644 --- a/src/util/dwarf.rs +++ b/src/util/dwarf.rs @@ -312,8 +312,8 @@ pub enum AttributeKind { MwLocalSpoffset = 0x2310 | (FormKind::Block4 as u16), MwMips16 = 0x2330 | (FormKind::String as u16), MwDwarf2Location = 0x2340 | (FormKind::Block2 as u16), - Unknown800 = 0x8000 | (FormKind::Data4 as u16), - Unknown801 = 0x8010 | (FormKind::Data4 as u16), + GccSfName = 0x8000 | (FormKind::Data4 as u16), // GccSfName extension (offset into .debug_sfnames) + GccSfInfo = 0x8010 | (FormKind::Data4 as u16), // GccSfInfo extension (offset into .debug_srcinfo) MwPrologueEnd = 0x8040 | (FormKind::Addr as u16), MwEpilogueStart = 0x8050 | (FormKind::Addr as u16), } @@ -771,6 +771,8 @@ pub enum Language { Fortran90 = 0x8, Pascal83 = 0x9, Modula2 = 0xa, + // MWCC asm extension, emitted by PS2 MWCC asm_r5900_elf.dll + MwAsm = 0x8000, } impl Display for Language { @@ -786,6 +788,7 @@ impl Display for Language { Language::Fortran90 => write!(f, "Fortran90"), Language::Pascal83 => write!(f, "Pascal83"), Language::Modula2 => write!(f, "Modula2"), + Language::MwAsm => write!(f, "MwAsm"), } } } @@ -798,6 +801,8 @@ pub struct CompileUnit { pub language: Option, pub start_address: Option, pub end_address: Option, + pub gcc_srcfile_name_offset: Option, + pub gcc_srcinfo_offset: Option, } #[derive(Debug, Clone)] @@ -2541,6 +2546,8 @@ pub fn process_compile_unit(tag: &Tag) -> Result { let mut language = None; let mut start_address = None; let mut end_address = None; + let mut gcc_srcfile_name_offset = None; + let mut gcc_srcinfo_offset = None; for attr in &tag.attributes { match (attr.kind, &attr.value) { (AttributeKind::Sibling, _) => {} @@ -2552,14 +2559,15 @@ pub fn process_compile_unit(tag: &Tag) -> Result { } (AttributeKind::LowPc, &AttributeValue::Address(addr)) => start_address = Some(addr), (AttributeKind::HighPc, &AttributeValue::Address(addr)) => end_address = Some(addr), - (AttributeKind::StmtList, AttributeValue::Data4(_)) => { + (AttributeKind::StmtList, AttributeValue::Data4(_value)) => { // TODO .line support } - (AttributeKind::Unknown800, AttributeValue::Data4(_)) => { - // TODO Unknown800 support + + (AttributeKind::GccSfName, &AttributeValue::Data4(value)) => { + gcc_srcfile_name_offset = Some(value) } - (AttributeKind::Unknown801, AttributeValue::Data4(_)) => { - // TODO Unknown801 support + (AttributeKind::GccSfInfo, &AttributeValue::Data4(value)) => { + gcc_srcinfo_offset = Some(value) } _ => { bail!("Unhandled CompileUnit attribute {:?}", attr); @@ -2568,7 +2576,16 @@ pub fn process_compile_unit(tag: &Tag) -> Result { } let name = name.ok_or_else(|| anyhow!("CompileUnit without Name: {:?}", tag))?; - Ok(CompileUnit { name, producer, comp_dir, language, start_address, end_address }) + Ok(CompileUnit { + name, + producer, + comp_dir, + language, + start_address, + end_address, + gcc_srcfile_name_offset, + gcc_srcinfo_offset, + }) } pub fn process_overlay_branch(tag: &Tag) -> Result { @@ -2587,6 +2604,9 @@ pub fn process_overlay_branch(tag: &Tag) -> Result { (AttributeKind::MwOverlayId, AttributeValue::Data4(value)) => id = Some(*value), (AttributeKind::LowPc, &AttributeValue::Address(addr)) => start_address = Some(addr), (AttributeKind::HighPc, &AttributeValue::Address(addr)) => end_address = Some(addr), + (AttributeKind::Name, AttributeValue::String(_s)) => { + // TODO + } _ => bail!("Unhandled OverlayBranch attribute {:?}", attr), } }