diff --git a/include/llvm/ObjectYAML/DWARFYAML.h b/include/llvm/ObjectYAML/DWARFYAML.h index 08b02691ffc..7b2f28db1f0 100644 --- a/include/llvm/ObjectYAML/DWARFYAML.h +++ b/include/llvm/ObjectYAML/DWARFYAML.h @@ -83,7 +83,7 @@ struct RangeEntry { /// Class that describes a single range list inside the .debug_ranges section. struct Ranges { Optional Offset; - llvm::yaml::Hex8 AddrSize; + Optional AddrSize; std::vector Entries; }; @@ -162,6 +162,7 @@ struct LineTable { struct Data { bool IsLittleEndian; + bool Is64bit; std::vector AbbrevDecls; std::vector DebugStrings; std::vector ARanges; diff --git a/lib/ObjectYAML/DWARFEmitter.cpp b/lib/ObjectYAML/DWARFEmitter.cpp index 9ab6aa5aeaf..b373cfceff2 100644 --- a/lib/ObjectYAML/DWARFEmitter.cpp +++ b/lib/ObjectYAML/DWARFEmitter.cpp @@ -148,13 +148,19 @@ Error DWARFYAML::emitDebugRanges(raw_ostream &OS, const DWARFYAML::Data &DI) { Twine::utohexstr(CurrOffset) + ")"); if (DebugRanges.Offset) ZeroFillBytes(OS, *DebugRanges.Offset - CurrOffset); + + uint8_t AddrSize; + if (DebugRanges.AddrSize) + AddrSize = *DebugRanges.AddrSize; + else + AddrSize = DI.Is64bit ? 8 : 4; for (auto Entry : DebugRanges.Entries) { - writeVariableSizedInteger(Entry.LowOffset, DebugRanges.AddrSize, OS, + writeVariableSizedInteger(Entry.LowOffset, AddrSize, OS, DI.IsLittleEndian); - writeVariableSizedInteger(Entry.HighOffset, DebugRanges.AddrSize, OS, + writeVariableSizedInteger(Entry.HighOffset, AddrSize, OS, DI.IsLittleEndian); } - ZeroFillBytes(OS, DebugRanges.AddrSize * 2); + ZeroFillBytes(OS, AddrSize * 2); ++EntryIndex; } diff --git a/lib/ObjectYAML/DWARFYAML.cpp b/lib/ObjectYAML/DWARFYAML.cpp index 8298047d8be..bfb29181e3c 100644 --- a/lib/ObjectYAML/DWARFYAML.cpp +++ b/lib/ObjectYAML/DWARFYAML.cpp @@ -97,7 +97,7 @@ void MappingTraits::mapping( void MappingTraits::mapping(IO &IO, DWARFYAML::Ranges &DebugRanges) { IO.mapOptional("Offset", DebugRanges.Offset); - IO.mapRequired("AddrSize", DebugRanges.AddrSize); + IO.mapOptional("AddrSize", DebugRanges.AddrSize); IO.mapRequired("Entries", DebugRanges.Entries); } diff --git a/lib/ObjectYAML/ELFYAML.cpp b/lib/ObjectYAML/ELFYAML.cpp index 87f4eea126a..84fbdb01365 100644 --- a/lib/ObjectYAML/ELFYAML.cpp +++ b/lib/ObjectYAML/ELFYAML.cpp @@ -1655,9 +1655,12 @@ void MappingTraits::mapping(IO &IO, ELFYAML::Object &Object) { IO.mapOptional("Symbols", Object.Symbols); IO.mapOptional("DynamicSymbols", Object.DynamicSymbols); IO.mapOptional("DWARF", Object.DWARF); - if (Object.DWARF) + if (Object.DWARF) { Object.DWARF->IsLittleEndian = Object.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB); + Object.DWARF->Is64bit = + Object.Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64); + } IO.setContext(nullptr); } diff --git a/lib/ObjectYAML/MachOYAML.cpp b/lib/ObjectYAML/MachOYAML.cpp index a5341383e8a..cd9ca76f5d2 100644 --- a/lib/ObjectYAML/MachOYAML.cpp +++ b/lib/ObjectYAML/MachOYAML.cpp @@ -107,6 +107,8 @@ void MappingTraits::mapping(IO &IO, Object.DWARF.IsLittleEndian = Object.IsLittleEndian; IO.mapRequired("FileHeader", Object.Header); + Object.DWARF.Is64bit = Object.Header.magic == MachO::MH_MAGIC_64 || + Object.Header.magic == MachO::MH_CIGAM_64; IO.mapOptional("LoadCommands", Object.LoadCommands); if(!Object.LinkEdit.isEmpty() || !IO.outputting()) IO.mapOptional("LinkEditData", Object.LinkEdit); diff --git a/test/tools/obj2yaml/macho-DWARF-debug-ranges.yaml b/test/tools/obj2yaml/macho-DWARF-debug-ranges.yaml index be1a52a22ef..fe972a0fb40 100644 --- a/test/tools/obj2yaml/macho-DWARF-debug-ranges.yaml +++ b/test/tools/obj2yaml/macho-DWARF-debug-ranges.yaml @@ -203,7 +203,6 @@ DWARF: Form: DW_FORM_addr debug_ranges: - Offset: 0x00000000 - AddrSize: 0x08 Entries: - LowOffset: 0x0000000000000000 HighOffset: 0x0000000000000020 diff --git a/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml b/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml index db8eb89be7d..adaceeeae8a 100644 --- a/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml +++ b/test/tools/yaml2obj/ELF/DWARF/debug-ranges.yaml @@ -84,8 +84,7 @@ DWARF: HighOffset: 0x00000010 - LowOffset: 0x00000000 HighOffset: 0x00000000 - - AddrSize: 0x08 - Entries: + - Entries: - LowOffset: 0x0000000000000010 HighOffset: 0x0000000000000020 - LowOffset: 0x0000000000000030 @@ -207,8 +206,7 @@ Sections: Size: 0x10 DWARF: debug_ranges: - - AddrSize: 0x08 - Entries: + - Entries: - LowOffset: 0x0000000000000001 HighOffset: 0x0000000000000002 @@ -229,8 +227,7 @@ Sections: Content: "00" DWARF: debug_ranges: - - AddrSize: 0x08 - Entries: + - Entries: - LowOffset: 0x0000000000000001 HighOffset: 0x0000000000000002 @@ -290,8 +287,7 @@ Sections: Type: SHT_STRTAB DWARF: debug_ranges: - - AddrSize: 0x08 - Entries: + - Entries: - LowOffset: 0x0000000000000001 HighOffset: 0x0000000000000002 @@ -345,17 +341,14 @@ FileHeader: Machine: EM_X86_64 DWARF: debug_ranges: - - AddrSize: 0x08 - Entries: + - Entries: - LowOffset: 0x01 HighOffset: 0x02 - Offset: 0x21 ## There are 0x20 bytes before this entry. - AddrSize: 0x08 Entries: - LowOffset: 0x01 HighOffset: 0x02 - Offset: 0x41 ## There are 0x41 bytes before this entry. - AddrSize: 0x08 Entries: - LowOffset: 0x01 HighOffset: 0x02 @@ -375,12 +368,10 @@ FileHeader: Machine: EM_X86_64 DWARF: debug_ranges: - - AddrSize: 0x08 - Entries: + - Entries: - LowOffset: 0x01 HighOffset: 0x02 - Offset: 0x1F ## Must be greater than or equal to 0x20. - AddrSize: 0x08 Entries: - LowOffset: 0x01 HighOffset: 0x02