Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,4 @@
add_subdirectory(ELF)
add_subdirectory(Mach-O)
add_subdirectory(PECOFF)
add_subdirectory(JIT)

View File

@@ -0,0 +1,14 @@
add_lldb_library(lldbPluginObjectFileELF PLUGIN
ELFHeader.cpp
ObjectFileELF.cpp
LINK_LIBS
lldbCore
lldbHost
lldbSymbol
lldbTarget
LINK_COMPONENTS
BinaryFormat
Object
Support
)

View File

@@ -0,0 +1,448 @@
//===-- ELFHeader.cpp ----------------------------------------- -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <cstring>
#include "lldb/Core/Section.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/Stream.h"
#include "ELFHeader.h"
using namespace elf;
using namespace lldb;
using namespace llvm::ELF;
//------------------------------------------------------------------------------
// Static utility functions.
//
// GetMaxU64 and GetMaxS64 wrap the similarly named methods from DataExtractor
// with error handling code and provide for parsing a sequence of values.
static bool GetMaxU64(const lldb_private::DataExtractor &data,
lldb::offset_t *offset, uint64_t *value,
uint32_t byte_size) {
const lldb::offset_t saved_offset = *offset;
*value = data.GetMaxU64(offset, byte_size);
return *offset != saved_offset;
}
static bool GetMaxU64(const lldb_private::DataExtractor &data,
lldb::offset_t *offset, uint64_t *value,
uint32_t byte_size, uint32_t count) {
lldb::offset_t saved_offset = *offset;
for (uint32_t i = 0; i < count; ++i, ++value) {
if (GetMaxU64(data, offset, value, byte_size) == false) {
*offset = saved_offset;
return false;
}
}
return true;
}
static bool GetMaxS64(const lldb_private::DataExtractor &data,
lldb::offset_t *offset, int64_t *value,
uint32_t byte_size) {
const lldb::offset_t saved_offset = *offset;
*value = data.GetMaxS64(offset, byte_size);
return *offset != saved_offset;
}
static bool GetMaxS64(const lldb_private::DataExtractor &data,
lldb::offset_t *offset, int64_t *value,
uint32_t byte_size, uint32_t count) {
lldb::offset_t saved_offset = *offset;
for (uint32_t i = 0; i < count; ++i, ++value) {
if (GetMaxS64(data, offset, value, byte_size) == false) {
*offset = saved_offset;
return false;
}
}
return true;
}
//------------------------------------------------------------------------------
// ELFHeader
ELFHeader::ELFHeader() { memset(this, 0, sizeof(ELFHeader)); }
ByteOrder ELFHeader::GetByteOrder() const {
if (e_ident[EI_DATA] == ELFDATA2MSB)
return eByteOrderBig;
if (e_ident[EI_DATA] == ELFDATA2LSB)
return eByteOrderLittle;
return eByteOrderInvalid;
}
bool ELFHeader::HasHeaderExtension() const {
bool result = false;
// Check if any of these values looks like sentinel.
result |= e_phnum_hdr == 0xFFFF; // PN_XNUM
result |= e_shnum_hdr == SHN_UNDEF;
result |= e_shstrndx_hdr == SHN_XINDEX;
// If header extension is present, the section offset cannot be null.
result &= e_shoff != 0;
// Done.
return result;
}
void ELFHeader::ParseHeaderExtension(lldb_private::DataExtractor &data) {
// Extract section #0 header.
ELFSectionHeader section_zero;
lldb::offset_t offset = 0;
lldb_private::DataExtractor sh_data(data, e_shoff, e_shentsize);
bool ok = section_zero.Parse(sh_data, &offset);
// If we succeeded, fix the header.
if (ok) {
if (e_phnum_hdr == 0xFFFF) // PN_XNUM
e_phnum = section_zero.sh_info;
if (e_shnum_hdr == SHN_UNDEF)
e_shnum = section_zero.sh_size;
if (e_shstrndx_hdr == SHN_XINDEX)
e_shstrndx = section_zero.sh_link;
}
}
bool ELFHeader::Parse(lldb_private::DataExtractor &data,
lldb::offset_t *offset) {
// Read e_ident. This provides byte order and address size info.
if (data.GetU8(offset, &e_ident, EI_NIDENT) == NULL)
return false;
const unsigned byte_size = Is32Bit() ? 4 : 8;
data.SetByteOrder(GetByteOrder());
data.SetAddressByteSize(byte_size);
// Read e_type and e_machine.
if (data.GetU16(offset, &e_type, 2) == NULL)
return false;
// Read e_version.
if (data.GetU32(offset, &e_version, 1) == NULL)
return false;
// Read e_entry, e_phoff and e_shoff.
if (GetMaxU64(data, offset, &e_entry, byte_size, 3) == false)
return false;
// Read e_flags.
if (data.GetU32(offset, &e_flags, 1) == NULL)
return false;
// Read e_ehsize, e_phentsize, e_phnum, e_shentsize, e_shnum and
// e_shstrndx.
if (data.GetU16(offset, &e_ehsize, 6) == NULL)
return false;
// Initialize e_phnum, e_shnum, and e_shstrndx with the values
// read from the header.
e_phnum = e_phnum_hdr;
e_shnum = e_shnum_hdr;
e_shstrndx = e_shstrndx_hdr;
// See if we have extended header in section #0.
if (HasHeaderExtension())
ParseHeaderExtension(data);
return true;
}
bool ELFHeader::MagicBytesMatch(const uint8_t *magic) {
return memcmp(magic, ElfMagic, strlen(ElfMagic)) == 0;
}
unsigned ELFHeader::AddressSizeInBytes(const uint8_t *magic) {
unsigned address_size = 0;
switch (magic[EI_CLASS]) {
case ELFCLASS32:
address_size = 4;
break;
case ELFCLASS64:
address_size = 8;
break;
}
return address_size;
}
unsigned ELFHeader::GetRelocationJumpSlotType() const {
unsigned slot = 0;
switch (e_machine) {
default:
assert(false && "architecture not supported");
break;
case EM_PPC:
slot = R_PPC_JMP_SLOT;
break;
case EM_PPC64:
slot = R_PPC64_JMP_SLOT;
break;
case EM_386:
case EM_IAMCU: // FIXME: is this correct?
slot = R_386_JUMP_SLOT;
break;
case EM_X86_64:
slot = R_X86_64_JUMP_SLOT;
break;
case EM_ARM:
slot = R_ARM_JUMP_SLOT;
break;
case EM_HEXAGON:
slot = R_HEX_JMP_SLOT;
break;
case EM_AARCH64:
slot = R_AARCH64_JUMP_SLOT;
break;
case EM_MIPS:
slot = R_MIPS_JUMP_SLOT;
break;
case EM_S390:
slot = R_390_JMP_SLOT;
break;
}
return slot;
}
//------------------------------------------------------------------------------
// ELFSectionHeader
ELFSectionHeader::ELFSectionHeader() {
memset(this, 0, sizeof(ELFSectionHeader));
}
bool ELFSectionHeader::Parse(const lldb_private::DataExtractor &data,
lldb::offset_t *offset) {
const unsigned byte_size = data.GetAddressByteSize();
// Read sh_name and sh_type.
if (data.GetU32(offset, &sh_name, 2) == NULL)
return false;
// Read sh_flags.
if (GetMaxU64(data, offset, &sh_flags, byte_size) == false)
return false;
// Read sh_addr, sh_off and sh_size.
if (GetMaxU64(data, offset, &sh_addr, byte_size, 3) == false)
return false;
// Read sh_link and sh_info.
if (data.GetU32(offset, &sh_link, 2) == NULL)
return false;
// Read sh_addralign and sh_entsize.
if (GetMaxU64(data, offset, &sh_addralign, byte_size, 2) == false)
return false;
return true;
}
//------------------------------------------------------------------------------
// ELFSymbol
ELFSymbol::ELFSymbol() { memset(this, 0, sizeof(ELFSymbol)); }
#define ENUM_TO_CSTR(e) \
case e: \
return #e
const char *ELFSymbol::bindingToCString(unsigned char binding) {
switch (binding) {
ENUM_TO_CSTR(STB_LOCAL);
ENUM_TO_CSTR(STB_GLOBAL);
ENUM_TO_CSTR(STB_WEAK);
ENUM_TO_CSTR(STB_LOOS);
ENUM_TO_CSTR(STB_HIOS);
ENUM_TO_CSTR(STB_LOPROC);
ENUM_TO_CSTR(STB_HIPROC);
}
return "";
}
const char *ELFSymbol::typeToCString(unsigned char type) {
switch (type) {
ENUM_TO_CSTR(STT_NOTYPE);
ENUM_TO_CSTR(STT_OBJECT);
ENUM_TO_CSTR(STT_FUNC);
ENUM_TO_CSTR(STT_SECTION);
ENUM_TO_CSTR(STT_FILE);
ENUM_TO_CSTR(STT_COMMON);
ENUM_TO_CSTR(STT_TLS);
ENUM_TO_CSTR(STT_GNU_IFUNC);
ENUM_TO_CSTR(STT_HIOS);
ENUM_TO_CSTR(STT_LOPROC);
ENUM_TO_CSTR(STT_HIPROC);
}
return "";
}
const char *ELFSymbol::sectionIndexToCString(
elf_half shndx, const lldb_private::SectionList *section_list) {
switch (shndx) {
ENUM_TO_CSTR(SHN_UNDEF);
ENUM_TO_CSTR(SHN_LOPROC);
ENUM_TO_CSTR(SHN_HIPROC);
ENUM_TO_CSTR(SHN_LOOS);
ENUM_TO_CSTR(SHN_HIOS);
ENUM_TO_CSTR(SHN_ABS);
ENUM_TO_CSTR(SHN_COMMON);
ENUM_TO_CSTR(SHN_XINDEX);
default: {
const lldb_private::Section *section =
section_list->GetSectionAtIndex(shndx).get();
if (section)
return section->GetName().AsCString("");
} break;
}
return "";
}
void ELFSymbol::Dump(lldb_private::Stream *s, uint32_t idx,
const lldb_private::DataExtractor *strtab_data,
const lldb_private::SectionList *section_list) {
s->Printf("[%3u] 0x%16.16" PRIx64 " 0x%16.16" PRIx64
" 0x%8.8x 0x%2.2x (%-10s %-13s) 0x%2.2x 0x%4.4x (%-10s) %s\n",
idx, st_value, st_size, st_name, st_info,
bindingToCString(getBinding()), typeToCString(getType()), st_other,
st_shndx, sectionIndexToCString(st_shndx, section_list),
strtab_data ? strtab_data->PeekCStr(st_name) : "");
}
bool ELFSymbol::Parse(const lldb_private::DataExtractor &data,
lldb::offset_t *offset) {
const unsigned byte_size = data.GetAddressByteSize();
const bool parsing_32 = byte_size == 4;
// Read st_name.
if (data.GetU32(offset, &st_name, 1) == NULL)
return false;
if (parsing_32) {
// Read st_value and st_size.
if (GetMaxU64(data, offset, &st_value, byte_size, 2) == false)
return false;
// Read st_info and st_other.
if (data.GetU8(offset, &st_info, 2) == NULL)
return false;
// Read st_shndx.
if (data.GetU16(offset, &st_shndx, 1) == NULL)
return false;
} else {
// Read st_info and st_other.
if (data.GetU8(offset, &st_info, 2) == NULL)
return false;
// Read st_shndx.
if (data.GetU16(offset, &st_shndx, 1) == NULL)
return false;
// Read st_value and st_size.
if (data.GetU64(offset, &st_value, 2) == NULL)
return false;
}
return true;
}
//------------------------------------------------------------------------------
// ELFProgramHeader
ELFProgramHeader::ELFProgramHeader() {
memset(this, 0, sizeof(ELFProgramHeader));
}
bool ELFProgramHeader::Parse(const lldb_private::DataExtractor &data,
lldb::offset_t *offset) {
const uint32_t byte_size = data.GetAddressByteSize();
const bool parsing_32 = byte_size == 4;
// Read p_type;
if (data.GetU32(offset, &p_type, 1) == NULL)
return false;
if (parsing_32) {
// Read p_offset, p_vaddr, p_paddr, p_filesz and p_memsz.
if (GetMaxU64(data, offset, &p_offset, byte_size, 5) == false)
return false;
// Read p_flags.
if (data.GetU32(offset, &p_flags, 1) == NULL)
return false;
// Read p_align.
if (GetMaxU64(data, offset, &p_align, byte_size) == false)
return false;
} else {
// Read p_flags.
if (data.GetU32(offset, &p_flags, 1) == NULL)
return false;
// Read p_offset, p_vaddr, p_paddr, p_filesz, p_memsz and p_align.
if (GetMaxU64(data, offset, &p_offset, byte_size, 6) == false)
return false;
}
return true;
}
//------------------------------------------------------------------------------
// ELFDynamic
ELFDynamic::ELFDynamic() { memset(this, 0, sizeof(ELFDynamic)); }
bool ELFDynamic::Parse(const lldb_private::DataExtractor &data,
lldb::offset_t *offset) {
const unsigned byte_size = data.GetAddressByteSize();
return GetMaxS64(data, offset, &d_tag, byte_size, 2);
}
//------------------------------------------------------------------------------
// ELFRel
ELFRel::ELFRel() { memset(this, 0, sizeof(ELFRel)); }
bool ELFRel::Parse(const lldb_private::DataExtractor &data,
lldb::offset_t *offset) {
const unsigned byte_size = data.GetAddressByteSize();
// Read r_offset and r_info.
if (GetMaxU64(data, offset, &r_offset, byte_size, 2) == false)
return false;
return true;
}
//------------------------------------------------------------------------------
// ELFRela
ELFRela::ELFRela() { memset(this, 0, sizeof(ELFRela)); }
bool ELFRela::Parse(const lldb_private::DataExtractor &data,
lldb::offset_t *offset) {
const unsigned byte_size = data.GetAddressByteSize();
// Read r_offset and r_info.
if (GetMaxU64(data, offset, &r_offset, byte_size, 2) == false)
return false;
// Read r_addend;
if (GetMaxS64(data, offset, &r_addend, byte_size) == false)
return false;
return true;
}

View File

@@ -0,0 +1,412 @@
//===-- ELFHeader.h ------------------------------------------- -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
/// @file
/// @brief Generic structures and typedefs for ELF files.
///
/// This file provides definitions for the various entities comprising an ELF
/// file. The structures are generic in the sense that they do not correspond
/// to the exact binary layout of an ELF, but can be used to hold the
/// information present in both 32 and 64 bit variants of the format. Each
/// entity provides a \c Parse method which is capable of transparently reading
/// both 32 and 64 bit instances of the object.
//===----------------------------------------------------------------------===//
#ifndef liblldb_ELFHeader_h_
#define liblldb_ELFHeader_h_
#include "llvm/BinaryFormat/ELF.h"
#include "lldb/lldb-enumerations.h"
#include "lldb/lldb-types.h"
namespace lldb_private {
class DataExtractor;
} // End namespace lldb_private.
namespace elf {
//------------------------------------------------------------------------------
/// @name ELF type definitions.
///
/// Types used to represent the various components of ELF structures. All types
/// are signed or unsigned integral types wide enough to hold values from both
/// 32 and 64 bit ELF variants.
//@{
typedef uint64_t elf_addr;
typedef uint64_t elf_off;
typedef uint16_t elf_half;
typedef uint32_t elf_word;
typedef int32_t elf_sword;
typedef uint64_t elf_size;
typedef uint64_t elf_xword;
typedef int64_t elf_sxword;
//@}
//------------------------------------------------------------------------------
/// @class ELFHeader
/// @brief Generic representation of an ELF file header.
///
/// This object is used to identify the general attributes on an ELF file and to
/// locate additional sections within the file.
struct ELFHeader {
unsigned char e_ident[llvm::ELF::EI_NIDENT]; ///< ELF file identification.
elf_addr e_entry; ///< Virtual address program entry point.
elf_off e_phoff; ///< File offset of program header table.
elf_off e_shoff; ///< File offset of section header table.
elf_word e_flags; ///< Processor specific flags.
elf_word e_version; ///< Version of object file (always 1).
elf_half e_type; ///< Object file type.
elf_half e_machine; ///< Target architecture.
elf_half e_ehsize; ///< Byte size of the ELF header.
elf_half e_phentsize; ///< Size of a program header table entry.
elf_half e_phnum_hdr; ///< Number of program header entries.
elf_half e_shentsize; ///< Size of a section header table entry.
elf_half e_shnum_hdr; ///< Number of section header entries.
elf_half e_shstrndx_hdr; ///< String table section index.
// In some cases these numbers do not fit in 16 bits and they are
// stored outside of the header in section #0. Here are the actual
// values.
elf_word e_phnum; ///< Number of program header entries.
elf_word e_shnum; ///< Number of section header entries.
elf_word e_shstrndx; ///< String table section index.
ELFHeader();
//--------------------------------------------------------------------------
/// Returns true if this is a 32 bit ELF file header.
///
/// @return
/// True if this is a 32 bit ELF file header.
bool Is32Bit() const {
return e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS32;
}
//--------------------------------------------------------------------------
/// Returns true if this is a 64 bit ELF file header.
///
/// @return
/// True if this is a 64 bit ELF file header.
bool Is64Bit() const {
return e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64;
}
//--------------------------------------------------------------------------
/// The byte order of this ELF file header.
///
/// @return
/// The byte order of this ELF file as described by the header.
lldb::ByteOrder GetByteOrder() const;
//--------------------------------------------------------------------------
/// The jump slot relocation type of this ELF.
unsigned GetRelocationJumpSlotType() const;
//--------------------------------------------------------------------------
/// Check if there should be header extension in section header #0
///
/// @return
/// True if parsing the ELFHeader requires reading header extension
/// and false otherwise.
bool HasHeaderExtension() const;
//--------------------------------------------------------------------------
/// Parse an ELFHeader entry starting at position \p offset and
/// update the data extractor with the address size and byte order
/// attributes as defined by the header.
///
/// @param[in,out] data
/// The DataExtractor to read from. Updated with the address size and
/// byte order attributes appropriate to this header.
///
/// @param[in,out] offset
/// Pointer to an offset in the data. On return the offset will be
/// advanced by the number of bytes read.
///
/// @return
/// True if the ELFHeader was successfully read and false
/// otherwise.
bool Parse(lldb_private::DataExtractor &data, lldb::offset_t *offset);
//--------------------------------------------------------------------------
/// Examines at most EI_NIDENT bytes starting from the given pointer and
/// determines if the magic ELF identification exists.
///
/// @return
/// True if the given sequence of bytes identifies an ELF file.
static bool MagicBytesMatch(const uint8_t *magic);
//--------------------------------------------------------------------------
/// Examines at most EI_NIDENT bytes starting from the given address and
/// determines the address size of the underlying ELF file. This function
/// should only be called on an pointer for which MagicBytesMatch returns
/// true.
///
/// @return
/// The number of bytes forming an address in the ELF file (either 4 or
/// 8), else zero if the address size could not be determined.
static unsigned AddressSizeInBytes(const uint8_t *magic);
private:
//--------------------------------------------------------------------------
/// Parse an ELFHeader header extension entry. This method is called
/// by Parse().
///
/// @param[in] data
/// The DataExtractor to read from.
void ParseHeaderExtension(lldb_private::DataExtractor &data);
};
//------------------------------------------------------------------------------
/// @class ELFSectionHeader
/// @brief Generic representation of an ELF section header.
struct ELFSectionHeader {
elf_word sh_name; ///< Section name string index.
elf_word sh_type; ///< Section type.
elf_xword sh_flags; ///< Section attributes.
elf_addr sh_addr; ///< Virtual address of the section in memory.
elf_off sh_offset; ///< Start of section from beginning of file.
elf_xword sh_size; ///< Number of bytes occupied in the file.
elf_word sh_link; ///< Index of associated section.
elf_word sh_info; ///< Extra section info (overloaded).
elf_xword sh_addralign; ///< Power of two alignment constraint.
elf_xword sh_entsize; ///< Byte size of each section entry.
ELFSectionHeader();
//--------------------------------------------------------------------------
/// Parse an ELFSectionHeader entry from the given DataExtracter starting at
/// position \p offset.
///
/// @param[in] data
/// The DataExtractor to read from. The address size of the extractor
/// determines if a 32 or 64 bit object should be read.
///
/// @param[in,out] offset
/// Pointer to an offset in the data. On return the offset will be
/// advanced by the number of bytes read.
///
/// @return
/// True if the ELFSectionHeader was successfully read and false
/// otherwise.
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
};
//------------------------------------------------------------------------------
/// @class ELFProgramHeader
/// @brief Generic representation of an ELF program header.
struct ELFProgramHeader {
elf_word p_type; ///< Type of program segment.
elf_word p_flags; ///< Segment attributes.
elf_off p_offset; ///< Start of segment from beginning of file.
elf_addr p_vaddr; ///< Virtual address of segment in memory.
elf_addr p_paddr; ///< Physical address (for non-VM systems).
elf_xword p_filesz; ///< Byte size of the segment in file.
elf_xword p_memsz; ///< Byte size of the segment in memory.
elf_xword p_align; ///< Segment alignment constraint.
ELFProgramHeader();
/// Parse an ELFProgramHeader entry from the given DataExtractor starting at
/// position \p offset. The address size of the DataExtractor determines if
/// a 32 or 64 bit object is to be parsed.
///
/// @param[in] data
/// The DataExtractor to read from. The address size of the extractor
/// determines if a 32 or 64 bit object should be read.
///
/// @param[in,out] offset
/// Pointer to an offset in the data. On return the offset will be
/// advanced by the number of bytes read.
///
/// @return
/// True if the ELFProgramHeader was successfully read and false
/// otherwise.
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
};
//------------------------------------------------------------------------------
/// @class ELFSymbol
/// @brief Represents a symbol within an ELF symbol table.
struct ELFSymbol {
elf_addr st_value; ///< Absolute or relocatable address.
elf_xword st_size; ///< Size of the symbol or zero.
elf_word st_name; ///< Symbol name string index.
unsigned char st_info; ///< Symbol type and binding attributes.
unsigned char st_other; ///< Reserved for future use.
elf_half st_shndx; ///< Section to which this symbol applies.
ELFSymbol();
/// Returns the binding attribute of the st_info member.
unsigned char getBinding() const { return st_info >> 4; }
/// Returns the type attribute of the st_info member.
unsigned char getType() const { return st_info & 0x0F; }
/// Sets the binding and type of the st_info member.
void setBindingAndType(unsigned char binding, unsigned char type) {
st_info = (binding << 4) + (type & 0x0F);
}
static const char *bindingToCString(unsigned char binding);
static const char *typeToCString(unsigned char type);
static const char *
sectionIndexToCString(elf_half shndx,
const lldb_private::SectionList *section_list);
/// Parse an ELFSymbol entry from the given DataExtractor starting at
/// position \p offset. The address size of the DataExtractor determines if
/// a 32 or 64 bit object is to be parsed.
///
/// @param[in] data
/// The DataExtractor to read from. The address size of the extractor
/// determines if a 32 or 64 bit object should be read.
///
/// @param[in,out] offset
/// Pointer to an offset in the data. On return the offset will be
/// advanced by the number of bytes read.
///
/// @return
/// True if the ELFSymbol was successfully read and false otherwise.
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
void Dump(lldb_private::Stream *s, uint32_t idx,
const lldb_private::DataExtractor *strtab_data,
const lldb_private::SectionList *section_list);
};
//------------------------------------------------------------------------------
/// @class ELFDynamic
/// @brief Represents an entry in an ELF dynamic table.
struct ELFDynamic {
elf_sxword d_tag; ///< Type of dynamic table entry.
union {
elf_xword d_val; ///< Integer value of the table entry.
elf_addr d_ptr; ///< Pointer value of the table entry.
};
ELFDynamic();
/// Parse an ELFDynamic entry from the given DataExtractor starting at
/// position \p offset. The address size of the DataExtractor determines if
/// a 32 or 64 bit object is to be parsed.
///
/// @param[in] data
/// The DataExtractor to read from. The address size of the extractor
/// determines if a 32 or 64 bit object should be read.
///
/// @param[in,out] offset
/// Pointer to an offset in the data. On return the offset will be
/// advanced by the number of bytes read.
///
/// @return
/// True if the ELFDynamic entry was successfully read and false
/// otherwise.
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
};
//------------------------------------------------------------------------------
/// @class ELFRel
/// @brief Represents a relocation entry with an implicit addend.
struct ELFRel {
elf_addr r_offset; ///< Address of reference.
elf_xword r_info; ///< symbol index and type of relocation.
ELFRel();
/// Parse an ELFRel entry from the given DataExtractor starting at position
/// \p offset. The address size of the DataExtractor determines if a 32 or
/// 64 bit object is to be parsed.
///
/// @param[in] data
/// The DataExtractor to read from. The address size of the extractor
/// determines if a 32 or 64 bit object should be read.
///
/// @param[in,out] offset
/// Pointer to an offset in the data. On return the offset will be
/// advanced by the number of bytes read.
///
/// @return
/// True if the ELFRel entry was successfully read and false otherwise.
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
/// Returns the type when the given entry represents a 32-bit relocation.
static unsigned RelocType32(const ELFRel &rel) { return rel.r_info & 0x0ff; }
/// Returns the type when the given entry represents a 64-bit relocation.
static unsigned RelocType64(const ELFRel &rel) {
return rel.r_info & 0xffffffff;
}
/// Returns the symbol index when the given entry represents a 32-bit
/// relocation.
static unsigned RelocSymbol32(const ELFRel &rel) { return rel.r_info >> 8; }
/// Returns the symbol index when the given entry represents a 64-bit
/// relocation.
static unsigned RelocSymbol64(const ELFRel &rel) { return rel.r_info >> 32; }
};
//------------------------------------------------------------------------------
/// @class ELFRela
/// @brief Represents a relocation entry with an explicit addend.
struct ELFRela {
elf_addr r_offset; ///< Address of reference.
elf_xword r_info; ///< Symbol index and type of relocation.
elf_sxword r_addend; ///< Constant part of expression.
ELFRela();
/// Parse an ELFRela entry from the given DataExtractor starting at position
/// \p offset. The address size of the DataExtractor determines if a 32 or
/// 64 bit object is to be parsed.
///
/// @param[in] data
/// The DataExtractor to read from. The address size of the extractor
/// determines if a 32 or 64 bit object should be read.
///
/// @param[in,out] offset
/// Pointer to an offset in the data. On return the offset will be
/// advanced by the number of bytes read.
///
/// @return
/// True if the ELFRela entry was successfully read and false otherwise.
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
/// Returns the type when the given entry represents a 32-bit relocation.
static unsigned RelocType32(const ELFRela &rela) {
return rela.r_info & 0x0ff;
}
/// Returns the type when the given entry represents a 64-bit relocation.
static unsigned RelocType64(const ELFRela &rela) {
return rela.r_info & 0xffffffff;
}
/// Returns the symbol index when the given entry represents a 32-bit
/// relocation.
static unsigned RelocSymbol32(const ELFRela &rela) {
return rela.r_info >> 8;
}
/// Returns the symbol index when the given entry represents a 64-bit
/// relocation.
static unsigned RelocSymbol64(const ELFRela &rela) {
return rela.r_info >> 32;
}
};
} // End namespace elf.
#endif // #ifndef liblldb_ELFHeader_h_

View File

@@ -0,0 +1 @@
36027dde04325fe3274373fcef9cff7ad4a1f50d

View File

@@ -0,0 +1,388 @@
//===-- ObjectFileELF.h --------------------------------------- -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_ObjectFileELF_h_
#define liblldb_ObjectFileELF_h_
// C Includes
#include <stdint.h>
// C++ Includes
#include <vector>
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/UUID.h"
#include "lldb/lldb-private.h"
#include "ELFHeader.h"
struct ELFNote {
elf::elf_word n_namesz;
elf::elf_word n_descsz;
elf::elf_word n_type;
std::string n_name;
ELFNote() : n_namesz(0), n_descsz(0), n_type(0) {}
/// Parse an ELFNote entry from the given DataExtractor starting at position
/// \p offset.
///
/// @param[in] data
/// The DataExtractor to read from.
///
/// @param[in,out] offset
/// Pointer to an offset in the data. On return the offset will be
/// advanced by the number of bytes read.
///
/// @return
/// True if the ELFRel entry was successfully read and false otherwise.
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset);
size_t GetByteSize() const {
return 12 + llvm::alignTo(n_namesz, 4) + llvm::alignTo(n_descsz, 4);
}
};
//------------------------------------------------------------------------------
/// @class ObjectFileELF
/// @brief Generic ELF object file reader.
///
/// This class provides a generic ELF (32/64 bit) reader plugin implementing the
/// ObjectFile protocol.
class ObjectFileELF : public lldb_private::ObjectFile {
public:
~ObjectFileELF() override;
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
static void Initialize();
static void Terminate();
static lldb_private::ConstString GetPluginNameStatic();
static const char *GetPluginDescriptionStatic();
static lldb_private::ObjectFile *
CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, const lldb_private::FileSpec *file,
lldb::offset_t file_offset, lldb::offset_t length);
static lldb_private::ObjectFile *CreateMemoryInstance(
const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
lldb::offset_t file_offset,
lldb::offset_t length,
lldb_private::ModuleSpecList &specs);
static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset,
lldb::addr_t length);
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
lldb_private::ConstString GetPluginName() override;
uint32_t GetPluginVersion() override;
//------------------------------------------------------------------
// ObjectFile Protocol.
//------------------------------------------------------------------
bool ParseHeader() override;
bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value,
bool value_is_offset) override;
lldb::ByteOrder GetByteOrder() const override;
bool IsExecutable() const override;
uint32_t GetAddressByteSize() const override;
lldb::AddressClass GetAddressClass(lldb::addr_t file_addr) override;
lldb_private::Symtab *GetSymtab() override;
bool IsStripped() override;
void CreateSections(lldb_private::SectionList &unified_section_list) override;
void Dump(lldb_private::Stream *s) override;
bool GetArchitecture(lldb_private::ArchSpec &arch) override;
bool GetUUID(lldb_private::UUID *uuid) override;
lldb_private::FileSpecList GetDebugSymbolFilePaths() override;
uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
lldb_private::Address
GetImageInfoAddress(lldb_private::Target *target) override;
lldb_private::Address GetEntryPointAddress() override;
ObjectFile::Type CalculateType() override;
ObjectFile::Strata CalculateStrata() override;
size_t ReadSectionData(lldb_private::Section *section,
lldb::offset_t section_offset, void *dst,
size_t dst_len) override;
size_t ReadSectionData(lldb_private::Section *section,
lldb_private::DataExtractor &section_data) override;
// Returns number of program headers found in the ELF file.
size_t GetProgramHeaderCount();
// Returns the program header with the given index.
const elf::ELFProgramHeader *GetProgramHeaderByIndex(lldb::user_id_t id);
// Returns segment data for the given index.
lldb_private::DataExtractor GetSegmentDataByIndex(lldb::user_id_t id);
llvm::StringRef
StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const override;
void RelocateSection(lldb_private::Section *section) override;
private:
ObjectFileELF(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, const lldb_private::FileSpec *file,
lldb::offset_t offset, lldb::offset_t length);
ObjectFileELF(const lldb::ModuleSP &module_sp,
lldb::DataBufferSP &header_data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
typedef std::vector<elf::ELFProgramHeader> ProgramHeaderColl;
typedef ProgramHeaderColl::iterator ProgramHeaderCollIter;
typedef ProgramHeaderColl::const_iterator ProgramHeaderCollConstIter;
struct ELFSectionHeaderInfo : public elf::ELFSectionHeader {
lldb_private::ConstString section_name;
};
typedef std::vector<ELFSectionHeaderInfo> SectionHeaderColl;
typedef SectionHeaderColl::iterator SectionHeaderCollIter;
typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter;
typedef std::vector<elf::ELFDynamic> DynamicSymbolColl;
typedef DynamicSymbolColl::iterator DynamicSymbolCollIter;
typedef DynamicSymbolColl::const_iterator DynamicSymbolCollConstIter;
typedef std::map<lldb::addr_t, lldb::AddressClass>
FileAddressToAddressClassMap;
/// Version of this reader common to all plugins based on this class.
static const uint32_t m_plugin_version = 1;
static const uint32_t g_core_uuid_magic;
/// ELF file header.
elf::ELFHeader m_header;
/// ELF build ID.
lldb_private::UUID m_uuid;
/// ELF .gnu_debuglink file and crc data if available.
std::string m_gnu_debuglink_file;
uint32_t m_gnu_debuglink_crc;
/// Collection of program headers.
ProgramHeaderColl m_program_headers;
/// Collection of section headers.
SectionHeaderColl m_section_headers;
/// Collection of symbols from the dynamic table.
DynamicSymbolColl m_dynamic_symbols;
/// List of file specifications corresponding to the modules (shared
/// libraries) on which this object file depends.
mutable std::unique_ptr<lldb_private::FileSpecList> m_filespec_ap;
/// Cached value of the entry point for this module.
lldb_private::Address m_entry_point_address;
/// The architecture detected from parsing elf file contents.
lldb_private::ArchSpec m_arch_spec;
/// The address class for each symbol in the elf file
FileAddressToAddressClassMap m_address_class_map;
/// Returns a 1 based index of the given section header.
size_t SectionIndex(const SectionHeaderCollIter &I);
/// Returns a 1 based index of the given section header.
size_t SectionIndex(const SectionHeaderCollConstIter &I) const;
// Parses the ELF program headers.
static size_t GetProgramHeaderInfo(ProgramHeaderColl &program_headers,
lldb_private::DataExtractor &object_data,
const elf::ELFHeader &header);
// Finds PT_NOTE segments and calculates their crc sum.
static uint32_t
CalculateELFNotesSegmentsCRC32(const ProgramHeaderColl &program_headers,
lldb_private::DataExtractor &data);
/// Parses all section headers present in this object file and populates
/// m_program_headers. This method will compute the header list only once.
/// Returns the number of headers parsed.
size_t ParseProgramHeaders();
/// Parses all section headers present in this object file and populates
/// m_section_headers. This method will compute the header list only once.
/// Returns the number of headers parsed.
size_t ParseSectionHeaders();
static void ParseARMAttributes(lldb_private::DataExtractor &data,
uint64_t length,
lldb_private::ArchSpec &arch_spec);
/// Parses the elf section headers and returns the uuid, debug link name, crc,
/// archspec.
static size_t GetSectionHeaderInfo(SectionHeaderColl &section_headers,
lldb_private::DataExtractor &object_data,
const elf::ELFHeader &header,
lldb_private::UUID &uuid,
std::string &gnu_debuglink_file,
uint32_t &gnu_debuglink_crc,
lldb_private::ArchSpec &arch_spec);
/// Scans the dynamic section and locates all dependent modules (shared
/// libraries) populating m_filespec_ap. This method will compute the
/// dependent module list only once. Returns the number of dependent
/// modules parsed.
size_t ParseDependentModules();
/// Parses the dynamic symbol table and populates m_dynamic_symbols. The
/// vector retains the order as found in the object file. Returns the
/// number of dynamic symbols parsed.
size_t ParseDynamicSymbols();
/// Populates m_symtab_ap will all non-dynamic linker symbols. This method
/// will parse the symbols only once. Returns the number of symbols parsed.
unsigned ParseSymbolTable(lldb_private::Symtab *symbol_table,
lldb::user_id_t start_id,
lldb_private::Section *symtab);
/// Helper routine for ParseSymbolTable().
unsigned ParseSymbols(lldb_private::Symtab *symbol_table,
lldb::user_id_t start_id,
lldb_private::SectionList *section_list,
const size_t num_symbols,
const lldb_private::DataExtractor &symtab_data,
const lldb_private::DataExtractor &strtab_data);
/// Scans the relocation entries and adds a set of artificial symbols to the
/// given symbol table for each PLT slot. Returns the number of symbols
/// added.
unsigned ParseTrampolineSymbols(lldb_private::Symtab *symbol_table,
lldb::user_id_t start_id,
const ELFSectionHeaderInfo *rela_hdr,
lldb::user_id_t section_id);
void ParseUnwindSymbols(lldb_private::Symtab *symbol_table,
lldb_private::DWARFCallFrameInfo *eh_frame);
/// Relocates debug sections
unsigned RelocateDebugSections(const elf::ELFSectionHeader *rel_hdr,
lldb::user_id_t rel_id,
lldb_private::Symtab *thetab);
unsigned ApplyRelocations(lldb_private::Symtab *symtab,
const elf::ELFHeader *hdr,
const elf::ELFSectionHeader *rel_hdr,
const elf::ELFSectionHeader *symtab_hdr,
const elf::ELFSectionHeader *debug_hdr,
lldb_private::DataExtractor &rel_data,
lldb_private::DataExtractor &symtab_data,
lldb_private::DataExtractor &debug_data,
lldb_private::Section *rel_section);
/// Loads the section name string table into m_shstr_data. Returns the
/// number of bytes constituting the table.
size_t GetSectionHeaderStringTable();
/// Utility method for looking up a section given its name. Returns the
/// index of the corresponding section or zero if no section with the given
/// name can be found (note that section indices are always 1 based, and so
/// section index 0 is never valid).
lldb::user_id_t GetSectionIndexByName(const char *name);
// Returns the ID of the first section that has the given type.
lldb::user_id_t GetSectionIndexByType(unsigned type);
/// Returns the section header with the given id or NULL.
const ELFSectionHeaderInfo *GetSectionHeaderByIndex(lldb::user_id_t id);
/// @name ELF header dump routines
//@{
static void DumpELFHeader(lldb_private::Stream *s,
const elf::ELFHeader &header);
static void DumpELFHeader_e_ident_EI_DATA(lldb_private::Stream *s,
unsigned char ei_data);
static void DumpELFHeader_e_type(lldb_private::Stream *s,
elf::elf_half e_type);
//@}
/// @name ELF program header dump routines
//@{
void DumpELFProgramHeaders(lldb_private::Stream *s);
static void DumpELFProgramHeader(lldb_private::Stream *s,
const elf::ELFProgramHeader &ph);
static void DumpELFProgramHeader_p_type(lldb_private::Stream *s,
elf::elf_word p_type);
static void DumpELFProgramHeader_p_flags(lldb_private::Stream *s,
elf::elf_word p_flags);
//@}
/// @name ELF section header dump routines
//@{
void DumpELFSectionHeaders(lldb_private::Stream *s);
static void DumpELFSectionHeader(lldb_private::Stream *s,
const ELFSectionHeaderInfo &sh);
static void DumpELFSectionHeader_sh_type(lldb_private::Stream *s,
elf::elf_word sh_type);
static void DumpELFSectionHeader_sh_flags(lldb_private::Stream *s,
elf::elf_xword sh_flags);
//@}
/// ELF dependent module dump routine.
void DumpDependentModules(lldb_private::Stream *s);
const elf::ELFDynamic *FindDynamicSymbol(unsigned tag);
unsigned PLTRelocationType();
static lldb_private::Status
RefineModuleDetailsFromNote(lldb_private::DataExtractor &data,
lldb_private::ArchSpec &arch_spec,
lldb_private::UUID &uuid);
};
#endif // liblldb_ObjectFileELF_h_

