Skip to content

Commit 4357986

Browse files
committed
[DWARFYAML][debug_info] Pull out dwarf::FormParams from DWARFYAML::Unit.
Unit.Format, Unit.Version and Unit.AddrSize are replaced with dwarf::FormParams in D84496 to get rid of unnecessary functions getOffsetSize() and getRefSize(). However, that change makes it difficult to make AddrSize optional (Optional<uint8_t>). This change pulls out dwarf::FormParams from DWARFYAML::Unit and use it as a helper struct in DWARFYAML::emitDebugInfo(). Reviewed By: jhenderson, MaskRay Differential Revision: https://reviews.llvm.org/D85296
1 parent 6148cca commit 4357986

File tree

4 files changed

+31
-32
lines changed

4 files changed

+31
-32
lines changed

llvm/include/llvm/ObjectYAML/DWARFYAML.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ struct DWARFContext {
120120
};
121121

122122
struct Unit {
123-
dwarf::FormParams FormParams;
123+
dwarf::DwarfFormat Format;
124124
Optional<yaml::Hex64> Length;
125+
uint16_t Version;
126+
uint8_t AddrSize;
125127
llvm::dwarf::UnitType Type; // Added in DWARF 5
126128
yaml::Hex64 AbbrOffset;
127129
std::vector<Entry> Entries;

llvm/lib/ObjectYAML/DWARFEmitter.cpp

+20-23
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ Error DWARFYAML::emitDebugGNUPubtypes(raw_ostream &OS, const Data &DI) {
251251
}
252252

253253
static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
254-
const DWARFYAML::Unit &Unit,
254+
const dwarf::FormParams &Params,
255255
const DWARFYAML::Entry &Entry,
256256
raw_ostream &OS, bool IsLittleEndian) {
257257
uint64_t EntryBegin = OS.tell();
@@ -278,14 +278,14 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
278278
case dwarf::DW_FORM_addr:
279279
// TODO: Test this error.
280280
if (Error Err = writeVariableSizedInteger(
281-
FormVal->Value, Unit.FormParams.AddrSize, OS, IsLittleEndian))
281+
FormVal->Value, Params.AddrSize, OS, IsLittleEndian))
282282
return std::move(Err);
283283
break;
284284
case dwarf::DW_FORM_ref_addr:
285285
// TODO: Test this error.
286-
if (Error Err = writeVariableSizedInteger(
287-
FormVal->Value, Unit.FormParams.getRefAddrByteSize(), OS,
288-
IsLittleEndian))
286+
if (Error Err = writeVariableSizedInteger(FormVal->Value,
287+
Params.getRefAddrByteSize(),
288+
OS, IsLittleEndian))
289289
return std::move(Err);
290290
break;
291291
case dwarf::DW_FORM_exprloc:
@@ -367,9 +367,9 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
367367
case dwarf::DW_FORM_GNU_strp_alt:
368368
case dwarf::DW_FORM_line_strp:
369369
case dwarf::DW_FORM_strp_sup:
370-
cantFail(writeVariableSizedInteger(
371-
FormVal->Value, Unit.FormParams.getDwarfOffsetByteSize(), OS,
372-
IsLittleEndian));
370+
cantFail(writeVariableSizedInteger(FormVal->Value,
371+
Params.getDwarfOffsetByteSize(), OS,
372+
IsLittleEndian));
373373
break;
374374
default:
375375
break;
@@ -382,10 +382,10 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
382382

383383
Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
384384
for (const DWARFYAML::Unit &Unit : DI.CompileUnits) {
385+
dwarf::FormParams Params = {Unit.Version, Unit.AddrSize, Unit.Format};
385386
uint64_t Length = 3; // sizeof(version) + sizeof(address_size)
386-
Length += Unit.FormParams.Version >= 5 ? 1 : 0; // sizeof(unit_type)
387-
Length +=
388-
Unit.FormParams.getDwarfOffsetByteSize(); // sizeof(debug_abbrev_offset)
387+
Length += Unit.Version >= 5 ? 1 : 0; // sizeof(unit_type)
388+
Length += Params.getDwarfOffsetByteSize(); // sizeof(debug_abbrev_offset)
389389

390390
// Since the length of the current compilation unit is undetermined yet, we
391391
// firstly write the content of the compilation unit to a buffer to
@@ -396,7 +396,7 @@ Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
396396

397397
for (const DWARFYAML::Entry &Entry : Unit.Entries) {
398398
if (Expected<uint64_t> EntryLength = writeDIE(
399-
DI.AbbrevDecls, Unit, Entry, EntryBufferOS, DI.IsLittleEndian))
399+
DI.AbbrevDecls, Params, Entry, EntryBufferOS, DI.IsLittleEndian))
400400
Length += *EntryLength;
401401
else
402402
return EntryLength.takeError();
@@ -407,17 +407,15 @@ Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
407407
if (Unit.Length)
408408
Length = *Unit.Length;
409409

