#include "llvm/ObjectYAML/DWARFEmitter.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/ObjectYAML/DWARFYAML.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/SwapByteOrder.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Host.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <vector>
usingnamespacellvm;
template <typename T>
static void writeInteger(T Integer, raw_ostream &OS, bool IsLittleEndian) { … }
static Error writeVariableSizedInteger(uint64_t Integer, size_t Size,
raw_ostream &OS, bool IsLittleEndian) { … }
static void ZeroFillBytes(raw_ostream &OS, size_t Size) { … }
static void writeInitialLength(const dwarf::DwarfFormat Format,
const uint64_t Length, raw_ostream &OS,
bool IsLittleEndian) { … }
static void writeDWARFOffset(uint64_t Offset, dwarf::DwarfFormat Format,
raw_ostream &OS, bool IsLittleEndian) { … }
Error DWARFYAML::emitDebugStr(raw_ostream &OS, const DWARFYAML::Data &DI) { … }
StringRef DWARFYAML::Data::getAbbrevTableContentByIndex(uint64_t Index) const { … }
Error DWARFYAML::emitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) { … }
Error DWARFYAML::emitDebugAranges(raw_ostream &OS, const DWARFYAML::Data &DI) { … }
Error DWARFYAML::emitDebugRanges(raw_ostream &OS, const DWARFYAML::Data &DI) { … }
static Error emitPubSection(raw_ostream &OS, const DWARFYAML::PubSection &Sect,
bool IsLittleEndian, bool IsGNUPubSec = false) { … }
Error DWARFYAML::emitDebugPubnames(raw_ostream &OS, const Data &DI) { … }
Error DWARFYAML::emitDebugPubtypes(raw_ostream &OS, const Data &DI) { … }
Error DWARFYAML::emitDebugGNUPubnames(raw_ostream &OS, const Data &DI) { … }
Error DWARFYAML::emitDebugGNUPubtypes(raw_ostream &OS, const Data &DI) { … }
static Expected<uint64_t> writeDIE(const DWARFYAML::Data &DI, uint64_t CUIndex,
uint64_t AbbrevTableID,
const dwarf::FormParams &Params,
const DWARFYAML::Entry &Entry,
raw_ostream &OS, bool IsLittleEndian) { … }
Error DWARFYAML::emitDebugInfo(raw_ostream &OS, const DWARFYAML::Data &DI) { … }
static void emitFileEntry(raw_ostream &OS, const DWARFYAML::File &File) { … }
static void writeExtendedOpcode(const DWARFYAML::LineTableOpcode &Op,
uint8_t AddrSize, bool IsLittleEndian,
raw_ostream &OS) { … }
static void writeLineTableOpcode(const DWARFYAML::LineTableOpcode &Op,
uint8_t OpcodeBase, uint8_t AddrSize,
raw_ostream &OS, bool IsLittleEndian) { … }
static std::vector<uint8_t>
getStandardOpcodeLengths(uint16_t Version, std::optional<uint8_t> OpcodeBase) { … }
Error DWARFYAML::emitDebugLine(raw_ostream &OS, const DWARFYAML::Data &DI) { … }
Error DWARFYAML::emitDebugAddr(raw_ostream &OS, const Data &DI) { … }
Error DWARFYAML::emitDebugStrOffsets(raw_ostream &OS, const Data &DI) { … }
namespace {
void emitDebugNamesHeader(raw_ostream &OS, bool IsLittleEndian,
uint32_t NameCount, uint32_t AbbrevSize,
uint32_t CombinedSizeOtherParts) { … }
std::string
emitDebugNamesAbbrev(ArrayRef<DWARFYAML::DebugNameAbbreviation> Abbrevs) { … }
std::string emitDebugNamesCUOffsets(bool IsLittleEndian) { … }
std::string emitDebugNamesNameTable(
bool IsLittleEndian,
const DenseMap<uint32_t, std::vector<DWARFYAML::DebugNameEntry>> &Entries,
ArrayRef<uint32_t> EntryPoolOffsets) { … }
DenseMap<uint32_t, std::vector<DWARFYAML::DebugNameEntry>>
groupEntries(ArrayRef<DWARFYAML::DebugNameEntry> Entries) { … }
Expected<SmallVector<uint8_t>>
getNonZeroDataSizesFor(uint32_t AbbrevCode,
ArrayRef<DWARFYAML::DebugNameAbbreviation> Abbrevs) { … }
struct PoolOffsetsAndData { … };
Expected<PoolOffsetsAndData> emitDebugNamesEntryPool(
bool IsLittleEndian,
const DenseMap<uint32_t, std::vector<DWARFYAML::DebugNameEntry>>
&StrpToEntries,
ArrayRef<DWARFYAML::DebugNameAbbreviation> Abbrevs) { … }
}
Error DWARFYAML::emitDebugNames(raw_ostream &OS, const Data &DI) { … }
static Error checkOperandCount(StringRef EncodingString,
ArrayRef<yaml::Hex64> Values,
uint64_t ExpectedOperands) { … }
static Error writeListEntryAddress(StringRef EncodingName, raw_ostream &OS,
uint64_t Addr, uint8_t AddrSize,
bool IsLittleEndian) { … }
static Expected<uint64_t>
writeDWARFExpression(raw_ostream &OS,
const DWARFYAML::DWARFOperation &Operation,
uint8_t AddrSize, bool IsLittleEndian) { … }
static Expected<uint64_t> writeListEntry(raw_ostream &OS,
const DWARFYAML::RnglistEntry &Entry,
uint8_t AddrSize,
bool IsLittleEndian) { … }
static Expected<uint64_t> writeListEntry(raw_ostream &OS,
const DWARFYAML::LoclistEntry &Entry,
uint8_t AddrSize,
bool IsLittleEndian) { … }
template <typename EntryType>
static Error writeDWARFLists(raw_ostream &OS,
ArrayRef<DWARFYAML::ListTable<EntryType>> Tables,
bool IsLittleEndian, bool Is64BitAddrSize) { … }
Error DWARFYAML::emitDebugRnglists(raw_ostream &OS, const Data &DI) { … }
Error DWARFYAML::emitDebugLoclists(raw_ostream &OS, const Data &DI) { … }
std::function<Error(raw_ostream &, const DWARFYAML::Data &)>
DWARFYAML::getDWARFEmitterByName(StringRef SecName) { … }
static Error
emitDebugSectionImpl(const DWARFYAML::Data &DI, StringRef Sec,
StringMap<std::unique_ptr<MemoryBuffer>> &OutputBuffers) { … }
Expected<StringMap<std::unique_ptr<MemoryBuffer>>>
DWARFYAML::emitDebugSections(StringRef YAMLString, bool IsLittleEndian,
bool Is64BitAddrSize) { … }