View File

@@ -0,0 +1,11 @@
add_lldb_library(lldbPluginObjectFileJIT PLUGIN
ObjectFileJIT.cpp
LINK_LIBS
lldbCore
lldbHost
lldbSymbol
lldbTarget
LINK_COMPONENTS
Support
)

View File

@@ -0,0 +1,266 @@
//===-- ObjectFileJIT.cpp ---------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
#include "ObjectFileJIT.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/FileSpecList.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/RangeMap.h"
#include "lldb/Core/Section.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Host/Host.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/DataBuffer.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/Timer.h"
#include "lldb/Utility/UUID.h"
#ifndef __APPLE__
#include "Utility/UuidCompatibility.h"
#endif
using namespace lldb;
using namespace lldb_private;
void ObjectFileJIT::Initialize() {
PluginManager::RegisterPlugin(GetPluginNameStatic(),
GetPluginDescriptionStatic(), CreateInstance,
CreateMemoryInstance, GetModuleSpecifications);
}
void ObjectFileJIT::Terminate() {
PluginManager::UnregisterPlugin(CreateInstance);
}
lldb_private::ConstString ObjectFileJIT::GetPluginNameStatic() {
static ConstString g_name("jit");
return g_name;
}
const char *ObjectFileJIT::GetPluginDescriptionStatic() {
return "JIT code object file";
}
ObjectFile *ObjectFileJIT::CreateInstance(const lldb::ModuleSP &module_sp,
DataBufferSP &data_sp,
lldb::offset_t data_offset,
const FileSpec *file,
lldb::offset_t file_offset,
lldb::offset_t length) {
// JIT'ed object file is backed by the ObjectFileJITDelegate, never
// read from a file
return NULL;
}
ObjectFile *ObjectFileJIT::CreateMemoryInstance(const lldb::ModuleSP &module_sp,
DataBufferSP &data_sp,
const ProcessSP &process_sp,
lldb::addr_t header_addr) {
// JIT'ed object file is backed by the ObjectFileJITDelegate, never
// read from memory
return NULL;
}
size_t ObjectFileJIT::GetModuleSpecifications(
const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, lldb::offset_t file_offset,
lldb::offset_t length, lldb_private::ModuleSpecList &specs) {
// JIT'ed object file can't be read from a file on disk
return 0;
}
ObjectFileJIT::ObjectFileJIT(const lldb::ModuleSP &module_sp,
const ObjectFileJITDelegateSP &delegate_sp)
: ObjectFile(module_sp, NULL, 0, 0, DataBufferSP(), 0), m_delegate_wp() {
if (delegate_sp) {
m_delegate_wp = delegate_sp;
m_data.SetByteOrder(delegate_sp->GetByteOrder());
m_data.SetAddressByteSize(delegate_sp->GetAddressByteSize());
}
}
ObjectFileJIT::~ObjectFileJIT() {}
bool ObjectFileJIT::ParseHeader() {
// JIT code is never in a file, nor is it required to have any header
return false;
}
ByteOrder ObjectFileJIT::GetByteOrder() const { return m_data.GetByteOrder(); }
bool ObjectFileJIT::IsExecutable() const { return false; }
uint32_t ObjectFileJIT::GetAddressByteSize() const {
return m_data.GetAddressByteSize();
}
Symtab *ObjectFileJIT::GetSymtab() {
ModuleSP module_sp(GetModule());
if (module_sp) {
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
if (m_symtab_ap.get() == NULL) {
m_symtab_ap.reset(new Symtab(this));
std::lock_guard<std::recursive_mutex> symtab_guard(
m_symtab_ap->GetMutex());
ObjectFileJITDelegateSP delegate_sp(m_delegate_wp.lock());
if (delegate_sp)
delegate_sp->PopulateSymtab(this, *m_symtab_ap);
// TODO: get symbols from delegate
m_symtab_ap->Finalize();
}
}
return m_symtab_ap.get();
}
bool ObjectFileJIT::IsStripped() {
return false; // JIT code that is in a module is never stripped
}
void ObjectFileJIT::CreateSections(SectionList &unified_section_list) {
if (!m_sections_ap.get()) {
m_sections_ap.reset(new SectionList());
ObjectFileJITDelegateSP delegate_sp(m_delegate_wp.lock());
if (delegate_sp) {
delegate_sp->PopulateSectionList(this, *m_sections_ap);
unified_section_list = *m_sections_ap;
}
}
}
void ObjectFileJIT::Dump(Stream *s) {
ModuleSP module_sp(GetModule());
if (module_sp) {
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
s->Printf("%p: ", static_cast<void *>(this));
s->Indent();
s->PutCString("ObjectFileJIT");
ArchSpec arch;
if (GetArchitecture(arch))
*s << ", arch = " << arch.GetArchitectureName();
s->EOL();
SectionList *sections = GetSectionList();
if (sections)
sections->Dump(s, NULL, true, UINT32_MAX);
if (m_symtab_ap.get())
m_symtab_ap->Dump(s, NULL, eSortOrderNone);
}
}
bool ObjectFileJIT::GetUUID(lldb_private::UUID *uuid) {
// TODO: maybe get from delegate, not needed for first pass
return false;
}
uint32_t ObjectFileJIT::GetDependentModules(FileSpecList &files) {
// JIT modules don't have dependencies, but they could
// if external functions are called and we know where they are
files.Clear();
return 0;
}
lldb_private::Address ObjectFileJIT::GetEntryPointAddress() {
return Address();
}
lldb_private::Address ObjectFileJIT::GetHeaderAddress() { return Address(); }
ObjectFile::Type ObjectFileJIT::CalculateType() { return eTypeJIT; }
ObjectFile::Strata ObjectFileJIT::CalculateStrata() { return eStrataJIT; }
bool ObjectFileJIT::GetArchitecture(ArchSpec &arch) {
ObjectFileJITDelegateSP delegate_sp(m_delegate_wp.lock());
if (delegate_sp)
return delegate_sp->GetArchitecture(arch);
return false;
}
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
lldb_private::ConstString ObjectFileJIT::GetPluginName() {
return GetPluginNameStatic();
}
uint32_t ObjectFileJIT::GetPluginVersion() { return 1; }
bool ObjectFileJIT::SetLoadAddress(Target &target, lldb::addr_t value,
bool value_is_offset) {
size_t num_loaded_sections = 0;
SectionList *section_list = GetSectionList();
if (section_list) {
const size_t num_sections = section_list->GetSize();
// "value" is an offset to apply to each top level segment
for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
// Iterate through the object file sections to find all
// of the sections that size on disk (to avoid __PAGEZERO)
// and load them
SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
if (section_sp && section_sp->GetFileSize() > 0 &&
section_sp->IsThreadSpecific() == false) {
if (target.GetSectionLoadList().SetSectionLoadAddress(
section_sp, section_sp->GetFileAddress() + value))
++num_loaded_sections;
}
}
}
return num_loaded_sections > 0;
}
size_t ObjectFileJIT::ReadSectionData(lldb_private::Section *section,
lldb::offset_t section_offset, void *dst,
size_t dst_len) {
lldb::offset_t file_size = section->GetFileSize();
if (section_offset < file_size) {
size_t src_len = file_size - section_offset;
if (src_len > dst_len)
src_len = dst_len;
const uint8_t *src =
((uint8_t *)(uintptr_t)section->GetFileOffset()) + section_offset;
memcpy(dst, src, src_len);
return src_len;
}
return 0;
}
size_t ObjectFileJIT::ReadSectionData(
lldb_private::Section *section,
lldb_private::DataExtractor &section_data) {
if (section->GetFileSize()) {
const void *src = (void *)(uintptr_t)section->GetFileOffset();
DataBufferSP data_sp(
new lldb_private::DataBufferHeap(src, section->GetFileSize()));
if (data_sp) {
section_data.SetData(data_sp, 0, data_sp->GetByteSize());
section_data.SetByteOrder(GetByteOrder());
section_data.SetAddressByteSize(GetAddressByteSize());
return section_data.GetByteSize();
}
}
section_data.Clear();
return 0;
}

