forked from OSchip/llvm-project
[ObjectYAML] Pull DWARF support into DWARFYAML namespace
Since DWARF formatting is agnostic to the object file it is stored in, it doesn't make sense for this to be in the MachOYAML implementation. Pulling it into its own namespace means we could modify the ELF and COFF YAML tools to emit DWARF as well. In a follow-up patch I will better abstract this in obj2yaml and yaml2obj so that the DWARF bits in the tools can be re-used too. llvm-svn: 288984
This commit is contained in:
parent
50db7f416c
commit
79e60eb948
|
@ -0,0 +1,108 @@
|
|||
//===- DWARFYAML.h - DWARF YAMLIO implementation ----------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
///
|
||||
/// \file
|
||||
/// \brief This file declares classes for handling the YAML representation
|
||||
/// of DWARF Debug Info.
|
||||
///
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
#ifndef LLVM_OBJECTYAML_DWARFYAML_H
|
||||
#define LLVM_OBJECTYAML_DWARFYAML_H
|
||||
|
||||
#include "llvm/ObjectYAML/YAML.h"
|
||||
#include "llvm/Support/Dwarf.h"
|
||||
|
||||
namespace llvm {
|
||||
namespace DWARFYAML {
|
||||
|
||||
struct DWARFAttributeAbbrev {
|
||||
llvm::dwarf::Attribute Attribute;
|
||||
llvm::dwarf::Form Form;
|
||||
};
|
||||
|
||||
struct DWARFAbbrev {
|
||||
llvm::yaml::Hex32 Code;
|
||||
llvm::dwarf::Tag Tag;
|
||||
llvm::dwarf::Constants Children;
|
||||
std::vector<DWARFAttributeAbbrev> Attributes;
|
||||
};
|
||||
|
||||
struct DWARFData {
|
||||
std::vector<DWARFAbbrev> AbbrevDecls;
|
||||
std::vector<StringRef> DebugStrings;
|
||||
|
||||
bool isEmpty() const;
|
||||
};
|
||||
|
||||
} // namespace llvm::DWARFYAML
|
||||
} // namespace llvm
|
||||
|
||||
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::StringRef)
|
||||
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::DWARFAttributeAbbrev)
|
||||
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::DWARFYAML::DWARFAbbrev)
|
||||
|
||||
namespace llvm {
|
||||
namespace yaml {
|
||||
|
||||
template <> struct MappingTraits<DWARFYAML::DWARFData> {
|
||||
static void mapping(IO &IO, DWARFYAML::DWARFData &DWARF);
|
||||
};
|
||||
|
||||
template <> struct MappingTraits<DWARFYAML::DWARFAbbrev> {
|
||||
static void mapping(IO &IO, DWARFYAML::DWARFAbbrev &Abbrev);
|
||||
};
|
||||
|
||||
template <> struct MappingTraits<DWARFYAML::DWARFAttributeAbbrev> {
|
||||
static void mapping(IO &IO, DWARFYAML::DWARFAttributeAbbrev &AttAbbrev);
|
||||
};
|
||||
|
||||
#define HANDLE_DW_TAG(unused, name) \
|
||||
io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name);
|
||||
|
||||
template <> struct ScalarEnumerationTraits<dwarf::Tag> {
|
||||
static void enumeration(IO &io, dwarf::Tag &value) {
|
||||
#include "llvm/Support/Dwarf.def"
|
||||
io.enumFallback<Hex16>(value);
|
||||
}
|
||||
};
|
||||
|
||||
#define HANDLE_DW_AT(unused, name) \
|
||||
io.enumCase(value, "DW_AT_" #name, dwarf::DW_AT_##name);
|
||||
|
||||
template <> struct ScalarEnumerationTraits<dwarf::Attribute> {
|
||||
static void enumeration(IO &io, dwarf::Attribute &value) {
|
||||
#include "llvm/Support/Dwarf.def"
|
||||
io.enumFallback<Hex16>(value);
|
||||
}
|
||||
};
|
||||
|
||||
#define HANDLE_DW_FORM(unused, name) \
|
||||
io.enumCase(value, "DW_FORM_" #name, dwarf::DW_FORM_##name);
|
||||
|
||||
template <> struct ScalarEnumerationTraits<dwarf::Form> {
|
||||
static void enumeration(IO &io, dwarf::Form &value) {
|
||||
#include "llvm/Support/Dwarf.def"
|
||||
io.enumFallback<Hex16>(value);
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct ScalarEnumerationTraits<dwarf::Constants> {
|
||||
static void enumeration(IO &io, dwarf::Constants &value) {
|
||||
io.enumCase(value, "DW_CHILDREN_no", dwarf::DW_CHILDREN_no);
|
||||
io.enumCase(value, "DW_CHILDREN_yes", dwarf::DW_CHILDREN_yes);
|
||||
io.enumFallback<Hex16>(value);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace llvm::yaml
|
||||
} // namespace llvm
|
||||
|
||||
#endif
|
|
@ -17,8 +17,8 @@
|
|||
#define LLVM_OBJECTYAML_MACHOYAML_H
|
||||
|
||||
#include "llvm/ObjectYAML/YAML.h"
|
||||
#include "llvm/ObjectYAML/DWARFYAML.h"
|
||||
#include "llvm/Support/MachO.h"
|
||||
#include "llvm/Support/Dwarf.h"
|
||||
|
||||
namespace llvm {
|
||||
namespace MachOYAML {
|
||||
|
@ -105,31 +105,12 @@ struct LinkEditData {
|
|||
bool isEmpty() const;
|
||||
};
|
||||
|
||||
struct DWARFAttributeAbbrev {
|
||||
llvm::dwarf::Attribute Attribute;
|
||||
llvm::dwarf::Form Form;
|
||||
};
|
||||
|
||||
struct DWARFAbbrev {
|
||||
llvm::yaml::Hex32 Code;
|
||||
llvm::dwarf::Tag Tag;
|
||||
llvm::dwarf::Constants Children;
|
||||
std::vector<DWARFAttributeAbbrev> Attributes;
|
||||
};
|
||||
|
||||
struct DWARFData {
|
||||
std::vector<DWARFAbbrev> AbbrevDecls;
|
||||
std::vector<StringRef> DebugStrings;
|
||||
|
||||
bool isEmpty() const;
|
||||
};
|
||||
|
||||
struct Object {
|
||||
FileHeader Header;
|
||||
std::vector<LoadCommand> LoadCommands;
|
||||
std::vector<Section> Sections;
|
||||
LinkEditData LinkEdit;
|
||||
DWARFData DWARF;
|
||||
DWARFYAML::DWARFData DWARF;
|
||||
};
|
||||
|
||||
struct FatHeader {
|
||||
|
@ -164,11 +145,8 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::RebaseOpcode)
|
|||
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::BindOpcode)
|
||||
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::ExportEntry)
|
||||
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::NListEntry)
|
||||
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::StringRef)
|
||||
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::Object)
|
||||
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::FatArch)
|
||||
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::DWARFAttributeAbbrev)
|
||||
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MachOYAML::DWARFAbbrev)
|
||||
|
||||
namespace llvm {
|
||||
namespace yaml {
|
||||
|
@ -221,18 +199,6 @@ template <> struct MappingTraits<MachOYAML::NListEntry> {
|
|||
static void mapping(IO &IO, MachOYAML::NListEntry &NListEntry);
|
||||
};
|
||||
|
||||
template <> struct MappingTraits<MachOYAML::DWARFData> {
|
||||
static void mapping(IO &IO, MachOYAML::DWARFData &DWARF);
|
||||
};
|
||||
|
||||
template <> struct MappingTraits<MachOYAML::DWARFAbbrev> {
|
||||
static void mapping(IO &IO, MachOYAML::DWARFAbbrev &Abbrev);
|
||||
};
|
||||
|
||||
template <> struct MappingTraits<MachOYAML::DWARFAttributeAbbrev> {
|
||||
static void mapping(IO &IO, MachOYAML::DWARFAttributeAbbrev &AttAbbrev);
|
||||
};
|
||||
|
||||
#define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
|
||||
io.enumCase(value, #LCName, MachO::LCName);
|
||||
|
||||
|
@ -279,44 +245,6 @@ template <> struct ScalarEnumerationTraits<MachO::BindOpcode> {
|
|||
}
|
||||
};
|
||||
|
||||
#define HANDLE_DW_TAG(unused, name) \
|
||||
io.enumCase(value, "DW_TAG_" #name, dwarf::DW_TAG_##name);
|
||||
|
||||
template <> struct ScalarEnumerationTraits<dwarf::Tag> {
|
||||
static void enumeration(IO &io, dwarf::Tag &value) {
|
||||
#include "llvm/Support/Dwarf.def"
|
||||
io.enumFallback<Hex16>(value);
|
||||
}
|
||||
};
|
||||
|
||||
#define HANDLE_DW_AT(unused, name) \
|
||||
io.enumCase(value, "DW_AT_" #name, dwarf::DW_AT_##name);
|
||||
|
||||
template <> struct ScalarEnumerationTraits<dwarf::Attribute> {
|
||||
static void enumeration(IO &io, dwarf::Attribute &value) {
|
||||
#include "llvm/Support/Dwarf.def"
|
||||
io.enumFallback<Hex16>(value);
|
||||
}
|
||||
};
|
||||
|
||||
#define HANDLE_DW_FORM(unused, name) \
|
||||
io.enumCase(value, "DW_FORM_" #name, dwarf::DW_FORM_##name);
|
||||
|
||||
template <> struct ScalarEnumerationTraits<dwarf::Form> {
|
||||
static void enumeration(IO &io, dwarf::Form &value) {
|
||||
#include "llvm/Support/Dwarf.def"
|
||||
io.enumFallback<Hex16>(value);
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct ScalarEnumerationTraits<dwarf::Constants> {
|
||||
static void enumeration(IO &io, dwarf::Constants &value) {
|
||||
io.enumCase(value, "DW_CHILDREN_no", dwarf::DW_CHILDREN_no);
|
||||
io.enumCase(value, "DW_CHILDREN_yes", dwarf::DW_CHILDREN_yes);
|
||||
io.enumFallback<Hex16>(value);
|
||||
}
|
||||
};
|
||||
|
||||
// This trait is used for 16-byte chars in Mach structures used for strings
|
||||
typedef char char_16[16];
|
||||
|
||||
|
|
|
@ -4,4 +4,5 @@ add_llvm_library(LLVMObjectYAML
|
|||
ELFYAML.cpp
|
||||
MachOYAML.cpp
|
||||
ObjectYAML.cpp
|
||||
DWARFYAML.cpp
|
||||
)
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
//===- DWARFYAML.cpp - DWARF YAMLIO implementation ------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines classes for handling the YAML representation of DWARF Debug
|
||||
// Info.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ObjectYAML/DWARFYAML.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
bool DWARFYAML::DWARFData::isEmpty() const {
|
||||
return 0 == DebugStrings.size() + AbbrevDecls.size();
|
||||
}
|
||||
|
||||
namespace yaml {
|
||||
|
||||
void MappingTraits<DWARFYAML::DWARFData>::mapping(
|
||||
IO &IO, DWARFYAML::DWARFData &DWARF) {
|
||||
IO.mapOptional("debug_str", DWARF.DebugStrings);
|
||||
IO.mapOptional("debug_abbrev", DWARF.AbbrevDecls);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::DWARFAbbrev>::mapping(
|
||||
IO &IO, DWARFYAML::DWARFAbbrev &Abbrev) {
|
||||
IO.mapRequired("Code", Abbrev.Code);
|
||||
IO.mapRequired("Tag", Abbrev.Tag);
|
||||
IO.mapRequired("Children", Abbrev.Children);
|
||||
IO.mapRequired("Attributes", Abbrev.Attributes);
|
||||
}
|
||||
|
||||
void MappingTraits<DWARFYAML::DWARFAttributeAbbrev>::mapping(
|
||||
IO &IO, DWARFYAML::DWARFAttributeAbbrev &AttAbbrev) {
|
||||
IO.mapRequired("Attribute", AttAbbrev.Attribute);
|
||||
IO.mapRequired("Form", AttAbbrev.Form);
|
||||
}
|
||||
|
||||
} // namespace llvm::yaml
|
||||
|
||||
} // namespace llvm
|
|
@ -29,10 +29,6 @@ bool MachOYAML::LinkEditData::isEmpty() const {
|
|||
NameList.size() + StringTable.size();
|
||||
}
|
||||
|
||||
bool MachOYAML::DWARFData::isEmpty() const {
|
||||
return 0 == DebugStrings.size() + AbbrevDecls.size();
|
||||
}
|
||||
|
||||
namespace yaml {
|
||||
|
||||
void ScalarTraits<char_16>::output(const char_16 &Val, void *,
|
||||
|
@ -557,26 +553,6 @@ void MappingTraits<MachO::version_min_command>::mapping(
|
|||
IO.mapRequired("sdk", LoadCommand.sdk);
|
||||
}
|
||||
|
||||
void MappingTraits<MachOYAML::DWARFData>::mapping(
|
||||
IO &IO, MachOYAML::DWARFData &DWARF) {
|
||||
IO.mapOptional("debug_str", DWARF.DebugStrings);
|
||||
IO.mapOptional("debug_abbrev", DWARF.AbbrevDecls);
|
||||
}
|
||||
|
||||
void MappingTraits<MachOYAML::DWARFAbbrev>::mapping(
|
||||
IO &IO, MachOYAML::DWARFAbbrev &Abbrev) {
|
||||
IO.mapRequired("Code", Abbrev.Code);
|
||||
IO.mapRequired("Tag", Abbrev.Tag);
|
||||
IO.mapRequired("Children", Abbrev.Children);
|
||||
IO.mapRequired("Attributes", Abbrev.Attributes);
|
||||
}
|
||||
|
||||
void MappingTraits<MachOYAML::DWARFAttributeAbbrev>::mapping(
|
||||
IO &IO, MachOYAML::DWARFAttributeAbbrev &AttAbbrev) {
|
||||
IO.mapRequired("Attribute", AttAbbrev.Attribute);
|
||||
IO.mapRequired("Form", AttAbbrev.Form);
|
||||
}
|
||||
|
||||
} // namespace llvm::yaml
|
||||
|
||||
} // namespace llvm
|
||||
|
|
|
@ -488,13 +488,13 @@ void MachODumper::dumpDebugAbbrev(DWARFContextInMemory &DCtx,
|
|||
if(AbbrevSetPtr) {
|
||||
for(auto AbbrvDeclSet : *AbbrevSetPtr) {
|
||||
for(auto AbbrvDecl : AbbrvDeclSet.second) {
|
||||
MachOYAML::DWARFAbbrev Abbrv;
|
||||
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()) {
|
||||
MachOYAML::DWARFAttributeAbbrev AttAbrv;
|
||||
DWARFYAML::DWARFAttributeAbbrev AttAbrv;
|
||||
AttAbrv.Attribute = Attribute.Attr;
|
||||
AttAbrv.Form = Attribute.Form;
|
||||
Abbrv.Attributes.push_back(AttAbrv);
|
||||
|
|
Loading…
Reference in New Issue