410-
writeInitialLength(Unit.FormParams.Format, Length, OS, DI.IsLittleEndian);
411-
writeInteger((uint16_t)Unit.FormParams.Version, OS, DI.IsLittleEndian);
412-
if (Unit.FormParams.Version >= 5) {
410+
writeInitialLength(Unit.Format, Length, OS, DI.IsLittleEndian);
411+
writeInteger((uint16_t)Unit.Version, OS, DI.IsLittleEndian);
412+
if (Unit.Version >= 5) {
413413
writeInteger((uint8_t)Unit.Type, OS, DI.IsLittleEndian);
414-
writeInteger((uint8_t)Unit.FormParams.AddrSize, OS, DI.IsLittleEndian);
415-
writeDWARFOffset(Unit.AbbrOffset, Unit.FormParams.Format, OS,
416-
DI.IsLittleEndian);
414+
writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian);
415+
writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian);
417416
} else {
418-
writeDWARFOffset(Unit.AbbrOffset, Unit.FormParams.Format, OS,
419-
DI.IsLittleEndian);
420-
writeInteger((uint8_t)Unit.FormParams.AddrSize, OS, DI.IsLittleEndian);
417+
writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian);
418+
writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian);
421419
}
422420

423421
OS.write(EntryBuffer.data(), EntryBuffer.size());
@@ -473,8 +471,7 @@ Error DWARFYAML::emitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) {
473471
case dwarf::DW_LNE_set_discriminator:
474472
// TODO: Test this error.
475473
if (Error Err = writeVariableSizedInteger(
476-
Op.Data, DI.CompileUnits[0].FormParams.AddrSize, OS,
477-
DI.IsLittleEndian))
474+
Op.Data, DI.CompileUnits[0].AddrSize, OS, DI.IsLittleEndian))
478475
return Err;
479476
break;
480477
case dwarf::DW_LNE_define_file:

llvm/lib/ObjectYAML/DWARFYAML.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ void MappingTraits<DWARFYAML::PubSection>::mapping(
144144
}
145145

146146
void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) {
147-
IO.mapOptional("Format", Unit.FormParams.Format, dwarf::DWARF32);
147+
IO.mapOptional("Format", Unit.Format, dwarf::DWARF32);
148148
IO.mapOptional("Length", Unit.Length);
149-
IO.mapRequired("Version", Unit.FormParams.Version);
150-
if (Unit.FormParams.Version >= 5)
149+
IO.mapRequired("Version", Unit.Version);
150+
if (Unit.Version >= 5)
151151
IO.mapRequired("UnitType", Unit.Type);
152152
IO.mapRequired("AbbrOffset", Unit.AbbrOffset);
153-
IO.mapRequired("AddrSize", Unit.FormParams.AddrSize);
153+
IO.mapRequired("AddrSize", Unit.AddrSize);
154154
IO.mapOptional("Entries", Unit.Entries);
155155
}
156156

llvm/tools/obj2yaml/dwarf2yaml.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ void dumpDebugPubSections(DWARFContext &DCtx, DWARFYAML::Data &Y) {
167167
void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) {
168168
for (const auto &CU : DCtx.compile_units()) {
169169
DWARFYAML::Unit NewUnit;
170-
NewUnit.FormParams.Format = CU->getFormat();
170+
NewUnit.Format = CU->getFormat();
171171
NewUnit.Length = CU->getLength();
172-
NewUnit.FormParams.Version = CU->getVersion();
173-
if (NewUnit.FormParams.Version >= 5)
172+
NewUnit.Version = CU->getVersion();
173+
if (NewUnit.Version >= 5)
174174
NewUnit.Type = (dwarf::UnitType)CU->getUnitType();
175175
NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset();
176-
NewUnit.FormParams.AddrSize = CU->getAddressByteSize();
176+
NewUnit.AddrSize = CU->getAddressByteSize();
177177
for (auto DIE : CU->dies()) {
178178
DWARFYAML::Entry NewEntry;
179179
DataExtractor EntryData = CU->getDebugInfoExtractor();

0 commit comments

Comments
 (0)