mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-24 21:15:04 +00:00
18245f6cf7
This patch adds support for round tripping DWARF debug_aranges in and out of YAML. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289161 91177308-0d34-0410-b5e6-96231b3b80d8
69 lines
2.2 KiB
C++
69 lines
2.2 KiB
C++
//===- yaml2dwarf - Convert YAML to DWARF binary data ---------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// \brief The DWARF component of yaml2obj.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ObjectYAML/DWARFYAML.h"
|
|
#include "llvm/Support/Error.h"
|
|
#include "llvm/Support/LEB128.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
void ZeroFillBytes(raw_ostream &OS, size_t Size) {
|
|
std::vector<uint8_t> FillData;
|
|
FillData.insert(FillData.begin(), Size, 0);
|
|
OS.write(reinterpret_cast<char *>(FillData.data()), Size);
|
|
}
|
|
|
|
void yaml2debug_str(raw_ostream &OS, const DWARFYAML::Data &DI) {
|
|
for (auto Str : DI.DebugStrings) {
|
|
OS.write(Str.data(), Str.size());
|
|
OS.write('\0');
|
|
}
|
|
}
|
|
|
|
void yaml2debug_abbrev(raw_ostream &OS, const DWARFYAML::Data &DI) {
|
|
for (auto AbbrevDecl : DI.AbbrevDecls) {
|
|
encodeULEB128(AbbrevDecl.Code, OS);
|
|
encodeULEB128(AbbrevDecl.Tag, OS);
|
|
OS.write(AbbrevDecl.Children);
|
|
for (auto Attr : AbbrevDecl.Attributes) {
|
|
encodeULEB128(Attr.Attribute, OS);
|
|
encodeULEB128(Attr.Form, OS);
|
|
}
|
|
encodeULEB128(0, OS);
|
|
encodeULEB128(0, OS);
|
|
}
|
|
}
|
|
|
|
void yaml2debug_aranges(raw_ostream &OS, const DWARFYAML::Data &DI) {
|
|
for (auto Range : DI.ARanges) {
|
|
auto HeaderStart = OS.tell();
|
|
OS.write(reinterpret_cast<char *>(&Range.Length), 4);
|
|
OS.write(reinterpret_cast<char *>(&Range.Version), 2);
|
|
OS.write(reinterpret_cast<char *>(&Range.CuOffset), 4);
|
|
OS.write(reinterpret_cast<char *>(&Range.AddrSize), 1);
|
|
OS.write(reinterpret_cast<char *>(&Range.SegSize), 1);
|
|
|
|
auto HeaderSize = OS.tell() - HeaderStart;
|
|
auto FirstDescriptor = alignTo(HeaderSize, Range.AddrSize * 2);
|
|
ZeroFillBytes(OS, FirstDescriptor - HeaderSize);
|
|
|
|
for (auto Descriptor : Range.Descriptors) {
|
|
OS.write(reinterpret_cast<char *>(&Descriptor.Address), Range.AddrSize);
|
|
OS.write(reinterpret_cast<char *>(&Descriptor.Length), Range.AddrSize);
|
|
}
|
|
ZeroFillBytes(OS, Range.AddrSize * 2);
|
|
}
|
|
}
|