diff --git a/llvm/test/tools/obj2yaml/ELF/DWARF/unrecognized-debug-section.yaml b/llvm/test/tools/obj2yaml/ELF/DWARF/unrecognized-debug-section.yaml new file mode 100644 --- /dev/null +++ b/llvm/test/tools/obj2yaml/ELF/DWARF/unrecognized-debug-section.yaml @@ -0,0 +1,19 @@ +## Test dumping a debug section that its name is not recognized by yaml2obj. + +# RUN: yaml2obj %s | obj2yaml | FileCheck %s --check-prefix=UNRECOGNIZED + +# UNRECOGNIZED: Sections: +# UNRECOGNIZED-NEXT: - Name: .debug_foo +# UNRECOGNIZED-NEXT: Type: SHT_PROGBITS +# UNRECOGNIZED-NEXT: Content: '01020304' +# UNRECOGNIZED-NEXT: ... + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC +Sections: + - Name: .debug_foo + Type: SHT_PROGBITS + Content: '01020304' diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp --- a/llvm/tools/obj2yaml/elf2yaml.cpp +++ b/llvm/tools/obj2yaml/elf2yaml.cpp @@ -15,6 +15,7 @@ #include "llvm/ObjectYAML/DWARFYAML.h" #include "llvm/ObjectYAML/ELFYAML.h" #include "llvm/Support/DataExtractor.h" +#include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/YAMLTraits.h" @@ -416,6 +417,11 @@ Err = dumpDebugARanges(*DWARFCtx.get(), DWARF); else if (RawSec->Name == ".debug_str") Err = dumpDebugStrings(*DWARFCtx.get(), DWARF); + else + Err = + createStringError(errc::not_supported, + "the parser for the %s section is not supported", + RawSec->Name.str().c_str()); // If the DWARF section cannot be successfully parsed, emit raw content // instead of an entry in the DWARF section of the YAML.