From: Xing GUO Date: Fri, 31 Jul 2020 12:02:20 +0000 (+0800) Subject: [DWARFYAML] Add emitDebug[GNU]Pub[names/types] functions. NFC. X-Git-Tag: llvmorg-13-init~16174 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cbf5bf513b93cc5bfa360f4be8a57e50988e22f1;p=platform%2Fupstream%2Fllvm.git [DWARFYAML] Add emitDebug[GNU]Pub[names/types] functions. NFC. In this patch, emitDebugPubnames(), emitDebugPubtypes(), emitDebugGNUPubnames(), emitDebugGNUPubtypes() are added. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D85003 --- diff --git a/llvm/include/llvm/ObjectYAML/DWARFEmitter.h b/llvm/include/llvm/ObjectYAML/DWARFEmitter.h index 5837c69..5c29b0e 100644 --- a/llvm/include/llvm/ObjectYAML/DWARFEmitter.h +++ b/llvm/include/llvm/ObjectYAML/DWARFEmitter.h @@ -33,8 +33,10 @@ Error emitDebugStr(raw_ostream &OS, const Data &DI); Error emitDebugAranges(raw_ostream &OS, const Data &DI); Error emitDebugRanges(raw_ostream &OS, const Data &DI); -Error emitPubSection(raw_ostream &OS, const PubSection &Sect, - bool IsLittleEndian, bool IsGNUPubSec = false); +Error emitDebugPubnames(raw_ostream &OS, const Data &DI); +Error emitDebugPubtypes(raw_ostream &OS, const Data &DI); +Error emitDebugGNUPubnames(raw_ostream &OS, const Data &DI); +Error emitDebugGNUPubtypes(raw_ostream &OS, const Data &DI); Error emitDebugInfo(raw_ostream &OS, const Data &DI); Error emitDebugLine(raw_ostream &OS, const Data &DI); Error emitDebugAddr(raw_ostream &OS, const Data &DI); diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp index be9581f..9655b05 100644 --- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp +++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp @@ -209,9 +209,8 @@ Error DWARFYAML::emitDebugRanges(raw_ostream &OS, const DWARFYAML::Data &DI) { return Error::success(); } -Error DWARFYAML::emitPubSection(raw_ostream &OS, - const DWARFYAML::PubSection &Sect, - bool IsLittleEndian, bool IsGNUPubSec) { +static Error emitPubSection(raw_ostream &OS, const DWARFYAML::PubSection &Sect, + bool IsLittleEndian, bool IsGNUPubSec = false) { writeInitialLength(Sect.Length, OS, IsLittleEndian); writeInteger((uint16_t)Sect.Version, OS, IsLittleEndian); writeInteger((uint32_t)Sect.UnitOffset, OS, IsLittleEndian); @@ -227,6 +226,28 @@ Error DWARFYAML::emitPubSection(raw_ostream &OS, return Error::success(); } +Error DWARFYAML::emitDebugPubnames(raw_ostream &OS, const Data &DI) { + assert(DI.PubNames && "unexpected emitDebugPubnames() call"); + return emitPubSection(OS, *DI.PubNames, DI.IsLittleEndian); +} + +Error DWARFYAML::emitDebugPubtypes(raw_ostream &OS, const Data &DI) { + assert(DI.PubTypes && "unexpected emitDebugPubtypes() call"); + return emitPubSection(OS, *DI.PubTypes, DI.IsLittleEndian); +} + +Error DWARFYAML::emitDebugGNUPubnames(raw_ostream &OS, const Data &DI) { + assert(DI.GNUPubNames && "unexpected emitDebugGNUPubnames() call"); + return emitPubSection(OS, *DI.GNUPubNames, DI.IsLittleEndian, + /*IsGNUStyle=*/true); +} + +Error DWARFYAML::emitDebugGNUPubtypes(raw_ostream &OS, const Data &DI) { + assert(DI.GNUPubTypes && "unexpected emitDebugGNUPubtypes() call"); + return emitPubSection(OS, *DI.GNUPubTypes, DI.IsLittleEndian, + /*IsGNUStyle=*/true); +} + static Expected writeDIE(ArrayRef AbbrevDecls, const DWARFYAML::Unit &Unit, const DWARFYAML::Entry &Entry, diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp index bc27c03..9fefd8c 100644 --- a/llvm/lib/ObjectYAML/ELFEmitter.cpp +++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -967,15 +967,13 @@ Expected emitDWARF(typename ELFT::Shdr &SHeader, StringRef Name, else if (Name == ".debug_info") Err = DWARFYAML::emitDebugInfo(*OS, DWARF); else if (Name == ".debug_pubnames") - Err = DWARFYAML::emitPubSection(*OS, *DWARF.PubNames, DWARF.IsLittleEndian); + Err = DWARFYAML::emitDebugPubnames(*OS, DWARF); else if (Name == ".debug_pubtypes") - Err = DWARFYAML::emitPubSection(*OS, *DWARF.PubTypes, DWARF.IsLittleEndian); + Err = DWARFYAML::emitDebugPubtypes(*OS, DWARF); else if (Name == ".debug_gnu_pubnames") - Err = DWARFYAML::emitPubSection(*OS, *DWARF.GNUPubNames, - DWARF.IsLittleEndian, /*IsGNUStyle=*/true); + Err = DWARFYAML::emitDebugGNUPubnames(*OS, DWARF); else if (Name == ".debug_gnu_pubtypes") - Err = DWARFYAML::emitPubSection(*OS, *DWARF.GNUPubTypes, - DWARF.IsLittleEndian, /*IsGNUStyle=*/true); + Err = DWARFYAML::emitDebugGNUPubtypes(*OS, DWARF); else if (Name == ".debug_str_offsets") Err = DWARFYAML::emitDebugStrOffsets(*OS, DWARF); else if (Name == ".debug_rnglists") diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp b/llvm/lib/ObjectYAML/MachOEmitter.cpp index 6802644..619572a 100644 --- a/llvm/lib/ObjectYAML/MachOEmitter.cpp +++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp @@ -299,12 +299,10 @@ Error MachOWriter::writeSectionData(raw_ostream &OS) { Err = DWARFYAML::emitDebugRanges(OS, Obj.DWARF); else if (0 == strncmp(&Sec.sectname[0], "__debug_pubnames", 16)) { if (Obj.DWARF.PubNames) - Err = DWARFYAML::emitPubSection(OS, *Obj.DWARF.PubNames, - Obj.IsLittleEndian); + Err = DWARFYAML::emitDebugPubnames(OS, Obj.DWARF); } else if (0 == strncmp(&Sec.sectname[0], "__debug_pubtypes", 16)) { if (Obj.DWARF.PubTypes) - Err = DWARFYAML::emitPubSection(OS, *Obj.DWARF.PubTypes, - Obj.IsLittleEndian); + Err = DWARFYAML::emitDebugPubtypes(OS, Obj.DWARF); } else if (0 == strncmp(&Sec.sectname[0], "__debug_info", 16)) Err = DWARFYAML::emitDebugInfo(OS, Obj.DWARF); else if (0 == strncmp(&Sec.sectname[0], "__debug_line", 16))