diff options
author | Chris Bieneman <beanz@apple.com> | 2016-12-07 21:47:28 +0000 |
---|---|---|
committer | Chris Bieneman <beanz@apple.com> | 2016-12-07 21:47:28 +0000 |
commit | 26d060fbf9fe5525f06f13c398ad1c564528fe57 (patch) | |
tree | 8544b5262853338ce148e8452a709fb389ba53e5 /llvm/tools/obj2yaml/dwarf2yaml.cpp | |
parent | c53606ef02fa14e199c2ad65956ea33b5eb698f0 (diff) | |
download | bcm5719-llvm-26d060fbf9fe5525f06f13c398ad1c564528fe57.tar.gz bcm5719-llvm-26d060fbf9fe5525f06f13c398ad1c564528fe57.zip |
[obj2yaml] Refactor and abstract dwarf2yaml
This makes the dwarf2yaml code separated and reusable allowing ELF and COFF to share implementations with MachO.
llvm-svn: 288986
Diffstat (limited to 'llvm/tools/obj2yaml/dwarf2yaml.cpp')
-rw-r--r-- | llvm/tools/obj2yaml/dwarf2yaml.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/llvm/tools/obj2yaml/dwarf2yaml.cpp b/llvm/tools/obj2yaml/dwarf2yaml.cpp new file mode 100644 index 00000000000..99c12b2cd72 --- /dev/null +++ b/llvm/tools/obj2yaml/dwarf2yaml.cpp @@ -0,0 +1,53 @@ +//===------ 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; +} |