View File

@@ -0,0 +1,113 @@
//===-- ObjectFileJIT.h -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_ObjectFileJIT_h_
#define liblldb_ObjectFileJIT_h_
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Address.h"
#include "lldb/Symbol/ObjectFile.h"
//----------------------------------------------------------------------
// This class needs to be hidden as eventually belongs in a plugin that
// will export the ObjectFile protocol
//----------------------------------------------------------------------
class ObjectFileJIT : public lldb_private::ObjectFile {
public:
ObjectFileJIT(const lldb::ModuleSP &module_sp,
const lldb::ObjectFileJITDelegateSP &delegate_sp);
~ObjectFileJIT() override;
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
static void Initialize();
static void Terminate();
static lldb_private::ConstString GetPluginNameStatic();
static const char *GetPluginDescriptionStatic();
static lldb_private::ObjectFile *
CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, const lldb_private::FileSpec *file,
lldb::offset_t file_offset, lldb::offset_t length);
static lldb_private::ObjectFile *CreateMemoryInstance(
const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
lldb::offset_t file_offset,
lldb::offset_t length,
lldb_private::ModuleSpecList &specs);
//------------------------------------------------------------------
// Member Functions
//------------------------------------------------------------------
bool ParseHeader() override;
bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value,
bool value_is_offset) override;
lldb::ByteOrder GetByteOrder() const override;
bool IsExecutable() const override;
uint32_t GetAddressByteSize() const override;
lldb_private::Symtab *GetSymtab() override;
bool IsStripped() override;
void CreateSections(lldb_private::SectionList &unified_section_list) override;
void Dump(lldb_private::Stream *s) override;
bool GetArchitecture(lldb_private::ArchSpec &arch) override;
bool GetUUID(lldb_private::UUID *uuid) override;
uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
size_t ReadSectionData(lldb_private::Section *section,
lldb::offset_t section_offset, void *dst,
size_t dst_len) override;
size_t
ReadSectionData(lldb_private::Section *section,
lldb_private::DataExtractor &section_data) override;
lldb_private::Address GetEntryPointAddress() override;
lldb_private::Address GetHeaderAddress() override;
ObjectFile::Type CalculateType() override;
ObjectFile::Strata CalculateStrata() override;
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
lldb_private::ConstString GetPluginName() override;
uint32_t GetPluginVersion() override;
protected:
lldb::ObjectFileJITDelegateWP m_delegate_wp;
};
#endif // liblldb_ObjectFileJIT_h_

