2016-12-07 22:26:32 +01:00
|
|
|
//===- DWARFYAML.cpp - DWARF YAMLIO implementation ------------------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-12-07 22:26:32 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines classes for handling the YAML representation of DWARF Debug
|
|
|
|
// Info.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/ObjectYAML/DWARFYAML.h"
|
2020-06-05 06:15:34 +02:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2016-12-07 22:26:32 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2016-12-08 18:46:57 +01:00
|
|
|
bool DWARFYAML::Data::isEmpty() const {
|
2020-07-31 06:56:10 +02:00
|
|
|
return DebugStrings.empty() && AbbrevDecls.empty() && DebugAranges &&
|
2020-05-29 13:56:32 +02:00
|
|
|
DebugRanges.empty() && !PubNames && !PubTypes && !GNUPubNames &&
|
|
|
|
!GNUPubTypes && CompileUnits.empty() && DebugLines.empty();
|
2016-12-07 22:26:32 +01:00
|
|
|
}
|
|
|
|
|
2020-07-26 10:01:22 +02:00
|
|
|
SetVector<StringRef> DWARFYAML::Data::getNonEmptySectionNames() const {
|
2020-05-29 04:51:37 +02:00
|
|
|
SetVector<StringRef> SecNames;
|
|
|
|
if (!DebugStrings.empty())
|
|
|
|
SecNames.insert("debug_str");
|
2020-07-31 06:56:10 +02:00
|
|
|
if (DebugAranges)
|
2020-06-04 02:53:40 +02:00
|
|
|
SecNames.insert("debug_aranges");
|
2020-06-07 09:47:14 +02:00
|
|
|
if (!DebugRanges.empty())
|
|
|
|
SecNames.insert("debug_ranges");
|
2020-06-09 17:40:40 +02:00
|
|
|
if (!DebugLines.empty())
|
|
|
|
SecNames.insert("debug_line");
|
2020-06-16 04:50:49 +02:00
|
|
|
if (!DebugAddr.empty())
|
|
|
|
SecNames.insert("debug_addr");
|
2020-06-17 10:10:58 +02:00
|
|
|
if (!AbbrevDecls.empty())
|
|
|
|
SecNames.insert("debug_abbrev");
|
2020-06-20 06:09:22 +02:00
|
|
|
if (!CompileUnits.empty())
|
|
|
|
SecNames.insert("debug_info");
|
2020-06-23 14:39:38 +02:00
|
|
|
if (PubNames)
|
|
|
|
SecNames.insert("debug_pubnames");
|
2020-06-23 14:41:21 +02:00
|
|
|
if (PubTypes)
|
|
|
|
SecNames.insert("debug_pubtypes");
|
2020-07-03 12:13:49 +02:00
|
|
|
if (GNUPubNames)
|
|
|
|
SecNames.insert("debug_gnu_pubnames");
|
|
|
|
if (GNUPubTypes)
|
|
|
|
SecNames.insert("debug_gnu_pubtypes");
|
2020-07-16 16:32:31 +02:00
|
|
|
if (DebugStrOffsets)
|
|
|
|
SecNames.insert("debug_str_offsets");
|
2020-07-20 04:42:27 +02:00
|
|
|
if (DebugRnglists)
|
|
|
|
SecNames.insert("debug_rnglists");
|
2020-05-29 04:51:37 +02:00
|
|
|
return SecNames;
|
|
|
|
}
|
|
|
|
|
2016-12-07 22:26:32 +01:00
|
|
|
namespace yaml {
|
|
|
|
|
2016-12-22 23:44:27 +01:00
|
|
|
void MappingTraits<DWARFYAML::Data>::mapping(IO &IO, DWARFYAML::Data &DWARF) {
|
2020-07-03 11:56:02 +02:00
|
|
|
void *OldContext = IO.getContext();
|
|
|
|
DWARFYAML::DWARFContext DWARFCtx;
|
|
|
|
IO.setContext(&DWARFCtx);
|
2016-12-07 22:26:32 +01:00
|
|
|
IO.mapOptional("debug_str", DWARF.DebugStrings);
|
|
|
|
IO.mapOptional("debug_abbrev", DWARF.AbbrevDecls);
|
2020-07-31 06:56:10 +02:00
|
|
|
IO.mapOptional("debug_aranges", DWARF.DebugAranges);
|
2020-05-14 07:01:57 +02:00
|
|
|
if (!DWARF.DebugRanges.empty() || !IO.outputting())
|
|
|
|
IO.mapOptional("debug_ranges", DWARF.DebugRanges);
|
2020-05-29 13:56:32 +02:00
|
|
|
IO.mapOptional("debug_pubnames", DWARF.PubNames);
|
|
|
|
IO.mapOptional("debug_pubtypes", DWARF.PubTypes);
|
2020-07-03 11:56:02 +02:00
|
|
|
DWARFCtx.IsGNUPubSec = true;
|
2020-05-29 13:56:32 +02:00
|
|
|
IO.mapOptional("debug_gnu_pubnames", DWARF.GNUPubNames);
|
|
|
|
IO.mapOptional("debug_gnu_pubtypes", DWARF.GNUPubTypes);
|
2016-12-22 23:44:27 +01:00
|
|
|
IO.mapOptional("debug_info", DWARF.CompileUnits);
|
2017-01-10 07:22:49 +01:00
|
|
|
IO.mapOptional("debug_line", DWARF.DebugLines);
|
2020-06-16 04:50:49 +02:00
|
|
|
IO.mapOptional("debug_addr", DWARF.DebugAddr);
|
2020-07-16 16:32:31 +02:00
|
|
|
IO.mapOptional("debug_str_offsets", DWARF.DebugStrOffsets);
|
2020-07-20 04:42:27 +02:00
|
|
|
IO.mapOptional("debug_rnglists", DWARF.DebugRnglists);
|
2020-07-03 11:56:02 +02:00
|
|
|
IO.setContext(OldContext);
|
2016-12-07 22:26:32 +01:00
|
|
|
}
|
|
|
|
|
2016-12-22 23:44:27 +01:00
|
|
|
void MappingTraits<DWARFYAML::Abbrev>::mapping(IO &IO,
|
|
|
|
DWARFYAML::Abbrev &Abbrev) {
|
2020-06-18 07:02:08 +02:00
|
|
|
IO.mapOptional("Code", Abbrev.Code);
|
2016-12-07 22:26:32 +01:00
|
|
|
IO.mapRequired("Tag", Abbrev.Tag);
|
|
|
|
IO.mapRequired("Children", Abbrev.Children);
|
|
|
|
IO.mapRequired("Attributes", Abbrev.Attributes);
|
|
|
|
}
|
|
|
|
|
2016-12-08 18:46:57 +01:00
|
|
|
void MappingTraits<DWARFYAML::AttributeAbbrev>::mapping(
|
|
|
|
IO &IO, DWARFYAML::AttributeAbbrev &AttAbbrev) {
|
2016-12-07 22:26:32 +01:00
|
|
|
IO.mapRequired("Attribute", AttAbbrev.Attribute);
|
|
|
|
IO.mapRequired("Form", AttAbbrev.Form);
|
2017-03-07 00:22:49 +01:00
|
|
|
if(AttAbbrev.Form == dwarf::DW_FORM_implicit_const)
|
|
|
|
IO.mapRequired("Value", AttAbbrev.Value);
|
2016-12-07 22:26:32 +01:00
|
|
|
}
|
|
|
|
|
2016-12-09 01:26:44 +01:00
|
|
|
void MappingTraits<DWARFYAML::ARangeDescriptor>::mapping(
|
|
|
|
IO &IO, DWARFYAML::ARangeDescriptor &Descriptor) {
|
|
|
|
IO.mapRequired("Address", Descriptor.Address);
|
|
|
|
IO.mapRequired("Length", Descriptor.Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<DWARFYAML::ARange>::mapping(IO &IO,
|
2020-05-26 11:22:23 +02:00
|
|
|
DWARFYAML::ARange &ARange) {
|
2020-06-05 06:15:34 +02:00
|
|
|
IO.mapOptional("Format", ARange.Format, dwarf::DWARF32);
|
2020-07-30 11:42:18 +02:00
|
|
|
IO.mapOptional("Length", ARange.Length);
|
2020-05-26 11:22:23 +02:00
|
|
|
IO.mapRequired("Version", ARange.Version);
|
|
|
|
IO.mapRequired("CuOffset", ARange.CuOffset);
|
2020-07-30 11:39:39 +02:00
|
|
|
IO.mapOptional("AddressSize", ARange.AddrSize);
|
|
|
|
IO.mapOptional("SegmentSelectorSize", ARange.SegSize, 0);
|
2020-05-26 11:22:23 +02:00
|
|
|
IO.mapRequired("Descriptors", ARange.Descriptors);
|
2016-12-09 01:26:44 +01:00
|
|
|
}
|
|
|
|
|
2020-04-24 04:25:12 +02:00
|
|
|
void MappingTraits<DWARFYAML::RangeEntry>::mapping(
|
|
|
|
IO &IO, DWARFYAML::RangeEntry &Descriptor) {
|
|
|
|
IO.mapRequired("LowOffset", Descriptor.LowOffset);
|
|
|
|
IO.mapRequired("HighOffset", Descriptor.HighOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<DWARFYAML::Ranges>::mapping(IO &IO,
|
2020-05-14 07:01:57 +02:00
|
|
|
DWARFYAML::Ranges &DebugRanges) {
|
2020-06-11 02:36:06 +02:00
|
|
|
IO.mapOptional("Offset", DebugRanges.Offset);
|
2020-06-14 06:00:46 +02:00
|
|
|
IO.mapOptional("AddrSize", DebugRanges.AddrSize);
|
2020-05-14 07:01:57 +02:00
|
|
|
IO.mapRequired("Entries", DebugRanges.Entries);
|
2020-04-24 04:25:12 +02:00
|
|
|
}
|
|
|
|
|
2016-12-19 23:22:12 +01:00
|
|
|
void MappingTraits<DWARFYAML::PubEntry>::mapping(IO &IO,
|
|
|
|
DWARFYAML::PubEntry &Entry) {
|
|
|
|
IO.mapRequired("DieOffset", Entry.DieOffset);
|
2020-07-03 11:56:02 +02:00
|
|
|
if (static_cast<DWARFYAML::DWARFContext *>(IO.getContext())->IsGNUPubSec)
|
2016-12-19 23:22:12 +01:00
|
|
|
IO.mapRequired("Descriptor", Entry.Descriptor);
|
|
|
|
IO.mapRequired("Name", Entry.Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<DWARFYAML::PubSection>::mapping(
|
|
|
|
IO &IO, DWARFYAML::PubSection &Section) {
|
|
|
|
IO.mapRequired("Length", Section.Length);
|
|
|
|
IO.mapRequired("Version", Section.Version);
|
|
|
|
IO.mapRequired("UnitOffset", Section.UnitOffset);
|
|
|
|
IO.mapRequired("UnitSize", Section.UnitSize);
|
|
|
|
IO.mapRequired("Entries", Section.Entries);
|
|
|
|
}
|
|
|
|
|
2016-12-22 23:44:27 +01:00
|
|
|
void MappingTraits<DWARFYAML::Unit>::mapping(IO &IO, DWARFYAML::Unit &Unit) {
|
2020-07-24 10:54:31 +02:00
|
|
|
IO.mapOptional("Format", Unit.FormParams.Format, dwarf::DWARF32);
|
2020-07-23 17:00:19 +02:00
|
|
|
IO.mapOptional("Length", Unit.Length);
|
2020-07-24 10:54:31 +02:00
|
|
|
IO.mapRequired("Version", Unit.FormParams.Version);
|
|
|
|
if (Unit.FormParams.Version >= 5)
|
2017-03-07 19:50:58 +01:00
|
|
|
IO.mapRequired("UnitType", Unit.Type);
|
2016-12-22 23:44:27 +01:00
|
|
|
IO.mapRequired("AbbrOffset", Unit.AbbrOffset);
|
2020-07-24 10:54:31 +02:00
|
|
|
IO.mapRequired("AddrSize", Unit.FormParams.AddrSize);
|
2016-12-22 23:44:27 +01:00
|
|
|
IO.mapOptional("Entries", Unit.Entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<DWARFYAML::Entry>::mapping(IO &IO, DWARFYAML::Entry &Entry) {
|
|
|
|
IO.mapRequired("AbbrCode", Entry.AbbrCode);
|
|
|
|
IO.mapRequired("Values", Entry.Values);
|
|
|
|
}
|
|
|
|
|
2017-01-10 07:22:49 +01:00
|
|
|
void MappingTraits<DWARFYAML::FormValue>::mapping(
|
|
|
|
IO &IO, DWARFYAML::FormValue &FormValue) {
|
2016-12-22 23:44:27 +01:00
|
|
|
IO.mapOptional("Value", FormValue.Value);
|
2017-01-10 07:22:49 +01:00
|
|
|
if (!FormValue.CStr.empty() || !IO.outputting())
|
2016-12-22 23:44:27 +01:00
|
|
|
IO.mapOptional("CStr", FormValue.CStr);
|
2017-01-10 07:22:49 +01:00
|
|
|
if (!FormValue.BlockData.empty() || !IO.outputting())
|
2016-12-22 23:44:27 +01:00
|
|
|
IO.mapOptional("BlockData", FormValue.BlockData);
|
|
|
|
}
|
|
|
|
|
2017-01-10 07:22:49 +01:00
|
|
|
void MappingTraits<DWARFYAML::File>::mapping(IO &IO, DWARFYAML::File &File) {
|
|
|
|
IO.mapRequired("Name", File.Name);
|
|
|
|
IO.mapRequired("DirIdx", File.DirIdx);
|
|
|
|
IO.mapRequired("ModTime", File.ModTime);
|
|
|
|
IO.mapRequired("Length", File.Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<DWARFYAML::LineTableOpcode>::mapping(
|
|
|
|
IO &IO, DWARFYAML::LineTableOpcode &LineTableOpcode) {
|
|
|
|
IO.mapRequired("Opcode", LineTableOpcode.Opcode);
|
|
|
|
if (LineTableOpcode.Opcode == dwarf::DW_LNS_extended_op) {
|
|
|
|
IO.mapRequired("ExtLen", LineTableOpcode.ExtLen);
|
|
|
|
IO.mapRequired("SubOpcode", LineTableOpcode.SubOpcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting())
|
|
|
|
IO.mapOptional("UnknownOpcodeData", LineTableOpcode.UnknownOpcodeData);
|
|
|
|
if (!LineTableOpcode.UnknownOpcodeData.empty() || !IO.outputting())
|
|
|
|
IO.mapOptional("StandardOpcodeData", LineTableOpcode.StandardOpcodeData);
|
|
|
|
if (!LineTableOpcode.FileEntry.Name.empty() || !IO.outputting())
|
|
|
|
IO.mapOptional("FileEntry", LineTableOpcode.FileEntry);
|
|
|
|
if (LineTableOpcode.Opcode == dwarf::DW_LNS_advance_line || !IO.outputting())
|
|
|
|
IO.mapOptional("SData", LineTableOpcode.SData);
|
|
|
|
IO.mapOptional("Data", LineTableOpcode.Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<DWARFYAML::LineTable>::mapping(
|
|
|
|
IO &IO, DWARFYAML::LineTable &LineTable) {
|
2020-06-13 16:04:51 +02:00
|
|
|
IO.mapOptional("Format", LineTable.Format, dwarf::DWARF32);
|
2017-03-03 22:11:55 +01:00
|
|
|
IO.mapRequired("Length", LineTable.Length);
|
2017-01-10 07:22:49 +01:00
|
|
|
IO.mapRequired("Version", LineTable.Version);
|
|
|
|
IO.mapRequired("PrologueLength", LineTable.PrologueLength);
|
|
|
|
IO.mapRequired("MinInstLength", LineTable.MinInstLength);
|
|
|
|
if(LineTable.Version >= 4)
|
|
|
|
IO.mapRequired("MaxOpsPerInst", LineTable.MaxOpsPerInst);
|
|
|
|
IO.mapRequired("DefaultIsStmt", LineTable.DefaultIsStmt);
|
|
|
|
IO.mapRequired("LineBase", LineTable.LineBase);
|
|
|
|
IO.mapRequired("LineRange", LineTable.LineRange);
|
|
|
|
IO.mapRequired("OpcodeBase", LineTable.OpcodeBase);
|
|
|
|
IO.mapRequired("StandardOpcodeLengths", LineTable.StandardOpcodeLengths);
|
|
|
|
IO.mapRequired("IncludeDirs", LineTable.IncludeDirs);
|
|
|
|
IO.mapRequired("Files", LineTable.Files);
|
|
|
|
IO.mapRequired("Opcodes", LineTable.Opcodes);
|
|
|
|
}
|
|
|
|
|
2020-06-16 04:50:49 +02:00
|
|
|
void MappingTraits<DWARFYAML::SegAddrPair>::mapping(
|
|
|
|
IO &IO, DWARFYAML::SegAddrPair &SegAddrPair) {
|
|
|
|
IO.mapOptional("Segment", SegAddrPair.Segment, 0);
|
|
|
|
IO.mapOptional("Address", SegAddrPair.Address, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MappingTraits<DWARFYAML::AddrTableEntry>::mapping(
|
|
|
|
IO &IO, DWARFYAML::AddrTableEntry &AddrTable) {
|
|
|
|
IO.mapOptional("Format", AddrTable.Format, dwarf::DWARF32);
|
|
|
|
IO.mapOptional("Length", AddrTable.Length);
|
|
|
|
IO.mapRequired("Version", AddrTable.Version);
|
|
|
|
IO.mapOptional("AddressSize", AddrTable.AddrSize);
|
|
|
|
IO.mapOptional("SegmentSelectorSize", AddrTable.SegSelectorSize, 0);
|
|
|
|
IO.mapOptional("Entries", AddrTable.SegAddrPairs);
|
|
|
|
}
|
|
|
|
|
2020-07-16 16:32:31 +02:00
|
|
|
void MappingTraits<DWARFYAML::StringOffsetsTable>::mapping(
|
|
|
|
IO &IO, DWARFYAML::StringOffsetsTable &StrOffsetsTable) {
|
|
|
|
IO.mapOptional("Format", StrOffsetsTable.Format, dwarf::DWARF32);
|
|
|
|
IO.mapOptional("Length", StrOffsetsTable.Length);
|
|
|
|
IO.mapOptional("Version", StrOffsetsTable.Version, 5);
|
|
|
|
IO.mapOptional("Padding", StrOffsetsTable.Padding, 0);
|
|
|
|
IO.mapOptional("Offsets", StrOffsetsTable.Offsets);
|
|
|
|
}
|
|
|
|
|
2020-07-20 04:42:27 +02:00
|
|
|
void MappingTraits<DWARFYAML::RnglistEntry>::mapping(
|
|
|
|
IO &IO, DWARFYAML::RnglistEntry &RnglistEntry) {
|
|
|
|
IO.mapRequired("Operator", RnglistEntry.Operator);
|
|
|
|
IO.mapOptional("Values", RnglistEntry.Values);
|
|
|
|
}
|
|
|
|
|
2020-07-23 04:25:01 +02:00
|
|
|
template <typename EntryType>
|
|
|
|
void MappingTraits<DWARFYAML::ListEntries<EntryType>>::mapping(
|
|
|
|
IO &IO, DWARFYAML::ListEntries<EntryType> &ListEntries) {
|
|
|
|
IO.mapOptional("Entries", ListEntries.Entries);
|
2020-07-28 16:10:44 +02:00
|
|
|
IO.mapOptional("Content", ListEntries.Content);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename EntryType>
|
|
|
|
StringRef MappingTraits<DWARFYAML::ListEntries<EntryType>>::validate(
|
|
|
|
IO &IO, DWARFYAML::ListEntries<EntryType> &ListEntries) {
|
|
|
|
if (ListEntries.Entries && ListEntries.Content)
|
|
|
|
return "Entries and Content can't be used together";
|
|
|
|
return StringRef();
|
2020-07-20 04:42:27 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 04:25:01 +02:00
|
|
|
template <typename EntryType>
|
|
|
|
void MappingTraits<DWARFYAML::ListTable<EntryType>>::mapping(
|
|
|
|
IO &IO, DWARFYAML::ListTable<EntryType> &ListTable) {
|
|
|
|
IO.mapOptional("Format", ListTable.Format, dwarf::DWARF32);
|
|
|
|
IO.mapOptional("Length", ListTable.Length);
|
|
|
|
IO.mapOptional("Version", ListTable.Version, 5);
|
|
|
|
IO.mapOptional("AddressSize", ListTable.AddrSize);
|
|
|
|
IO.mapOptional("SegmentSelectorSize", ListTable.SegSelectorSize, 0);
|
|
|
|
IO.mapOptional("OffsetEntryCount", ListTable.OffsetEntryCount);
|
|
|
|
IO.mapOptional("Offsets", ListTable.Offsets);
|
|
|
|
IO.mapOptional("Lists", ListTable.Lists);
|
2020-07-20 04:42:27 +02:00
|
|
|
}
|
|
|
|
|
2017-03-03 22:11:55 +01:00
|
|
|
void MappingTraits<DWARFYAML::InitialLength>::mapping(
|
|
|
|
IO &IO, DWARFYAML::InitialLength &InitialLength) {
|
|
|
|
IO.mapRequired("TotalLength", InitialLength.TotalLength);
|
|
|
|
if (InitialLength.isDWARF64())
|
|
|
|
IO.mapRequired("TotalLength64", InitialLength.TotalLength64);
|
|
|
|
}
|
|
|
|
|
2017-07-01 03:35:55 +02:00
|
|
|
} // end namespace yaml
|
2016-12-07 22:26:32 +01:00
|
|
|
|
2017-07-01 03:35:55 +02:00
|
|
|
} // end namespace llvm
|