summaryrefslogtreecommitdiff
path: root/llvm/lib/ObjectYAML/DWARFEmitter.cpp
diff options
context:
space:
mode:
authorXing GUO <higuoxing@gmail.com>2020-08-06 16:37:52 +0800
committerXing GUO <higuoxing@gmail.com>2020-08-06 16:39:00 +0800
commit4357986b411dd164932c66ebfe4a9cf96a7d74cd (patch)
tree3e78b19ec865ef96b4bed6845bd05a786b313920 /llvm/lib/ObjectYAML/DWARFEmitter.cpp
parent6148cca70888ead020a808279043fd013ca72a2a (diff)
[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
Diffstat (limited to 'llvm/lib/ObjectYAML/DWARFEmitter.cpp')
-rw-r--r--llvm/lib/ObjectYAML/DWARFEmitter.cpp43
1 files changed, 20 insertions, 23 deletions
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index 1f79e3379b07..ad03104552e1 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -251,7 +251,7 @@ Error DWARFYAML::emitDebugGNUPubtypes(raw_ostream &OS, const Data &DI) {
}
static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
- const DWARFYAML::Unit &Unit,
+ const dwarf::FormParams &Params,
const DWARFYAML::Entry &Entry,
raw_ostream &OS, bool IsLittleEndian) {
uint64_t EntryBegin = OS.tell();
@@ -278,14 +278,14 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
case dwarf::DW_FORM_addr:
// TODO: Test this error.
if (Error Err = writeVariableSizedInteger(
- FormVal->Value, Unit.FormParams.AddrSize, OS, IsLittleEndian))
+ FormVal->Value, Params.AddrSize, OS, IsLittleEndian))
return std::move(Err);
break;
case dwarf::DW_FORM_ref_addr:
// TODO: Test this error.
- if (Error Err = writeVariableSizedInteger(
- FormVal->Value, Unit.FormParams.getRefAddrByteSize(), OS,
- IsLittleEndian))
+ if (Error Err = writeVariableSizedInteger(FormVal->Value,
+ Params.getRefAddrByteSize(),
+ OS, IsLittleEndian))
return std::move(Err);
break;
case dwarf::DW_FORM_exprloc:
@@ -367,9 +367,9 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
case dwarf::DW_FORM_GNU_strp_alt:
case dwarf::DW_FORM_line_strp:
case dwarf::DW_FORM_strp_sup:
- cantFail(writeVariableSizedInteger(
- FormVal->Value, Unit.FormParams.getDwarfOffsetByteSize(), OS,
- IsLittleEndian));
+ cantFail(writeVariableSizedInteger(FormVal->Value,
+ Params.getDwarfOffsetByteSize(), OS,
+ IsLittleEndian));
break;
default:
break;
@@ -382,10 +382,10 @@ static Expected<uint64_t> writeDIE(ArrayRef<DWARFYAML::Abbrev> AbbrevDecls,
Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
for (const DWARFYAML::Unit &Unit : DI.CompileUnits) {
+ dwarf::FormParams Params = {Unit.Version, Unit.AddrSize, Unit.Format};
uint64_t Length = 3; // sizeof(version) + sizeof(address_size)
- Length += Unit.FormParams.Version >= 5 ? 1 : 0; // sizeof(unit_type)
- Length +=
- Unit.FormParams.getDwarfOffsetByteSize(); // sizeof(debug_abbrev_offset)
+ Length += Unit.Version >= 5 ? 1 : 0; // sizeof(unit_type)
+ Length += Params.getDwarfOffsetByteSize(); // sizeof(debug_abbrev_offset)
// Since the length of the current compilation unit is undetermined yet, we
// 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) {
for (const DWARFYAML::Entry &Entry : Unit.Entries) {
if (Expected<uint64_t> EntryLength = writeDIE(
- DI.AbbrevDecls, Unit, Entry, EntryBufferOS, DI.IsLittleEndian))
+ DI.AbbrevDecls, Params, Entry, EntryBufferOS, DI.IsLittleEndian))
Length += *EntryLength;
else
return EntryLength.takeError();
@@ -407,17 +407,15 @@ Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) {
if (Unit.Length)
Length = *Unit.Length;
- writeInitialLength(Unit.FormParams.Format, Length, OS, DI.IsLittleEndian);
- writeInteger((uint16_t)Unit.FormParams.Version, OS, DI.IsLittleEndian);
- if (Unit.FormParams.Version >= 5) {
+ writeInitialLength(Unit.Format, Length, OS, DI.IsLittleEndian);
+ writeInteger((uint16_t)Unit.Version, OS, DI.IsLittleEndian);
+ if (Unit.Version >= 5) {
writeInteger((uint8_t)Unit.Type, OS, DI.IsLittleEndian);
- writeInteger((uint8_t)Unit.FormParams.AddrSize, OS, DI.IsLittleEndian);
- writeDWARFOffset(Unit.AbbrOffset, Unit.FormParams.Format, OS,
- DI.IsLittleEndian);
+ writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian);
+ writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian);
} else {
- writeDWARFOffset(Unit.AbbrOffset, Unit.FormParams.Format, OS,
- DI.IsLittleEndian);
- writeInteger((uint8_t)Unit.FormParams.AddrSize, OS, DI.IsLittleEndian);
+ writeDWARFOffset(Unit.AbbrOffset, Unit.Format, OS, DI.IsLittleEndian);
+ writeInteger((uint8_t)Unit.AddrSize, OS, DI.IsLittleEndian);
}
OS.write(EntryBuffer.data(), EntryBuffer.size());
@@ -473,8 +471,7 @@ Error DWARFYAML::emitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) {
case dwarf::DW_LNE_set_discriminator:
// TODO: Test this error.
if (Error Err = writeVariableSizedInteger(
- Op.Data, DI.CompileUnits[0].FormParams.AddrSize, OS,
- DI.IsLittleEndian))
+ Op.Data, DI.CompileUnits[0].AddrSize, OS, DI.IsLittleEndian))
return Err;
break;
case dwarf::DW_LNE_define_file: