2012-06-19 18:02:35 +00:00
|
|
|
//===------ utils/obj2yaml.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 "obj2yaml.h"
|
|
|
|
#include "llvm/Object/COFF.h"
|
|
|
|
|
2013-04-20 02:55:00 +00:00
|
|
|
using namespace llvm;
|
2012-06-19 18:02:35 +00:00
|
|
|
|
|
|
|
template <typename One, typename Two>
|
|
|
|
struct pod_pair { // I'd much rather use std::pair, but it's not a POD
|
|
|
|
One first;
|
|
|
|
Two second;
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:55:00 +00:00
|
|
|
#define STRING_PAIR(x) {COFF::x, #x}
|
|
|
|
static const pod_pair<COFF::MachineTypes, const char *>
|
2012-06-19 18:02:35 +00:00
|
|
|
MachineTypePairs [] = {
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_UNKNOWN),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_AM33),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_AMD64),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_ARM),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_ARMV7),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_EBC),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_I386),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_IA64),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_M32R),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_MIPS16),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_MIPSFPU),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_MIPSFPU16),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_POWERPC),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_POWERPCFP),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_R4000),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_SH3),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_SH3DSP),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_SH4),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_SH5),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_THUMB),
|
|
|
|
STRING_PAIR(IMAGE_FILE_MACHINE_WCEMIPSV2)
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:55:00 +00:00
|
|
|
static const pod_pair<COFF::SectionCharacteristics, const char *>
|
2012-06-19 18:02:35 +00:00
|
|
|
SectionCharacteristicsPairs1 [] = {
|
|
|
|
STRING_PAIR(IMAGE_SCN_TYPE_NO_PAD),
|
|
|
|
STRING_PAIR(IMAGE_SCN_CNT_CODE),
|
|
|
|
STRING_PAIR(IMAGE_SCN_CNT_INITIALIZED_DATA),
|
|
|
|
STRING_PAIR(IMAGE_SCN_CNT_UNINITIALIZED_DATA),
|
|
|
|
STRING_PAIR(IMAGE_SCN_LNK_OTHER),
|
|
|
|
STRING_PAIR(IMAGE_SCN_LNK_INFO),
|
|
|
|
STRING_PAIR(IMAGE_SCN_LNK_REMOVE),
|
|
|
|
STRING_PAIR(IMAGE_SCN_LNK_COMDAT),
|
|
|
|
STRING_PAIR(IMAGE_SCN_GPREL),
|
|
|
|
STRING_PAIR(IMAGE_SCN_MEM_PURGEABLE),
|
|
|
|
STRING_PAIR(IMAGE_SCN_MEM_16BIT),
|
|
|
|
STRING_PAIR(IMAGE_SCN_MEM_LOCKED),
|
|
|
|
STRING_PAIR(IMAGE_SCN_MEM_PRELOAD)
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:55:00 +00:00
|
|
|
static const pod_pair<COFF::SectionCharacteristics, const char *>
|
2012-06-19 18:02:35 +00:00
|
|
|
SectionCharacteristicsPairsAlignment [] = {
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_1BYTES),
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_2BYTES),
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_4BYTES),
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_8BYTES),
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_16BYTES),
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_32BYTES),
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_64BYTES),
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_128BYTES),
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_256BYTES),
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_512BYTES),
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_1024BYTES),
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_2048BYTES),
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_4096BYTES),
|
|
|
|
STRING_PAIR(IMAGE_SCN_ALIGN_8192BYTES)
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:55:00 +00:00
|
|
|
static const pod_pair<COFF::SectionCharacteristics, const char *>
|
2012-06-19 18:02:35 +00:00
|
|
|
SectionCharacteristicsPairs2 [] = {
|
|
|
|
STRING_PAIR(IMAGE_SCN_LNK_NRELOC_OVFL),
|
|
|
|
STRING_PAIR(IMAGE_SCN_MEM_DISCARDABLE),
|
|
|
|
STRING_PAIR(IMAGE_SCN_MEM_NOT_CACHED),
|
|
|
|
STRING_PAIR(IMAGE_SCN_MEM_NOT_PAGED),
|
|
|
|
STRING_PAIR(IMAGE_SCN_MEM_SHARED),
|
|
|
|
STRING_PAIR(IMAGE_SCN_MEM_EXECUTE),
|
|
|
|
STRING_PAIR(IMAGE_SCN_MEM_READ),
|
|
|
|
STRING_PAIR(IMAGE_SCN_MEM_WRITE)
|
|
|
|
};
|
2013-04-20 02:55:00 +00:00
|
|
|
|
|
|
|
static const pod_pair<COFF::SymbolBaseType, const char *>
|
2012-06-19 18:02:35 +00:00
|
|
|
SymbolBaseTypePairs [] = {
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_NULL),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_VOID),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_CHAR),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_SHORT),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_INT),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_LONG),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_FLOAT),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_DOUBLE),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_STRUCT),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_UNION),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_ENUM),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_MOE),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_BYTE),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_WORD),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_UINT),
|
|
|
|
STRING_PAIR(IMAGE_SYM_TYPE_DWORD)
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:55:00 +00:00
|
|
|
static const pod_pair<COFF::SymbolComplexType, const char *>
|
2012-06-19 18:02:35 +00:00
|
|
|
SymbolComplexTypePairs [] = {
|
|
|
|
STRING_PAIR(IMAGE_SYM_DTYPE_NULL),
|
|
|
|
STRING_PAIR(IMAGE_SYM_DTYPE_POINTER),
|
|
|
|
STRING_PAIR(IMAGE_SYM_DTYPE_FUNCTION),
|
|
|
|
STRING_PAIR(IMAGE_SYM_DTYPE_ARRAY),
|
|
|
|
};
|
2013-04-20 02:55:00 +00:00
|
|
|
|
|
|
|
static const pod_pair<COFF::SymbolStorageClass, const char *>
|
2012-06-19 18:02:35 +00:00
|
|
|
SymbolStorageClassPairs [] = {
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_END_OF_FUNCTION),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_NULL),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_AUTOMATIC),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_EXTERNAL),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_STATIC),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_REGISTER),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_EXTERNAL_DEF),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_LABEL),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_UNDEFINED_LABEL),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_ARGUMENT),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_STRUCT_TAG),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_MEMBER_OF_UNION),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_UNION_TAG),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_TYPE_DEFINITION),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_UNDEFINED_STATIC),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_ENUM_TAG),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_MEMBER_OF_ENUM),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_REGISTER_PARAM),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_BIT_FIELD),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_BLOCK),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_FUNCTION),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_END_OF_STRUCT),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_FILE),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_SECTION),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_WEAK_EXTERNAL),
|
|
|
|
STRING_PAIR(IMAGE_SYM_CLASS_CLR_TOKEN),
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:55:00 +00:00
|
|
|
static const pod_pair<COFF::RelocationTypeX86, const char *>
|
2012-06-19 18:02:35 +00:00
|
|
|
RelocationTypeX86Pairs [] = {
|
|
|
|
STRING_PAIR(IMAGE_REL_I386_ABSOLUTE),
|
|
|
|
STRING_PAIR(IMAGE_REL_I386_DIR16),
|
|
|
|
STRING_PAIR(IMAGE_REL_I386_REL16),
|
|
|
|
STRING_PAIR(IMAGE_REL_I386_DIR32),
|
|
|
|
STRING_PAIR(IMAGE_REL_I386_DIR32NB),
|
|
|
|
STRING_PAIR(IMAGE_REL_I386_SEG12),
|
|
|
|
STRING_PAIR(IMAGE_REL_I386_SECTION),
|
|
|
|
STRING_PAIR(IMAGE_REL_I386_SECREL),
|
|
|
|
STRING_PAIR(IMAGE_REL_I386_TOKEN),
|
|
|
|
STRING_PAIR(IMAGE_REL_I386_SECREL7),
|
|
|
|
STRING_PAIR(IMAGE_REL_I386_REL32),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_ABSOLUTE),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_ADDR64),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_ADDR32),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_ADDR32NB),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_REL32),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_REL32_1),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_REL32_2),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_REL32_3),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_REL32_4),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_REL32_5),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_SECTION),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_SECREL),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_SECREL7),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_TOKEN),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_SREL32),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_PAIR),
|
|
|
|
STRING_PAIR(IMAGE_REL_AMD64_SSPAN32)
|
|
|
|
};
|
|
|
|
|
2013-04-20 02:55:00 +00:00
|
|
|
static const pod_pair<COFF::RelocationTypesARM, const char *>
|
2012-06-19 18:02:35 +00:00
|
|
|
RelocationTypesARMPairs [] = {
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_ABSOLUTE),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_ADDR32),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_ADDR32NB),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_BRANCH24),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_BRANCH11),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_TOKEN),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_BLX24),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_BLX11),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_SECTION),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_SECREL),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_MOV32A),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_MOV32T),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_BRANCH20T),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_BRANCH24T),
|
|
|
|
STRING_PAIR(IMAGE_REL_ARM_BLX23T)
|
|
|
|
};
|
|
|
|
#undef STRING_PAIR
|
|
|
|
|
2013-04-20 02:55:00 +00:00
|
|
|
static raw_ostream &writeName(raw_ostream &Out,
|
|
|
|
const char *Name, std::size_t NameSize) {
|
2012-06-19 18:02:35 +00:00
|
|
|
for (std::size_t i = 0; i < NameSize; ++i) {
|
|
|
|
if (!Name[i]) break;
|
|
|
|
Out << Name[i];
|
|
|
|
}
|
|
|
|
return Out;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given an array of pod_pair<enum, const char *>, write all enums that match
|
|
|
|
template <typename T, std::size_t N>
|
2013-04-20 02:55:00 +00:00
|
|
|
static raw_ostream &writeBitMask(raw_ostream &Out,
|
|
|
|
const pod_pair<T, const char *> (&Arr)[N],
|
|
|
|
unsigned long Val) {
|
2012-06-19 18:02:35 +00:00
|
|
|
for (std::size_t i = 0; i < N; ++i)
|
|
|
|
if (Val & Arr[i].first)
|
|
|
|
Out << Arr[i].second << ", ";
|
|
|
|
return Out;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Given an array of pod_pair<enum, const char *>, look up a value
|
|
|
|
template <typename T, std::size_t N>
|
2013-04-20 02:55:00 +00:00
|
|
|
const char *nameLookup(const pod_pair<T, const char *> (&Arr)[N],
|
|
|
|
unsigned long Val, const char *NotFound = NULL) {
|
2012-06-19 18:02:35 +00:00
|
|
|
T n = static_cast<T>(Val);
|
|
|
|
for (std::size_t i = 0; i < N; ++i)
|
|
|
|
if (n == Arr[i].first)
|
|
|
|
return Arr[i].second;
|
|
|
|
return NotFound;
|
|
|
|
}
|
|
|
|
|
2013-04-20 03:33:09 +00:00
|
|
|
static void yamlCOFFHeader(const object::coff_file_header *Header,
|
|
|
|
raw_ostream &Out) {
|
2013-04-20 03:13:00 +00:00
|
|
|
COFF::header H;
|
|
|
|
H.Machine = Header->Machine;
|
|
|
|
H.Characteristics = Header->Characteristics;
|
2012-06-19 18:02:35 +00:00
|
|
|
|
2013-04-08 08:55:18 +00:00
|
|
|
Out << "header: !Header\n";
|
2012-06-19 18:02:35 +00:00
|
|
|
Out << " Machine: ";
|
|
|
|
Out << nameLookup(MachineTypePairs, Header->Machine, "# Unknown_MachineTypes")
|
|
|
|
<< " # (";
|
2013-04-20 03:33:09 +00:00
|
|
|
objyaml::writeHexNumber(Out, Header->Machine) << ")\n\n";
|
2012-06-19 18:02:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-20 03:33:09 +00:00
|
|
|
static void yamlCOFFSections(object::COFFObjectFile &Obj,
|
|
|
|
std::size_t NumSections, raw_ostream &Out) {
|
2013-04-20 02:55:00 +00:00
|
|
|
error_code ec;
|
2013-04-08 08:55:18 +00:00
|
|
|
Out << "sections:\n";
|
2013-04-20 02:55:00 +00:00
|
|
|
for (object::section_iterator iter = Obj.begin_sections();
|
|
|
|
iter != Obj.end_sections(); iter.increment(ec)) {
|
|
|
|
const object::coff_section *sect = Obj.getCOFFSection(iter);
|
|
|
|
|
2013-04-08 08:55:18 +00:00
|
|
|
Out << " - !Section\n";
|
2012-06-19 18:02:35 +00:00
|
|
|
Out << " Name: ";
|
2013-04-20 03:13:00 +00:00
|
|
|
writeName(Out, sect->Name, sizeof(sect->Name)) << '\n';
|
2012-06-19 18:02:35 +00:00
|
|
|
|
|
|
|
Out << " Characteristics: [";
|
2013-04-20 03:13:00 +00:00
|
|
|
writeBitMask(Out, SectionCharacteristicsPairs1, sect->Characteristics);
|
2013-04-20 02:55:00 +00:00
|
|
|
Out << nameLookup(SectionCharacteristicsPairsAlignment,
|
|
|
|
sect->Characteristics & 0x00F00000, "# Unrecognized_IMAGE_SCN_ALIGN")
|
2012-06-19 18:02:35 +00:00
|
|
|
<< ", ";
|
2013-04-20 03:13:00 +00:00
|
|
|
writeBitMask(Out, SectionCharacteristicsPairs2, sect->Characteristics);
|
2012-06-19 18:02:35 +00:00
|
|
|
Out << "] # ";
|
2013-04-20 03:16:59 +00:00
|
|
|
objyaml::writeHexNumber(Out, sect->Characteristics) << '\n';
|
2012-06-19 18:02:35 +00:00
|
|
|
|
2013-04-20 02:55:00 +00:00
|
|
|
ArrayRef<uint8_t> sectionData;
|
|
|
|
Obj.getSectionContents(sect, sectionData);
|
2012-06-19 18:02:35 +00:00
|
|
|
Out << " SectionData: ";
|
2013-04-20 03:16:59 +00:00
|
|
|
objyaml::writeHexStream(Out, sectionData) << '\n';
|
2012-07-31 22:04:08 +00:00
|
|
|
if (iter->begin_relocations() != iter->end_relocations())
|
|
|
|
Out << " Relocations:\n";
|
2013-04-20 02:55:00 +00:00
|
|
|
for (object::relocation_iterator rIter = iter->begin_relocations();
|
2012-06-19 18:02:35 +00:00
|
|
|
rIter != iter->end_relocations(); rIter.increment(ec)) {
|
2013-04-20 02:55:00 +00:00
|
|
|
const object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter);
|
2012-06-19 18:02:35 +00:00
|
|
|
|
2013-04-08 08:55:18 +00:00
|
|
|
Out << " - !Relocation\n";
|
2012-06-19 18:02:35 +00:00
|
|
|
Out << " VirtualAddress: " ;
|
2013-04-20 03:16:59 +00:00
|
|
|
objyaml::writeHexNumber(Out, reloc->VirtualAddress) << '\n';
|
2013-04-08 08:55:18 +00:00
|
|
|
Out << " SymbolTableIndex: " << reloc->SymbolTableIndex << '\n';
|
2013-04-20 02:55:00 +00:00
|
|
|
Out << " Type: "
|
2013-04-08 08:55:18 +00:00
|
|
|
<< nameLookup(RelocationTypeX86Pairs, reloc->Type) << '\n';
|
2012-06-19 18:02:35 +00:00
|
|
|
// TODO: Use the correct reloc type for the machine.
|
2013-04-08 08:55:18 +00:00
|
|
|
Out << '\n';
|
2012-06-19 18:02:35 +00:00
|
|
|
}
|
|
|
|
|
2013-04-20 02:55:00 +00:00
|
|
|
}
|
2012-06-19 18:02:35 +00:00
|
|
|
}
|
|
|
|
|
2013-04-20 03:33:09 +00:00
|
|
|
static void yamlCOFFSymbols(object::COFFObjectFile &Obj, std::size_t NumSymbols,
|
|
|
|
raw_ostream &Out) {
|
2013-04-20 02:55:00 +00:00
|
|
|
error_code ec;
|
2013-04-08 08:55:18 +00:00
|
|
|
Out << "symbols:\n";
|
2013-04-20 02:55:00 +00:00
|
|
|
for (object::symbol_iterator iter = Obj.begin_symbols();
|
|
|
|
iter != Obj.end_symbols(); iter.increment(ec)) {
|
2012-06-19 18:02:35 +00:00
|
|
|
// Gather all the info that we need
|
2013-04-20 02:55:00 +00:00
|
|
|
StringRef str;
|
|
|
|
const object::coff_symbol *symbol = Obj.getCOFFSymbol(iter);
|
2012-06-19 18:02:35 +00:00
|
|
|
Obj.getSymbolName(symbol, str);
|
|
|
|
std::size_t simpleType = symbol->getBaseType();
|
|
|
|
std::size_t complexType = symbol->getComplexType();
|
|
|
|
std::size_t storageClass = symbol->StorageClass;
|
2013-04-20 02:55:00 +00:00
|
|
|
|
2013-04-08 08:55:18 +00:00
|
|
|
Out << " - !Symbol\n";
|
2013-04-20 02:55:00 +00:00
|
|
|
Out << " Name: " << str << '\n';
|
2012-06-19 18:02:35 +00:00
|
|
|
|
2013-04-08 08:55:18 +00:00
|
|
|
Out << " Value: " << symbol->Value << '\n';
|
|
|
|
Out << " SectionNumber: " << symbol->SectionNumber << '\n';
|
2012-06-19 18:02:35 +00:00
|
|
|
|
2013-04-20 02:55:00 +00:00
|
|
|
Out << " SimpleType: "
|
|
|
|
<< nameLookup(SymbolBaseTypePairs, simpleType,
|
|
|
|
"# Unknown_SymbolBaseType")
|
2013-04-08 08:55:18 +00:00
|
|
|
<< " # (" << simpleType << ")\n";
|
2013-04-20 02:55:00 +00:00
|
|
|
|
|
|
|
Out << " ComplexType: "
|
|
|
|
<< nameLookup(SymbolComplexTypePairs, complexType,
|
|
|
|
"# Unknown_SymbolComplexType")
|
2013-04-08 08:55:18 +00:00
|
|
|
<< " # (" << complexType << ")\n";
|
2013-04-20 02:55:00 +00:00
|
|
|
|
|
|
|
Out << " StorageClass: "
|
2012-06-19 18:02:35 +00:00
|
|
|
<< nameLookup(SymbolStorageClassPairs, storageClass,
|
2013-04-20 02:55:00 +00:00
|
|
|
"# Unknown_StorageClass")
|
2013-04-08 08:55:18 +00:00
|
|
|
<< " # (" << (int) storageClass << ")\n";
|
2012-06-19 18:02:35 +00:00
|
|
|
|
|
|
|
if (symbol->NumberOfAuxSymbols > 0) {
|
2013-04-20 02:55:00 +00:00
|
|
|
ArrayRef<uint8_t> aux = Obj.getSymbolAuxData(symbol);
|
|
|
|
Out << " NumberOfAuxSymbols: "
|
2013-04-08 08:55:18 +00:00
|
|
|
<< (int) symbol->NumberOfAuxSymbols << '\n';
|
2012-06-19 18:02:35 +00:00
|
|
|
Out << " AuxillaryData: ";
|
2013-04-20 03:16:59 +00:00
|
|
|
objyaml::writeHexStream(Out, aux);
|
2012-06-19 18:02:35 +00:00
|
|
|
}
|
2013-04-20 02:55:00 +00:00
|
|
|
|
2013-04-08 08:55:18 +00:00
|
|
|
Out << '\n';
|
2012-06-19 18:02:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-20 02:55:00 +00:00
|
|
|
error_code coff2yaml(raw_ostream &Out, MemoryBuffer *TheObj) {
|
|
|
|
error_code ec;
|
|
|
|
object::COFFObjectFile obj(TheObj, ec);
|
|
|
|
if (ec)
|
|
|
|
return ec;
|
|
|
|
|
|
|
|
const object::coff_file_header *hd;
|
|
|
|
ec = obj.getHeader(hd);
|
|
|
|
if (ec)
|
|
|
|
return ec;
|
|
|
|
|
|
|
|
yamlCOFFHeader(hd, Out);
|
|
|
|
yamlCOFFSections(obj, hd->NumberOfSections, Out);
|
|
|
|
yamlCOFFSymbols(obj, hd->NumberOfSymbols, Out);
|
|
|
|
|
2012-06-19 18:02:35 +00:00
|
|
|
return ec;
|
|
|
|
}
|