View File

@@ -0,0 +1,13 @@
add_lldb_library(lldbPluginObjectFileMachO PLUGIN
ObjectFileMachO.cpp
LINK_LIBS
lldbCore
lldbHost
lldbSymbol
lldbTarget
lldbUtility
lldbPluginProcessUtility
LINK_COMPONENTS
Support
)

View File

@@ -0,0 +1 @@
e6941c9f6ed6b692ac9ee7827053e47e30c60313

View File

@@ -0,0 +1,210 @@
//===-- ObjectFileMachO.h ---------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_ObjectFileMachO_h_
#define liblldb_ObjectFileMachO_h_
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Address.h"
#include "lldb/Core/FileSpecList.h"
#include "lldb/Core/RangeMap.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/SafeMachO.h"
#include "lldb/Utility/UUID.h"
//----------------------------------------------------------------------
// This class needs to be hidden as eventually belongs in a plugin that
// will export the ObjectFile protocol
//----------------------------------------------------------------------
class ObjectFileMachO : public lldb_private::ObjectFile {
public:
ObjectFileMachO(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
const lldb_private::FileSpec *file, lldb::offset_t offset,
lldb::offset_t length);
ObjectFileMachO(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
~ObjectFileMachO() override = default;
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
static void Initialize();
static void Terminate();
static lldb_private::ConstString GetPluginNameStatic();
static const char *GetPluginDescriptionStatic();
static lldb_private::ObjectFile *
CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, const lldb_private::FileSpec *file,
lldb::offset_t file_offset, lldb::offset_t length);
static lldb_private::ObjectFile *CreateMemoryInstance(
const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
lldb::offset_t file_offset,
lldb::offset_t length,
lldb_private::ModuleSpecList &specs);
static bool SaveCore(const lldb::ProcessSP &process_sp,
const lldb_private::FileSpec &outfile,
lldb_private::Status &error);
static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset,
lldb::addr_t length);
//------------------------------------------------------------------
// Member Functions
//------------------------------------------------------------------
bool ParseHeader() override;
bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value,
bool value_is_offset) override;
lldb::ByteOrder GetByteOrder() const override;
bool IsExecutable() const override;
uint32_t GetAddressByteSize() const override;
lldb::AddressClass GetAddressClass(lldb::addr_t file_addr) override;
lldb_private::Symtab *GetSymtab() override;
bool IsStripped() override;
void CreateSections(lldb_private::SectionList &unified_section_list) override;
void Dump(lldb_private::Stream *s) override;
bool GetArchitecture(lldb_private::ArchSpec &arch) override;
bool GetUUID(lldb_private::UUID *uuid) override;
uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
lldb_private::FileSpecList GetReExportedLibraries() override {
return m_reexported_dylibs;
}
lldb_private::Address GetEntryPointAddress() override;
lldb_private::Address GetHeaderAddress() override;
uint32_t GetNumThreadContexts() override;
std::string GetIdentifierString() override;
bool GetCorefileMainBinaryInfo (lldb::addr_t &address, lldb_private::UUID &uuid) override;
lldb::RegisterContextSP
GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) override;
ObjectFile::Type CalculateType() override;
ObjectFile::Strata CalculateStrata() override;
uint32_t GetVersion(uint32_t *versions, uint32_t num_versions) override;
uint32_t GetMinimumOSVersion(uint32_t *versions,
uint32_t num_versions) override;
uint32_t GetSDKVersion(uint32_t *versions, uint32_t num_versions) override;
bool GetIsDynamicLinkEditor() override;
static bool ParseHeader(lldb_private::DataExtractor &data,
lldb::offset_t *data_offset_ptr,
llvm::MachO::mach_header &header);
bool AllowAssemblyEmulationUnwindPlans() override;
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
lldb_private::ConstString GetPluginName() override;
uint32_t GetPluginVersion() override;
protected:
static bool
GetUUID(const llvm::MachO::mach_header &header,
const lldb_private::DataExtractor &data,
lldb::offset_t lc_offset, // Offset to the first load command
lldb_private::UUID &uuid);
static bool GetArchitecture(const llvm::MachO::mach_header &header,
const lldb_private::DataExtractor &data,
lldb::offset_t lc_offset,
lldb_private::ArchSpec &arch);
// Intended for same-host arm device debugging where lldb needs to
// detect libraries in the shared cache and augment the nlist entries
// with an on-disk dyld_shared_cache file. The process will record
// the shared cache UUID so the on-disk cache can be matched or rejected
// correctly.
lldb_private::UUID GetProcessSharedCacheUUID(lldb_private::Process *);
// Intended for same-host arm device debugging where lldb will read
// shared cache libraries out of its own memory instead of the remote
// process' memory as an optimization. If lldb's shared cache UUID
// does not match the process' shared cache UUID, this optimization
// should not be used.
lldb_private::UUID GetLLDBSharedCacheUUID();
lldb_private::Section *GetMachHeaderSection();
lldb::addr_t CalculateSectionLoadAddressForMemoryImage(
lldb::addr_t mach_header_load_address,
const lldb_private::Section *mach_header_section,
const lldb_private::Section *section);
lldb_private::UUID
GetSharedCacheUUID(lldb_private::FileSpec dyld_shared_cache,
const lldb::ByteOrder byte_order,
const uint32_t addr_byte_size);
size_t ParseSymtab();
llvm::MachO::mach_header m_header;
static const lldb_private::ConstString &GetSegmentNameTEXT();
static const lldb_private::ConstString &GetSegmentNameDATA();
static const lldb_private::ConstString &GetSegmentNameDATA_DIRTY();
static const lldb_private::ConstString &GetSegmentNameDATA_CONST();
static const lldb_private::ConstString &GetSegmentNameOBJC();
static const lldb_private::ConstString &GetSegmentNameLINKEDIT();
static const lldb_private::ConstString &GetSectionNameEHFrame();
llvm::MachO::dysymtab_command m_dysymtab;
std::vector<llvm::MachO::segment_command_64> m_mach_segments;
std::vector<llvm::MachO::section_64> m_mach_sections;
std::vector<uint32_t> m_min_os_versions;
std::vector<uint32_t> m_sdk_versions;
typedef lldb_private::RangeVector<uint32_t, uint32_t> FileRangeArray;
lldb_private::Address m_entry_point_address;
FileRangeArray m_thread_context_offsets;
bool m_thread_context_offsets_valid;
lldb_private::FileSpecList m_reexported_dylibs;
bool m_allow_assembly_emulation_unwind_plans;
};
#endif // liblldb_ObjectFileMachO_h_

