Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/ObjectYAML/DWARFEmitter.cpp
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | for (auto Str : DI.DebugStrings) { | ||||
OS.write('\0'); | OS.write('\0'); | ||||
} | } | ||||
return Error::success(); | return Error::success(); | ||||
} | } | ||||
Error DWARFYAML::emitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) { | Error DWARFYAML::emitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) { | ||||
uint64_t AbbrevCode = 0; | uint64_t AbbrevCode = 0; | ||||
for (auto AbbrevDecl : DI.AbbrevDecls) { | for (const DWARFYAML::AbbrevTable &AbbrevTable : DI.DebugAbbrev) { | ||||
AbbrevCode = AbbrevDecl.Code ? (uint64_t)*AbbrevDecl.Code : AbbrevCode + 1; | for (const DWARFYAML::Abbrev &AbbrevDecl : AbbrevTable.Table) { | ||||
jhenderson: Don't use `auto` here. It's not obvious what the type is. | |||||
AbbrevCode = | |||||
AbbrevDecl.Code ? (uint64_t)*AbbrevDecl.Code : AbbrevCode + 1; | |||||
encodeULEB128(AbbrevCode, OS); | encodeULEB128(AbbrevCode, OS); | ||||
encodeULEB128(AbbrevDecl.Tag, OS); | encodeULEB128(AbbrevDecl.Tag, OS); | ||||
OS.write(AbbrevDecl.Children); | OS.write(AbbrevDecl.Children); | ||||
for (auto Attr : AbbrevDecl.Attributes) { | for (auto Attr : AbbrevDecl.Attributes) { | ||||
encodeULEB128(Attr.Attribute, OS); | encodeULEB128(Attr.Attribute, OS); | ||||
encodeULEB128(Attr.Form, OS); | encodeULEB128(Attr.Form, OS); | ||||
if (Attr.Form == dwarf::DW_FORM_implicit_const) | if (Attr.Form == dwarf::DW_FORM_implicit_const) | ||||
encodeSLEB128(Attr.Value, OS); | encodeSLEB128(Attr.Value, OS); | ||||
} | } | ||||
encodeULEB128(0, OS); | encodeULEB128(0, OS); | ||||
encodeULEB128(0, OS); | encodeULEB128(0, OS); | ||||
} | } | ||||
// The abbreviations for a given compilation unit end with an entry consisting | // The abbreviations for a given compilation unit end with an entry | ||||
// of a 0 byte for the abbreviation code. | // consisting of a 0 byte for the abbreviation code. | ||||
OS.write_zeros(1); | OS.write_zeros(1); | ||||
} | |||||
return Error::success(); | return Error::success(); | ||||
} | } | ||||
Error DWARFYAML::emitDebugAranges(raw_ostream &OS, const DWARFYAML::Data &DI) { | Error DWARFYAML::emitDebugAranges(raw_ostream &OS, const DWARFYAML::Data &DI) { | ||||
assert(DI.DebugAranges && "unexpected emitDebugAranges() call"); | assert(DI.DebugAranges && "unexpected emitDebugAranges() call"); | ||||
for (auto Range : *DI.DebugAranges) { | for (auto Range : *DI.DebugAranges) { | ||||
uint8_t AddrSize; | uint8_t AddrSize; | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
Error DWARFYAML::emitDebugGNUPubtypes(raw_ostream &OS, const Data &DI) { | Error DWARFYAML::emitDebugGNUPubtypes(raw_ostream &OS, const Data &DI) { | ||||
assert(DI.GNUPubTypes && "unexpected emitDebugGNUPubtypes() call"); | assert(DI.GNUPubTypes && "unexpected emitDebugGNUPubtypes() call"); | ||||
return emitPubSection(OS, *DI.GNUPubTypes, DI.IsLittleEndian, | return emitPubSection(OS, *DI.GNUPubTypes, DI.IsLittleEndian, | ||||
/*IsGNUStyle=*/true); | /*IsGNUStyle=*/true); | ||||
} | } | ||||
static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls, | static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::AbbrevTable> AbbrevTable, | ||||
const dwarf::FormParams &Params, | const dwarf::FormParams &Params, | ||||
const DWARFYAML::Entry &Entry, | const DWARFYAML::Entry &Entry, | ||||
raw_ostream &OS, bool IsLittleEndian) { | raw_ostream &OS, bool IsLittleEndian) { | ||||
uint64_t EntryBegin = OS.tell(); | uint64_t EntryBegin = OS.tell(); | ||||
encodeULEB128(Entry.AbbrCode, OS); | encodeULEB128(Entry.AbbrCode, OS); | ||||
uint32_t AbbrCode = Entry.AbbrCode; | uint32_t AbbrCode = Entry.AbbrCode; | ||||
if (AbbrCode == 0 || Entry.Values.empty()) | if (AbbrCode == 0 || Entry.Values.empty()) | ||||
return OS.tell() - EntryBegin; | return OS.tell() - EntryBegin; | ||||
if (AbbrevTable.empty()) | |||||
return createStringError( | |||||
errc::invalid_argument, | |||||
"non-empty compilation unit should have an associated abbrev table"); | |||||
ArrayRef<DWARFYAML::Abbrev> AbbrevDecls(AbbrevTable[0].Table); | |||||
Some DIEs only have abbrev codes and do not have values. If we do this work in the caller of this function, yaml2obj will reject empty DIEs. Higuoxing: >>! Comments from [D83116](https://reviews.llvm.org/D83116#inline-795444)
> @jhenderson : It… | |||||
if (AbbrCode > AbbrevDecls.size()) | if (AbbrCode > AbbrevDecls.size()) | ||||
return createStringError( | return createStringError( | ||||
errc::invalid_argument, | errc::invalid_argument, | ||||
"abbrev code must be less than or equal to the number of " | "abbrev code must be less than or equal to the number of " | ||||
"entries in abbreviation table"); | "entries in abbreviation table"); | ||||
const DWARFYAML::Abbrev &Abbrev = AbbrevDecls[AbbrCode - 1]; | const DWARFYAML::Abbrev &Abbrev = AbbrevDecls[AbbrCode - 1]; | ||||
auto FormVal = Entry.Values.begin(); | auto FormVal = Entry.Values.begin(); | ||||
auto AbbrForm = Abbrev.Attributes.begin(); | auto AbbrForm = Abbrev.Attributes.begin(); | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | for (const DWARFYAML::Unit &Unit : DI.CompileUnits) { | ||||
// firstly write the content of the compilation unit to a buffer to | // firstly write the content of the compilation unit to a buffer to | ||||
// calculate it and then serialize the buffer content to the actual output | // calculate it and then serialize the buffer content to the actual output | ||||
// stream. | // stream. | ||||
std::string EntryBuffer; | std::string EntryBuffer; | ||||
raw_string_ostream EntryBufferOS(EntryBuffer); | raw_string_ostream EntryBufferOS(EntryBuffer); | ||||
for (const DWARFYAML::Entry &Entry : Unit.Entries) { | for (const DWARFYAML::Entry &Entry : Unit.Entries) { | ||||
if (Expected<uint64_t> EntryLength = writeDIE( | if (Expected<uint64_t> EntryLength = writeDIE( | ||||
DI.AbbrevDecls, Params, Entry, EntryBufferOS, DI.IsLittleEndian)) | DI.DebugAbbrev, Params, Entry, EntryBufferOS, DI.IsLittleEndian)) | ||||
Length += *EntryLength; | Length += *EntryLength; | ||||
else | else | ||||
return EntryLength.takeError(); | return EntryLength.takeError(); | ||||
} | } | ||||
// If the length is specified in the YAML description, we use it instead of | // If the length is specified in the YAML description, we use it instead of | ||||
// the actual length. | // the actual length. | ||||
if (Unit.Length) | if (Unit.Length) | ||||
▲ Show 20 Lines • Show All 569 Lines • Show Last 20 Lines |
Don't use auto here. It's not obvious what the type is.