From b3b8c126d37143114f1799e727d450bd128bbc87 Mon Sep 17 00:00:00 2001 From: Ryan Mansfield Date: Tue, 20 Jan 2026 13:01:33 -0500 Subject: [PATCH] Warn when split DWARF files are missing When analyzing binaries with split DWARF (DW_AT_GNU_dwo_name), skip missing .dwo files with a warning instead of erroring. This allows analyzing binaries built on other machines or from SDKs where .dwo files may not be locally available, while still alerting the user that the analysis is incomplete. --- src/dwarf.cc | 6 ++ tests/dwarf/debug_info/missing-dwo-file.test | 66 ++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 tests/dwarf/debug_info/missing-dwo-file.test diff --git a/src/dwarf.cc b/src/dwarf.cc index 1d1603d..eb68bc1 100644 --- a/src/dwarf.cc +++ b/src/dwarf.cc @@ -668,6 +668,12 @@ static void ReadDWARFDebugInfo(dwarf::InfoReader& reader, std::string dwo_path = ConstructDwoPath(dwo_info); if (!dwo_path.empty() && &cu == &cu.skeleton()) { + // Check if DWO file exists before trying to open it + if (!std::filesystem::exists(dwo_path)) { + fprintf(stderr, "Warning: DWO file not found: %s\n", dwo_path.c_str()); + continue; + } + auto file = MmapInputFileFactory().OpenFile(dwo_path); dwarf::File dwo_dwarf; cu.dwarf().open(*file, &dwo_dwarf, sink); diff --git a/tests/dwarf/debug_info/missing-dwo-file.test b/tests/dwarf/debug_info/missing-dwo-file.test new file mode 100644 index 0000000..a2578e8 --- /dev/null +++ b/tests/dwarf/debug_info/missing-dwo-file.test @@ -0,0 +1,66 @@ +# Test that missing .dwo files produce a warning but don't fail analysis. + +# RUN: %yaml2obj %s -o %t.obj +# RUN: %bloaty %t.obj -d compileunits 2>&1 | %FileCheck %s + +# CHECK: Warning: DWO file not found: /nonexistent/path/missing.dwo + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_X86_64 +ProgramHeaders: + - Type: PT_LOAD + Flags: [ PF_X, PF_R ] + FirstSec: .text + LastSec: .text + VAddr: 0x1000 + Align: 0x1000 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x1000 + AddressAlign: 0x10 + Size: 0x50 + - Name: .debug_addr + Type: SHT_PROGBITS + AddressAlign: 0x1 + Content: '0010000000000000' +DWARF: + debug_str: + - /nonexistent/path/missing.dwo + - /some/comp/dir + debug_abbrev: + - ID: 0 + Table: + - Code: 0x1 + Tag: DW_TAG_compile_unit + Children: DW_CHILDREN_no + Attributes: + - Attribute: DW_AT_comp_dir + Form: DW_FORM_strp + - Attribute: DW_AT_GNU_dwo_name + Form: DW_FORM_strp + - Attribute: DW_AT_GNU_dwo_id + Form: DW_FORM_data8 + - Attribute: DW_AT_GNU_addr_base + Form: DW_FORM_sec_offset + debug_info: + - Version: 4 + AbbrevTableID: 0 + AbbrOffset: 0x0 + AddrSize: 8 + Entries: + - AbbrCode: 0x1 + Values: + # comp_dir offset (points to "/some/comp/dir") + - Value: 0x22 + # dwo_name offset (points to "/nonexistent/path/missing.dwo") + - Value: 0x0 + # dwo_id + - Value: 0x1234567890abcdef + # addr_base + - Value: 0x0