View File

@@ -0,0 +1,13 @@
add_lldb_library(lldbPluginObjectFilePECOFF PLUGIN
ObjectFilePECOFF.cpp
WindowsMiniDump.cpp
LINK_LIBS
lldbCore
lldbHost
lldbSymbol
lldbTarget
LINK_COMPONENTS
BinaryFormat
Support
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,287 @@
//===-- ObjectFilePECOFF.h --------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_ObjectFilePECOFF_h_
#define liblldb_ObjectFilePECOFF_h_
// C Includes
// C++ Includes
#include <vector>
// Other libraries and framework includes
// Project includes
#include "lldb/Symbol/ObjectFile.h"
class ObjectFilePECOFF : public lldb_private::ObjectFile {
public:
typedef enum MachineType {
MachineUnknown = 0x0,
MachineAm33 = 0x1d3,
MachineAmd64 = 0x8664,
MachineArm = 0x1c0,
MachineArmNt = 0x1c4,
MachineArm64 = 0xaa64,
MachineEbc = 0xebc,
MachineX86 = 0x14c,
MachineIA64 = 0x200,
MachineM32R = 0x9041,
MachineMips16 = 0x266,
MachineMipsFpu = 0x366,
MachineMipsFpu16 = 0x466,
MachinePowerPc = 0x1f0,
MachinePowerPcfp = 0x1f1,
MachineR4000 = 0x166,
MachineSh3 = 0x1a2,
MachineSh3dsp = 0x1a3,
MachineSh4 = 0x1a6,
MachineSh5 = 0x1a8,
MachineThumb = 0x1c2,
MachineWcemIpsv2 = 0x169
} MachineType;
ObjectFilePECOFF(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
const lldb_private::FileSpec *file,
lldb::offset_t file_offset, lldb::offset_t length);
ObjectFilePECOFF(const lldb::ModuleSP &module_sp,
lldb::DataBufferSP &header_data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
~ObjectFilePECOFF() override;
//------------------------------------------------------------------
// Static Functions
//------------------------------------------------------------------
static void Initialize();
static void Terminate();
static lldb_private::ConstString GetPluginNameStatic();
static const char *GetPluginDescriptionStatic();
static ObjectFile *
CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, const lldb_private::FileSpec *file,
lldb::offset_t offset, lldb::offset_t length);
static lldb_private::ObjectFile *CreateMemoryInstance(
const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset,
lldb::offset_t file_offset,
lldb::offset_t length,
lldb_private::ModuleSpecList &specs);
static bool SaveCore(const lldb::ProcessSP &process_sp,
const lldb_private::FileSpec &outfile,
lldb_private::Status &error);
static bool MagicBytesMatch(lldb::DataBufferSP &data_sp);
static lldb::SymbolType MapSymbolType(uint16_t coff_symbol_type);
bool ParseHeader() override;
bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value,
bool value_is_offset) override;
lldb::ByteOrder GetByteOrder() const override;
bool IsExecutable() const override;
uint32_t GetAddressByteSize() const override;
// virtual lldb_private::AddressClass
// GetAddressClass (lldb::addr_t file_addr);
lldb_private::Symtab *GetSymtab() override;
bool IsStripped() override;
void CreateSections(lldb_private::SectionList &unified_section_list) override;
void Dump(lldb_private::Stream *s) override;
bool GetArchitecture(lldb_private::ArchSpec &arch) override;
bool GetUUID(lldb_private::UUID *uuid) override;
uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
virtual lldb_private::Address GetEntryPointAddress() override;
ObjectFile::Type CalculateType() override;
ObjectFile::Strata CalculateStrata() override;
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
lldb_private::ConstString GetPluginName() override;
uint32_t GetPluginVersion() override;
bool IsWindowsSubsystem();
lldb_private::DataExtractor ReadImageData(uint32_t offset, size_t size);
protected:
bool NeedsEndianSwap() const;
typedef struct dos_header { // DOS .EXE header
uint16_t e_magic; // Magic number
uint16_t e_cblp; // Bytes on last page of file
uint16_t e_cp; // Pages in file
uint16_t e_crlc; // Relocations
uint16_t e_cparhdr; // Size of header in paragraphs
uint16_t e_minalloc; // Minimum extra paragraphs needed
uint16_t e_maxalloc; // Maximum extra paragraphs needed
uint16_t e_ss; // Initial (relative) SS value
uint16_t e_sp; // Initial SP value
uint16_t e_csum; // Checksum
uint16_t e_ip; // Initial IP value
uint16_t e_cs; // Initial (relative) CS value
uint16_t e_lfarlc; // File address of relocation table
uint16_t e_ovno; // Overlay number
uint16_t e_res[4]; // Reserved words
uint16_t e_oemid; // OEM identifier (for e_oeminfo)
uint16_t e_oeminfo; // OEM information; e_oemid specific
uint16_t e_res2[10]; // Reserved words
uint32_t e_lfanew; // File address of new exe header
} dos_header_t;
typedef struct coff_header {
uint16_t machine;
uint16_t nsects;
uint32_t modtime;
uint32_t symoff;
uint32_t nsyms;
uint16_t hdrsize;
uint16_t flags;
} coff_header_t;
typedef struct data_directory {
uint32_t vmaddr;
uint32_t vmsize;
} data_directory_t;
typedef struct coff_opt_header {
uint16_t magic;
uint8_t major_linker_version;
uint8_t minor_linker_version;
uint32_t code_size;
uint32_t data_size;
uint32_t bss_size;
uint32_t entry;
uint32_t code_offset;
uint32_t data_offset;
uint64_t image_base;
uint32_t sect_alignment;
uint32_t file_alignment;
uint16_t major_os_system_version;
uint16_t minor_os_system_version;
uint16_t major_image_version;
uint16_t minor_image_version;
uint16_t major_subsystem_version;
uint16_t minor_subsystem_version;
uint32_t reserved1;
uint32_t image_size;
uint32_t header_size;
uint32_t checksum;
uint16_t subsystem;
uint16_t dll_flags;
uint64_t stack_reserve_size;
uint64_t stack_commit_size;
uint64_t heap_reserve_size;
uint64_t heap_commit_size;
uint32_t loader_flags;
// uint32_t num_data_dir_entries;
std::vector<data_directory>
data_dirs; // will contain num_data_dir_entries entries
} coff_opt_header_t;
typedef enum coff_data_dir_type {
coff_data_dir_export_table = 0,
coff_data_dir_import_table = 1,
} coff_data_dir_type;
typedef struct section_header {
char name[8];
uint32_t vmsize; // Virtual Size
uint32_t vmaddr; // Virtual Addr
uint32_t size; // File size
uint32_t offset; // File offset
uint32_t reloff; // Offset to relocations
uint32_t lineoff; // Offset to line table entries
uint16_t nreloc; // Number of relocation entries
uint16_t nline; // Number of line table entries
uint32_t flags;
} section_header_t;
typedef struct coff_symbol {
char name[8];
uint32_t value;
uint16_t sect;
uint16_t type;
uint8_t storage;
uint8_t naux;
} coff_symbol_t;
typedef struct export_directory_entry {
uint32_t characteristics;
uint32_t time_date_stamp;
uint16_t major_version;
uint16_t minor_version;
uint32_t name;
uint32_t base;
uint32_t number_of_functions;
uint32_t number_of_names;
uint32_t address_of_functions;
uint32_t address_of_names;
uint32_t address_of_name_ordinals;
} export_directory_entry;
static bool ParseDOSHeader(lldb_private::DataExtractor &data,
dos_header_t &dos_header);
static bool ParseCOFFHeader(lldb_private::DataExtractor &data,
lldb::offset_t *offset_ptr,
coff_header_t &coff_header);
bool ParseCOFFOptionalHeader(lldb::offset_t *offset_ptr);
bool ParseSectionHeaders(uint32_t offset);
static void DumpDOSHeader(lldb_private::Stream *s,
const dos_header_t &header);
static void DumpCOFFHeader(lldb_private::Stream *s,
const coff_header_t &header);
static void DumpOptCOFFHeader(lldb_private::Stream *s,
const coff_opt_header_t &header);
void DumpSectionHeaders(lldb_private::Stream *s);
void DumpSectionHeader(lldb_private::Stream *s, const section_header_t &sh);
bool GetSectionName(std::string &sect_name, const section_header_t &sect);
typedef std::vector<section_header_t> SectionHeaderColl;
typedef SectionHeaderColl::iterator SectionHeaderCollIter;
typedef SectionHeaderColl::const_iterator SectionHeaderCollConstIter;
private:
dos_header_t m_dos_header;
coff_header_t m_coff_header;
coff_opt_header_t m_coff_header_opt;
SectionHeaderColl m_sect_headers;
lldb::addr_t m_image_base;
lldb_private::Address m_entry_point_address;
};
#endif // liblldb_ObjectFilePECOFF_h_

