forked from OSchip/llvm-project
54 lines
1.8 KiB
C++
54 lines
1.8 KiB
C++
|
//===------ dwarf2yaml.cpp - obj2yaml conversion tool -----------*- C++ -*-===//
|
||
|
//
|
||
|
// The LLVM Compiler Infrastructure
|
||
|
//
|
||
|
// This file is distributed under the University of Illinois Open Source
|
||
|
// License. See LICENSE.TXT for details.
|
||
|
//
|
||
|
//===----------------------------------------------------------------------===//
|
||
|
|
||
|
#include "Error.h"
|
||
|
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
|
||
|
#include "llvm/ObjectYAML/DWARFYAML.h"
|
||
|
|
||
|
using namespace llvm;
|
||
|
|
||
|
void dumpDebugAbbrev(DWARFContextInMemory &DCtx, DWARFYAML::DWARFData &Y) {
|
||
|
auto AbbrevSetPtr = DCtx.getDebugAbbrev();
|
||
|
if (AbbrevSetPtr) {
|
||
|
for (auto AbbrvDeclSet : *AbbrevSetPtr) {
|
||
|
for (auto AbbrvDecl : AbbrvDeclSet.second) {
|
||
|
DWARFYAML::DWARFAbbrev Abbrv;
|
||
|
Abbrv.Code = AbbrvDecl.getCode();
|
||
|
Abbrv.Tag = AbbrvDecl.getTag();
|
||
|
Abbrv.Children = AbbrvDecl.hasChildren() ? dwarf::DW_CHILDREN_yes
|
||
|
: dwarf::DW_CHILDREN_no;
|
||
|
for (auto Attribute : AbbrvDecl.attributes()) {
|
||
|
DWARFYAML::DWARFAttributeAbbrev AttAbrv;
|
||
|
AttAbrv.Attribute = Attribute.Attr;
|
||
|
AttAbrv.Form = Attribute.Form;
|
||
|
Abbrv.Attributes.push_back(AttAbrv);
|
||
|
}
|
||
|
Y.AbbrevDecls.push_back(Abbrv);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void dumpDebugStrings(DWARFContextInMemory &DCtx, DWARFYAML::DWARFData &Y) {
|
||
|
StringRef RemainingTable = DCtx.getStringSection();
|
||
|
while (RemainingTable.size() > 0) {
|
||
|
auto SymbolPair = RemainingTable.split('\0');
|
||
|
RemainingTable = SymbolPair.second;
|
||
|
Y.DebugStrings.push_back(SymbolPair.first);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
std::error_code dwarf2yaml(DWARFContextInMemory &DCtx,
|
||
|
DWARFYAML::DWARFData &Y) {
|
||
|
dumpDebugAbbrev(DCtx, Y);
|
||
|
dumpDebugStrings(DCtx, Y);
|
||
|
|
||
|
return obj2yaml_error::success;
|
||
|
}
|