Skip to content

Commit d6c3340

Browse files
committed
Fix PS2 MWCC line number parsing
1 parent 2cd1e2e commit d6c3340

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

objdiff-core/src/obj/read.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,11 @@ fn parse_line_info(
732732

733733
/// Parse .line section from DWARF 1.1 format.
734734
fn parse_line_info_dwarf1(obj_file: &object::File, sections: &mut [Section]) -> Result<()> {
735-
if let Some(section) = obj_file.section_by_name(".line") {
735+
let mut text_sections = sections.iter_mut().filter(|s| s.kind == SectionKind::Code);
736+
for section in obj_file.sections().filter(|s| s.name().is_ok_and(|n| n == ".line")) {
736737
let data = section.uncompressed_data()?;
737738
let mut reader: &[u8] = data.as_ref();
738739

739-
let mut text_sections = sections.iter_mut().filter(|s| s.kind == SectionKind::Code);
740740
while !reader.is_empty() {
741741
let mut section_data = reader;
742742
let size = read_u32(obj_file, &mut section_data)? as usize;

objdiff-core/tests/arch_mips.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,25 @@ fn ido_mdebug_line_numbers() {
8080
assert_eq!(text_section.line_info.get(&56), Some(&9));
8181
assert_eq!(text_section.line_info.len(), 66);
8282
}
83+
84+
#[test]
85+
#[cfg(feature = "mips")]
86+
fn mwcc_dwarf1_line_numbers_multiple_functions() {
87+
let diff_config = diff::DiffObjConfig::default();
88+
let obj = obj::read::parse(
89+
include_object!("data/mips/mwcc_lines_example.o"),
90+
&diff_config,
91+
diff::DiffSide::Base,
92+
)
93+
.unwrap();
94+
95+
for function_name in ["foo", "bar"] {
96+
let symbol = obj.symbols.iter().find(|s| s.name == function_name).unwrap();
97+
let section_idx = symbol.section.unwrap();
98+
let section = &obj.sections[section_idx];
99+
assert!(
100+
section.line_info.values().any(|line| *line > 0),
101+
"{function_name} should have valid line numbers"
102+
);
103+
}
104+
}
3.54 KB
Binary file not shown.

0 commit comments

Comments
 (0)