View File

@@ -0,0 +1,59 @@
//===-- WindowsMiniDump.cpp -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// This function is separated out from ObjectFilePECOFF.cpp to name avoid name
// collisions with WinAPI preprocessor macros.
#include "WindowsMiniDump.h"
#include "lldb/Utility/FileSpec.h"
#include "llvm/Support/ConvertUTF.h"
#ifdef _WIN32
#include "lldb/Host/windows/windows.h"
#include <dbghelp.h> // for MiniDumpWriteDump
#endif
namespace lldb_private {
bool SaveMiniDump(const lldb::ProcessSP &process_sp,
const lldb_private::FileSpec &outfile,
lldb_private::Status &error) {
if (!process_sp)
return false;
#ifdef _WIN32
HANDLE process_handle = ::OpenProcess(
PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, process_sp->GetID());
const std::string file_name = outfile.GetCString();
std::wstring wide_name;
wide_name.resize(file_name.size() + 1);
char *result_ptr = reinterpret_cast<char *>(&wide_name[0]);
const llvm::UTF8 *error_ptr = nullptr;
if (!llvm::ConvertUTF8toWide(sizeof(wchar_t), file_name, result_ptr,
error_ptr)) {
error.SetErrorString("cannot convert file name");
return false;
}
HANDLE file_handle =
::CreateFileW(wide_name.c_str(), GENERIC_WRITE, FILE_SHARE_READ, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
const auto result =
::MiniDumpWriteDump(process_handle, process_sp->GetID(), file_handle,
MiniDumpWithFullMemoryInfo, NULL, NULL, NULL);
::CloseHandle(file_handle);
::CloseHandle(process_handle);
if (!result) {
error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
return false;
}
return true;
#endif
return false;
}
} // namesapce lldb_private

View File

@@ -0,0 +1,23 @@
//===-- WindowsMiniDump.h ---------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_WindowsMiniDump_h_
#define liblldb_WindowsMiniDump_h_
#include "lldb/Target/Process.h"
namespace lldb_private {
bool SaveMiniDump(const lldb::ProcessSP &process_sp,
const lldb_private::FileSpec &outfile,
lldb_private::Status &error);
} // namespace lldb_private
#endif