Changeset View
Changeset View
Standalone View
Standalone View
llvm/tools/obj2yaml/dwarf2yaml.cpp
Show All 11 Lines | |||||
#include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h" | #include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h" | ||||
#include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h" | #include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h" | ||||
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h" | #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h" | ||||
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h" | #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" | ||||
#include "llvm/DebugInfo/DWARF/DWARFSection.h" | #include "llvm/DebugInfo/DWARF/DWARFSection.h" | ||||
#include "llvm/ObjectYAML/DWARFYAML.h" | #include "llvm/ObjectYAML/DWARFYAML.h" | ||||
#include <algorithm> | #include <algorithm> | ||||
jhenderson: I'm slightly surprised you needed to add this. Did this not compile without it? | |||||
I guess it was automatically added by the code completion tool. Higuoxing: I guess it was automatically added by the code completion tool. | |||||
using namespace llvm; | using namespace llvm; | ||||
void dumpDebugAbbrev(DWARFContext &DCtx, DWARFYAML::Data &Y) { | void dumpDebugAbbrev(DWARFContext &DCtx, DWARFYAML::Data &Y) { | ||||
auto AbbrevSetPtr = DCtx.getDebugAbbrev(); | auto AbbrevSetPtr = DCtx.getDebugAbbrev(); | ||||
if (AbbrevSetPtr) { | if (AbbrevSetPtr) { | ||||
uint64_t AbbrevTableID = 0; | |||||
for (auto AbbrvDeclSet : *AbbrevSetPtr) { | for (auto AbbrvDeclSet : *AbbrevSetPtr) { | ||||
Y.DebugAbbrev.emplace_back(); | Y.DebugAbbrev.emplace_back(); | ||||
for (auto AbbrvDecl : AbbrvDeclSet.second) { | for (auto AbbrvDecl : AbbrvDeclSet.second) { | ||||
DWARFYAML::Abbrev Abbrv; | DWARFYAML::Abbrev Abbrv; | ||||
Abbrv.Code = AbbrvDecl.getCode(); | Abbrv.Code = AbbrvDecl.getCode(); | ||||
Abbrv.Tag = AbbrvDecl.getTag(); | Abbrv.Tag = AbbrvDecl.getTag(); | ||||
Abbrv.Children = AbbrvDecl.hasChildren() ? dwarf::DW_CHILDREN_yes | Abbrv.Children = AbbrvDecl.hasChildren() ? dwarf::DW_CHILDREN_yes | ||||
: dwarf::DW_CHILDREN_no; | : dwarf::DW_CHILDREN_no; | ||||
for (auto Attribute : AbbrvDecl.attributes()) { | for (auto Attribute : AbbrvDecl.attributes()) { | ||||
DWARFYAML::AttributeAbbrev AttAbrv; | DWARFYAML::AttributeAbbrev AttAbrv; | ||||
AttAbrv.Attribute = Attribute.Attr; | AttAbrv.Attribute = Attribute.Attr; | ||||
AttAbrv.Form = Attribute.Form; | AttAbrv.Form = Attribute.Form; | ||||
if (AttAbrv.Form == dwarf::DW_FORM_implicit_const) | if (AttAbrv.Form == dwarf::DW_FORM_implicit_const) | ||||
AttAbrv.Value = Attribute.getImplicitConstValue(); | AttAbrv.Value = Attribute.getImplicitConstValue(); | ||||
Abbrv.Attributes.push_back(AttAbrv); | Abbrv.Attributes.push_back(AttAbrv); | ||||
} | } | ||||
Y.DebugAbbrev.back().ID = AbbrevTableID++; | |||||
Y.DebugAbbrev.back().Table.push_back(Abbrv); | Y.DebugAbbrev.back().Table.push_back(Abbrv); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void dumpDebugStrings(DWARFContext &DCtx, DWARFYAML::Data &Y) { | void dumpDebugStrings(DWARFContext &DCtx, DWARFYAML::Data &Y) { | ||||
StringRef RemainingTable = DCtx.getDWARFObj().getStrSection(); | StringRef RemainingTable = DCtx.getDWARFObj().getStrSection(); | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | |||||
void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) { | void dumpDebugInfo(DWARFContext &DCtx, DWARFYAML::Data &Y) { | ||||
for (const auto &CU : DCtx.compile_units()) { | for (const auto &CU : DCtx.compile_units()) { | ||||
DWARFYAML::Unit NewUnit; | DWARFYAML::Unit NewUnit; | ||||
NewUnit.Format = CU->getFormat(); | NewUnit.Format = CU->getFormat(); | ||||
NewUnit.Length = CU->getLength(); | NewUnit.Length = CU->getLength(); | ||||
NewUnit.Version = CU->getVersion(); | NewUnit.Version = CU->getVersion(); | ||||
if (NewUnit.Version >= 5) | if (NewUnit.Version >= 5) | ||||
NewUnit.Type = (dwarf::UnitType)CU->getUnitType(); | NewUnit.Type = (dwarf::UnitType)CU->getUnitType(); | ||||
const DWARFDebugAbbrev *DebugAbbrev = DCtx.getDebugAbbrev(); | |||||
NewUnit.AbbrevTableID = std::distance( | |||||
DebugAbbrev->begin(), | |||||
std::find_if( | |||||
DebugAbbrev->begin(), DebugAbbrev->end(), | |||||
[&](const std::pair<uint64_t, DWARFAbbreviationDeclarationSet> &P) { | |||||
return P.first == CU->getAbbreviations()->getOffset(); | |||||
})); | |||||
NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset(); | NewUnit.AbbrOffset = CU->getAbbreviations()->getOffset(); | ||||
NewUnit.AddrSize = CU->getAddressByteSize(); | NewUnit.AddrSize = CU->getAddressByteSize(); | ||||
for (auto DIE : CU->dies()) { | for (auto DIE : CU->dies()) { | ||||
DWARFYAML::Entry NewEntry; | DWARFYAML::Entry NewEntry; | ||||
DataExtractor EntryData = CU->getDebugInfoExtractor(); | DataExtractor EntryData = CU->getDebugInfoExtractor(); | ||||
uint64_t offset = DIE.getOffset(); | uint64_t offset = DIE.getOffset(); | ||||
assert(EntryData.isValidOffset(offset) && "Invalid DIE Offset"); | assert(EntryData.isValidOffset(offset) && "Invalid DIE Offset"); | ||||
▲ Show 20 Lines • Show All 225 Lines • Show Last 20 Lines |
I'm slightly surprised you needed to add this. Did this not compile without it?