aboutsummaryrefslogtreecommitdiff
path: root/source/Plugins/ObjectFile
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-04-16 16:04:10 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-04-16 16:04:10 +0000
commit74a628f776edb588bff8f8f5cc16eac947c9d631 (patch)
treedc32e010ac4902621e5a279bfeb48628f7f0e166 /source/Plugins/ObjectFile
parentafed7be32164a598f8172282c249af7266c48b46 (diff)
downloadsrc-74a628f776edb588bff8f8f5cc16eac947c9d631.tar.gz
src-74a628f776edb588bff8f8f5cc16eac947c9d631.zip
Vendor import of lldb trunk r300422:vendor/lldb/lldb-trunk-r300422
Notes
Notes: svn path=/vendor/lldb/dist/; revision=317027 svn path=/vendor/lldb/lldb-trunk-r300422/; revision=317028; tag=vendor/lldb/lldb-trunk-r300422
Diffstat (limited to 'source/Plugins/ObjectFile')
-rw-r--r--source/Plugins/ObjectFile/ELF/CMakeLists.txt10
-rw-r--r--source/Plugins/ObjectFile/ELF/ELFHeader.cpp47
-rw-r--r--source/Plugins/ObjectFile/ELF/ELFHeader.h32
-rw-r--r--source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp179
-rw-r--r--source/Plugins/ObjectFile/ELF/ObjectFileELF.h4
-rw-r--r--source/Plugins/ObjectFile/JIT/CMakeLists.txt10
-rw-r--r--source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp12
-rw-r--r--source/Plugins/ObjectFile/Mach-O/CMakeLists.txt12
-rw-r--r--source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp268
-rw-r--r--source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h7
-rw-r--r--source/Plugins/ObjectFile/PECOFF/CMakeLists.txt10
-rw-r--r--source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp47
-rw-r--r--source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp2
13 files changed, 502 insertions, 138 deletions
diff --git a/source/Plugins/ObjectFile/ELF/CMakeLists.txt b/source/Plugins/ObjectFile/ELF/CMakeLists.txt
index 69ec80c62bf0..a941b8d55848 100644
--- a/source/Plugins/ObjectFile/ELF/CMakeLists.txt
+++ b/source/Plugins/ObjectFile/ELF/CMakeLists.txt
@@ -1,4 +1,12 @@
-add_lldb_library(lldbPluginObjectFileELF
+add_lldb_library(lldbPluginObjectFileELF PLUGIN
ELFHeader.cpp
ObjectFileELF.cpp
+
+ LINK_LIBS
+ lldbCore
+ lldbHost
+ lldbSymbol
+ lldbTarget
+ LINK_COMPONENTS
+ Support
)
diff --git a/source/Plugins/ObjectFile/ELF/ELFHeader.cpp b/source/Plugins/ObjectFile/ELF/ELFHeader.cpp
index a3e82390d262..39ea49208700 100644
--- a/source/Plugins/ObjectFile/ELF/ELFHeader.cpp
+++ b/source/Plugins/ObjectFile/ELF/ELFHeader.cpp
@@ -9,9 +9,9 @@
#include <cstring>
-#include "lldb/Core/DataExtractor.h"
#include "lldb/Core/Section.h"
-#include "lldb/Core/Stream.h"
+#include "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Stream.h"
#include "ELFHeader.h"
@@ -81,6 +81,39 @@ ByteOrder ELFHeader::GetByteOrder() const {
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.
@@ -112,6 +145,16 @@ bool ELFHeader::Parse(lldb_private::DataExtractor &data,
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;
}
diff --git a/source/Plugins/ObjectFile/ELF/ELFHeader.h b/source/Plugins/ObjectFile/ELF/ELFHeader.h
index 71b200f1c16b..e6738a1ecb2b 100644
--- a/source/Plugins/ObjectFile/ELF/ELFHeader.h
+++ b/source/Plugins/ObjectFile/ELF/ELFHeader.h
@@ -24,6 +24,7 @@
#include "llvm/Support/ELF.h"
#include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-types.h"
namespace lldb_private {
class DataExtractor;
@@ -65,10 +66,17 @@ struct ELFHeader {
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; ///< Number of program header entries.
+ 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; ///< Number of section header entries.
- elf_half e_shstrndx; ///< String table section index.
+ 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();
@@ -102,6 +110,14 @@ struct ELFHeader {
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.
@@ -137,6 +153,16 @@ struct ELFHeader {
/// 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);
};
//------------------------------------------------------------------------------
diff --git a/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index eb983154618b..6e2001b21630 100644
--- a/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -14,25 +14,26 @@
#include <unordered_map>
#include "lldb/Core/ArchSpec.h"
-#include "lldb/Core/DataBuffer.h"
-#include "lldb/Core/Error.h"
#include "lldb/Core/FileSpecList.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/Section.h"
-#include "lldb/Core/Stream.h"
#include "lldb/Core/Timer.h"
#include "lldb/Symbol/DWARFCallFrameInfo.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
+#include "lldb/Utility/DataBufferLLVM.h"
+#include "lldb/Utility/Error.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Stream.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ARMBuildAttributes.h"
#include "llvm/Support/MathExtras.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/MipsABIFlags.h"
#define CASE_AND_STREAM(s, def, width) \
@@ -51,6 +52,7 @@ namespace {
const char *const LLDB_NT_OWNER_FREEBSD = "FreeBSD";
const char *const LLDB_NT_OWNER_GNU = "GNU";
const char *const LLDB_NT_OWNER_NETBSD = "NetBSD";
+const char *const LLDB_NT_OWNER_OPENBSD = "OpenBSD";
const char *const LLDB_NT_OWNER_CSR = "csr";
const char *const LLDB_NT_OWNER_ANDROID = "Android";
const char *const LLDB_NT_OWNER_CORE = "CORE";
@@ -286,10 +288,26 @@ static uint32_t kalimbaVariantFromElfFlags(const elf::elf_word e_flags) {
return kal_arch_variant;
}
-static uint32_t mipsVariantFromElfFlags(const elf::elf_word e_flags,
- uint32_t endian) {
- const uint32_t mips_arch = e_flags & llvm::ELF::EF_MIPS_ARCH;
+static uint32_t mipsVariantFromElfFlags (const elf::ELFHeader &header) {
+ const uint32_t mips_arch = header.e_flags & llvm::ELF::EF_MIPS_ARCH;
+ uint32_t endian = header.e_ident[EI_DATA];
uint32_t arch_variant = ArchSpec::eMIPSSubType_unknown;
+ uint32_t fileclass = header.e_ident[EI_CLASS];
+
+ // If there aren't any elf flags available (e.g core elf file) then return default
+ // 32 or 64 bit arch (without any architecture revision) based on object file's class.
+ if (header.e_type == ET_CORE) {
+ switch (fileclass) {
+ case llvm::ELF::ELFCLASS32:
+ return (endian == ELFDATA2LSB) ? ArchSpec::eMIPSSubType_mips32el
+ : ArchSpec::eMIPSSubType_mips32;
+ case llvm::ELF::ELFCLASS64:
+ return (endian == ELFDATA2LSB) ? ArchSpec::eMIPSSubType_mips64el
+ : ArchSpec::eMIPSSubType_mips64;
+ default:
+ return arch_variant;
+ }
+ }
switch (mips_arch) {
case llvm::ELF::EF_MIPS_ARCH_1:
@@ -324,7 +342,7 @@ static uint32_t mipsVariantFromElfFlags(const elf::elf_word e_flags,
static uint32_t subTypeFromElfHeader(const elf::ELFHeader &header) {
if (header.e_machine == llvm::ELF::EM_MIPS)
- return mipsVariantFromElfFlags(header.e_flags, header.e_ident[EI_DATA]);
+ return mipsVariantFromElfFlags(header);
return llvm::ELF::EM_CSR_KALIMBA == header.e_machine
? kalimbaVariantFromElfFlags(header.e_flags)
@@ -386,31 +404,42 @@ ObjectFile *ObjectFileELF::CreateInstance(const lldb::ModuleSP &module_sp,
lldb::offset_t file_offset,
lldb::offset_t length) {
if (!data_sp) {
- data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
+ data_sp =
+ DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset);
+ if (!data_sp)
+ return nullptr;
data_offset = 0;
}
- if (data_sp &&
- data_sp->GetByteSize() > (llvm::ELF::EI_NIDENT + data_offset)) {
- const uint8_t *magic = data_sp->GetBytes() + data_offset;
- if (ELFHeader::MagicBytesMatch(magic)) {
- // Update the data to contain the entire file if it doesn't already
- if (data_sp->GetByteSize() < length) {
- data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
- data_offset = 0;
- magic = data_sp->GetBytes();
- }
- unsigned address_size = ELFHeader::AddressSizeInBytes(magic);
- if (address_size == 4 || address_size == 8) {
- std::unique_ptr<ObjectFileELF> objfile_ap(new ObjectFileELF(
- module_sp, data_sp, data_offset, file, file_offset, length));
- ArchSpec spec;
- if (objfile_ap->GetArchitecture(spec) &&
- objfile_ap->SetModulesArchitecture(spec))
- return objfile_ap.release();
- }
- }
+ assert(data_sp);
+
+ if (data_sp->GetByteSize() <= (llvm::ELF::EI_NIDENT + data_offset))
+ return nullptr;
+
+ const uint8_t *magic = data_sp->GetBytes() + data_offset;
+ if (!ELFHeader::MagicBytesMatch(magic))
+ return nullptr;
+
+ // Update the data to contain the entire file if it doesn't already
+ if (data_sp->GetByteSize() < length) {
+ data_sp =
+ DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset);
+ if (!data_sp)
+ return nullptr;
+ data_offset = 0;
+ magic = data_sp->GetBytes();
}
+
+ unsigned address_size = ELFHeader::AddressSizeInBytes(magic);
+ if (address_size == 4 || address_size == 8) {
+ std::unique_ptr<ObjectFileELF> objfile_ap(new ObjectFileELF(
+ module_sp, data_sp, data_offset, file, file_offset, length));
+ ArchSpec spec;
+ if (objfile_ap->GetArchitecture(spec) &&
+ objfile_ap->SetModulesArchitecture(spec))
+ return objfile_ap.release();
+ }
+
return NULL;
}
@@ -610,7 +639,8 @@ size_t ObjectFileELF::GetModuleSpecifications(
DataExtractor data;
data.SetData(data_sp);
elf::ELFHeader header;
- if (header.Parse(data, &data_offset)) {
+ lldb::offset_t header_offset = data_offset;
+ if (header.Parse(data, &header_offset)) {
if (data_sp) {
ModuleSpec spec(file);
@@ -632,6 +662,7 @@ size_t ObjectFileELF::GetModuleSpecifications(
// SetArchitecture should have set the vendor to unknown
vendor = spec.GetArchitecture().GetTriple().getVendor();
assert(vendor == llvm::Triple::UnknownVendor);
+ UNUSED_IF_ASSERT_DISABLED(vendor);
//
// Validate it is ok to remove GetOsFromOSABI
@@ -644,15 +675,31 @@ size_t ObjectFileELF::GetModuleSpecifications(
__FUNCTION__, file.GetPath().c_str());
}
+ // In case there is header extension in the section #0, the header
+ // we parsed above could have sentinel values for e_phnum, e_shnum,
+ // and e_shstrndx. In this case we need to reparse the header
+ // with a bigger data source to get the actual values.
+ size_t section_header_end = header.e_shoff + header.e_shentsize;
+ if (header.HasHeaderExtension() &&
+ section_header_end > data_sp->GetByteSize()) {
+ data_sp = DataBufferLLVM::CreateSliceFromPath(
+ file.GetPath(), section_header_end, file_offset);
+ if (data_sp) {
+ data.SetData(data_sp);
+ lldb::offset_t header_offset = data_offset;
+ header.Parse(data, &header_offset);
+ }
+ }
+
// Try to get the UUID from the section list. Usually that's at the
- // end, so
- // map the file in if we don't have it already.
- size_t section_header_end =
+ // end, so map the file in if we don't have it already.
+ section_header_end =
header.e_shoff + header.e_shnum * header.e_shentsize;
if (section_header_end > data_sp->GetByteSize()) {
- data_sp = file.MemoryMapFileContentsIfLocal(file_offset,
- section_header_end);
- data.SetData(data_sp);
+ data_sp = DataBufferLLVM::CreateSliceFromPath(
+ file.GetPath(), section_header_end, file_offset);
+ if (data_sp)
+ data.SetData(data_sp);
}
uint32_t gnu_debuglink_crc = 0;
@@ -687,17 +734,17 @@ size_t ObjectFileELF::GetModuleSpecifications(
(file.GetByteSize() - file_offset) / 1024);
// For core files - which usually don't happen to have a
- // gnu_debuglink,
- // and are pretty bulky - calculating whole contents crc32 would
- // be too much of luxury.
- // Thus we will need to fallback to something simpler.
+ // gnu_debuglink, and are pretty bulky - calculating whole
+ // contents crc32 would be too much of luxury. Thus we will need
+ // to fallback to something simpler.
if (header.e_type == llvm::ELF::ET_CORE) {
size_t program_headers_end =
header.e_phoff + header.e_phnum * header.e_phentsize;
if (program_headers_end > data_sp->GetByteSize()) {
- data_sp = file.MemoryMapFileContentsIfLocal(
- file_offset, program_headers_end);
- data.SetData(data_sp);
+ data_sp = DataBufferLLVM::CreateSliceFromPath(
+ file.GetPath(), program_headers_end, file_offset);
+ if (data_sp)
+ data.SetData(data_sp);
}
ProgramHeaderColl program_headers;
GetProgramHeaderInfo(program_headers, set_data, header);
@@ -710,20 +757,23 @@ size_t ObjectFileELF::GetModuleSpecifications(
}
if (segment_data_end > data_sp->GetByteSize()) {
- data_sp = file.MemoryMapFileContentsIfLocal(file_offset,
- segment_data_end);
- data.SetData(data_sp);
+ data_sp = DataBufferLLVM::CreateSliceFromPath(
+ file.GetPath(), segment_data_end, file_offset);
+ if (data_sp)
+ data.SetData(data_sp);
}
core_notes_crc =
CalculateELFNotesSegmentsCRC32(program_headers, data);
} else {
// Need to map entire file into memory to calculate the crc.
- data_sp =
- file.MemoryMapFileContentsIfLocal(file_offset, SIZE_MAX);
- data.SetData(data_sp);
- gnu_debuglink_crc = calc_gnu_debuglink_crc32(
- data.GetDataStart(), data.GetByteSize());
+ data_sp = DataBufferLLVM::CreateSliceFromPath(file.GetPath(), -1,
+ file_offset);
+ if (data_sp) {
+ data.SetData(data_sp);
+ gnu_debuglink_crc = calc_gnu_debuglink_crc32(
+ data.GetDataStart(), data.GetByteSize());
+ }
}
}
if (gnu_debuglink_crc) {
@@ -799,7 +849,7 @@ bool ObjectFileELF::SetLoadAddress(Target &target, lldb::addr_t value,
if (section_list) {
if (!value_is_offset) {
bool found_offset = false;
- for (size_t i = 0, count = GetProgramHeaderCount(); i < count; ++i) {
+ for (size_t i = 1, count = GetProgramHeaderCount(); i <= count; ++i) {
const elf::ELFProgramHeader *header = GetProgramHeaderByIndex(i);
if (header == nullptr)
continue;
@@ -1315,6 +1365,10 @@ ObjectFileELF::RefineModuleDetailsFromNote(lldb_private::DataExtractor &data,
}
break;
}
+ if (arch_spec.IsMIPS() &&
+ arch_spec.GetTriple().getOS() == llvm::Triple::OSType::UnknownOS)
+ // The note.n_name == LLDB_NT_OWNER_GNU is valid for Linux platform
+ arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux);
}
// Process NetBSD ELF notes.
else if ((note.n_name == LLDB_NT_OWNER_NETBSD) &&
@@ -1336,6 +1390,12 @@ ObjectFileELF::RefineModuleDetailsFromNote(lldb_private::DataExtractor &data,
"ObjectFileELF::%s detected NetBSD, min version constant %" PRIu32,
__FUNCTION__, version_info);
}
+ // Process OpenBSD ELF notes.
+ else if (note.n_name == LLDB_NT_OWNER_OPENBSD) {
+ // Set the elf OS version to OpenBSD. Also clear the vendor.
+ arch_spec.GetTriple().setOS(llvm::Triple::OSType::OpenBSD);
+ arch_spec.GetTriple().setVendor(llvm::Triple::VendorType::UnknownVendor);
+ }
// Process CSR kalimba notes
else if ((note.n_type == LLDB_NT_GNU_ABI_TAG) &&
(note.n_name == LLDB_NT_OWNER_CSR)) {
@@ -1410,6 +1470,12 @@ ObjectFileELF::RefineModuleDetailsFromNote(lldb_private::DataExtractor &data,
break;
}
}
+ if (arch_spec.IsMIPS() &&
+ arch_spec.GetTriple().getOS() == llvm::Triple::OSType::UnknownOS)
+ // In case of MIPSR6, the LLDB_NT_OWNER_GNU note is missing
+ // for some cases (e.g. compile with -nostdlib)
+ // Hence set OS to Linux
+ arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux);
}
}
@@ -1524,6 +1590,7 @@ size_t ObjectFileELF::GetSectionHeaderInfo(SectionHeaderColl &section_headers,
GetOsFromOSABI(header.e_ident[EI_OSABI], ostype);
spec_ostype = arch_spec.GetTriple().getOS();
assert(spec_ostype == ostype);
+ UNUSED_IF_ASSERT_DISABLED(spec_ostype);
}
if (arch_spec.GetMachine() == llvm::Triple::mips ||
@@ -3065,10 +3132,10 @@ void ObjectFileELF::DumpELFHeader(Stream *s, const ELFHeader &header) {
s->Printf("e_flags = 0x%8.8x\n", header.e_flags);
s->Printf("e_ehsize = 0x%4.4x\n", header.e_ehsize);
s->Printf("e_phentsize = 0x%4.4x\n", header.e_phentsize);
- s->Printf("e_phnum = 0x%4.4x\n", header.e_phnum);
+ s->Printf("e_phnum = 0x%8.8x\n", header.e_phnum);
s->Printf("e_shentsize = 0x%4.4x\n", header.e_shentsize);
- s->Printf("e_shnum = 0x%4.4x\n", header.e_shnum);
- s->Printf("e_shstrndx = 0x%4.4x\n", header.e_shstrndx);
+ s->Printf("e_shnum = 0x%8.8x\n", header.e_shnum);
+ s->Printf("e_shstrndx = 0x%8.8x\n", header.e_shstrndx);
}
//----------------------------------------------------------------------
@@ -3315,7 +3382,7 @@ bool ObjectFileELF::GetArchitecture(ArchSpec &arch) {
// headers
// that might shed more light on the architecture
if (ParseProgramHeaders()) {
- for (size_t i = 0, count = GetProgramHeaderCount(); i < count; ++i) {
+ for (size_t i = 1, count = GetProgramHeaderCount(); i <= count; ++i) {
const elf::ELFProgramHeader *header = GetProgramHeaderByIndex(i);
if (header && header->p_type == PT_NOTE && header->p_offset != 0 &&
header->p_filesz > 0) {
diff --git a/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index 4ce5648cfed5..98bd9abb1932 100644
--- a/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -20,9 +20,9 @@
// Other libraries and framework includes
// Project includes
#include "lldb/Core/ArchSpec.h"
-#include "lldb/Core/UUID.h"
-#include "lldb/Host/FileSpec.h"
#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/UUID.h"
#include "lldb/lldb-private.h"
#include "ELFHeader.h"
diff --git a/source/Plugins/ObjectFile/JIT/CMakeLists.txt b/source/Plugins/ObjectFile/JIT/CMakeLists.txt
index 979724bac5ad..fd575532db4c 100644
--- a/source/Plugins/ObjectFile/JIT/CMakeLists.txt
+++ b/source/Plugins/ObjectFile/JIT/CMakeLists.txt
@@ -1,3 +1,11 @@
-add_lldb_library(lldbPluginObjectFileJIT
+add_lldb_library(lldbPluginObjectFileJIT PLUGIN
ObjectFileJIT.cpp
+
+ LINK_LIBS
+ lldbCore
+ lldbHost
+ lldbSymbol
+ lldbTarget
+ LINK_COMPONENTS
+ Support
)
diff --git a/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp b/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
index b5b5e38e1f6f..055a8219f154 100644
--- a/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
+++ b/source/Plugins/ObjectFile/JIT/ObjectFileJIT.cpp
@@ -12,27 +12,27 @@
#include "ObjectFileJIT.h"
#include "lldb/Core/ArchSpec.h"
-#include "lldb/Core/DataBuffer.h"
-#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/FileSpecList.h"
-#include "lldb/Core/Log.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/Core/StreamString.h"
#include "lldb/Core/Timer.h"
-#include "lldb/Core/UUID.h"
-#include "lldb/Host/FileSpec.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/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/UUID.h"
#ifndef __APPLE__
#include "Utility/UuidCompatibility.h"
diff --git a/source/Plugins/ObjectFile/Mach-O/CMakeLists.txt b/source/Plugins/ObjectFile/Mach-O/CMakeLists.txt
index 45d45860b9e5..d39b93768ae7 100644
--- a/source/Plugins/ObjectFile/Mach-O/CMakeLists.txt
+++ b/source/Plugins/ObjectFile/Mach-O/CMakeLists.txt
@@ -1,3 +1,13 @@
-add_lldb_library(lldbPluginObjectFileMachO
+add_lldb_library(lldbPluginObjectFileMachO PLUGIN
ObjectFileMachO.cpp
+
+ LINK_LIBS
+ lldbCore
+ lldbHost
+ lldbSymbol
+ lldbTarget
+ lldbUtility
+ lldbPluginProcessUtility
+ LINK_COMPONENTS
+ Support
)
diff --git a/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 9ef4e9c3c9b1..84ecfdc67bee 100644
--- a/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -18,21 +18,16 @@
#include "Plugins/Process/Utility/RegisterContextDarwin_i386.h"
#include "Plugins/Process/Utility/RegisterContextDarwin_x86_64.h"
#include "lldb/Core/ArchSpec.h"
-#include "lldb/Core/DataBuffer.h"
#include "lldb/Core/Debugger.h"
-#include "lldb/Core/Error.h"
#include "lldb/Core/FileSpecList.h"
-#include "lldb/Core/Log.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/RangeMap.h"
+#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Section.h"
#include "lldb/Core/StreamFile.h"
-#include "lldb/Core/StreamString.h"
#include "lldb/Core/Timer.h"
-#include "lldb/Core/UUID.h"
-#include "lldb/Host/FileSpec.h"
#include "lldb/Host/Host.h"
#include "lldb/Symbol/DWARFCallFrameInfo.h"
#include "lldb/Symbol/ObjectFile.h"
@@ -44,9 +39,17 @@
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadList.h"
+#include "lldb/Utility/DataBufferLLVM.h"
+#include "lldb/Utility/Error.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/StreamString.h"
+#include "lldb/Utility/UUID.h"
#include "lldb/Utility/SafeMachO.h"
+#include "llvm/Support/MemoryBuffer.h"
+
#include "ObjectFileMachO.h"
#if defined(__APPLE__) && \
@@ -57,6 +60,8 @@
#ifndef __APPLE__
#include "Utility/UuidCompatibility.h"
+#else
+#include <uuid/uuid.h>
#endif
#define THUMB_ADDRESS_BIT_MASK 0xfffffffffffffffeull
@@ -857,22 +862,30 @@ ObjectFile *ObjectFileMachO::CreateInstance(const lldb::ModuleSP &module_sp,
lldb::offset_t file_offset,
lldb::offset_t length) {
if (!data_sp) {
- data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
+ data_sp =
+ DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset);
+ if (!data_sp)
+ return nullptr;
data_offset = 0;
}
- if (ObjectFileMachO::MagicBytesMatch(data_sp, data_offset, length)) {
- // Update the data to contain the entire file if it doesn't already
- if (data_sp->GetByteSize() < length) {
- data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
- data_offset = 0;
- }
- std::unique_ptr<ObjectFile> objfile_ap(new ObjectFileMachO(
- module_sp, data_sp, data_offset, file, file_offset, length));
- if (objfile_ap.get() && objfile_ap->ParseHeader())
- return objfile_ap.release();
+ if (!ObjectFileMachO::MagicBytesMatch(data_sp, data_offset, length))
+ return nullptr;
+
+ // Update the data to contain the entire file if it doesn't already
+ if (data_sp->GetByteSize() < length) {
+ data_sp =
+ DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset);
+ if (!data_sp)
+ return nullptr;
+ data_offset = 0;
}
- return NULL;
+ auto objfile_ap = llvm::make_unique<ObjectFileMachO>(
+ module_sp, data_sp, data_offset, file, file_offset, length);
+ if (!objfile_ap || !objfile_ap->ParseHeader())
+ return nullptr;
+
+ return objfile_ap.release();
}
ObjectFile *ObjectFileMachO::CreateMemoryInstance(
@@ -901,7 +914,8 @@ size_t ObjectFileMachO::GetModuleSpecifications(
size_t header_and_load_cmds =
header.sizeofcmds + MachHeaderSizeFromMagic(header.magic);
if (header_and_load_cmds >= data_sp->GetByteSize()) {
- data_sp = file.ReadFileContents(file_offset, header_and_load_cmds);
+ data_sp = DataBufferLLVM::CreateSliceFromPath(
+ file.GetPath(), header_and_load_cmds, file_offset);
data.SetData(data_sp);
data_offset = MachHeaderSizeFromMagic(header.magic);
}
@@ -1113,8 +1127,8 @@ bool ObjectFileMachO::ParseHeader() {
ReadMemory(process_sp, m_memory_addr, header_and_lc_size);
} else {
// Read in all only the load command data from the file on disk
- data_sp =
- m_file.ReadFileContents(m_file_offset, header_and_lc_size);
+ data_sp = DataBufferLLVM::CreateSliceFromPath(
+ m_file.GetPath(), header_and_lc_size, m_file_offset);
if (data_sp->GetByteSize() != header_and_lc_size)
return false;
}
@@ -2085,22 +2099,23 @@ UUID ObjectFileMachO::GetSharedCacheUUID(FileSpec dyld_shared_cache,
const ByteOrder byte_order,
const uint32_t addr_byte_size) {
UUID dsc_uuid;
- DataBufferSP dsc_data_sp = dyld_shared_cache.MemoryMapFileContentsIfLocal(
- 0, sizeof(struct lldb_copy_dyld_cache_header_v1));
- if (dsc_data_sp) {
- DataExtractor dsc_header_data(dsc_data_sp, byte_order, addr_byte_size);
-
- char version_str[7];
- lldb::offset_t offset = 0;
- memcpy(version_str, dsc_header_data.GetData(&offset, 6), 6);
- version_str[6] = '\0';
- if (strcmp(version_str, "dyld_v") == 0) {
- offset = offsetof(struct lldb_copy_dyld_cache_header_v1, uuid);
- uint8_t uuid_bytes[sizeof(uuid_t)];
- memcpy(uuid_bytes, dsc_header_data.GetData(&offset, sizeof(uuid_t)),
- sizeof(uuid_t));
- dsc_uuid.SetBytes(uuid_bytes);
- }
+ DataBufferSP DscData = DataBufferLLVM::CreateSliceFromPath(
+ dyld_shared_cache.GetPath(),
+ sizeof(struct lldb_copy_dyld_cache_header_v1), 0);
+ if (!DscData)
+ return dsc_uuid;
+ DataExtractor dsc_header_data(DscData, byte_order, addr_byte_size);
+
+ char version_str[7];
+ lldb::offset_t offset = 0;
+ memcpy(version_str, dsc_header_data.GetData(&offset, 6), 6);
+ version_str[6] = '\0';
+ if (strcmp(version_str, "dyld_v") == 0) {
+ offset = offsetof(struct lldb_copy_dyld_cache_header_v1, uuid);
+ uint8_t uuid_bytes[sizeof(uuid_t)];
+ memcpy(uuid_bytes, dsc_header_data.GetData(&offset, sizeof(uuid_t)),
+ sizeof(uuid_t));
+ dsc_uuid.SetBytes(uuid_bytes);
}
return dsc_uuid;
}
@@ -2692,8 +2707,9 @@ size_t ObjectFileMachO::ParseSymtab() {
// Process the dyld shared cache header to find the unmapped symbols
- DataBufferSP dsc_data_sp = dsc_filespec.MemoryMapFileContentsIfLocal(
- 0, sizeof(struct lldb_copy_dyld_cache_header_v1));
+ DataBufferSP dsc_data_sp = DataBufferLLVM::CreateSliceFromPath(
+ dsc_filespec.GetPath(), sizeof(struct lldb_copy_dyld_cache_header_v1),
+ 0);
if (!dsc_uuid.IsValid()) {
dsc_uuid = GetSharedCacheUUID(dsc_filespec, byte_order, addr_byte_size);
}
@@ -2726,9 +2742,11 @@ size_t ObjectFileMachO::ParseSymtab() {
mappingOffset >= sizeof(struct lldb_copy_dyld_cache_header_v1)) {
DataBufferSP dsc_mapping_info_data_sp =
- dsc_filespec.MemoryMapFileContentsIfLocal(
- mappingOffset,
- sizeof(struct lldb_copy_dyld_cache_mapping_info));
+ DataBufferLLVM::CreateSliceFromPath(
+ dsc_filespec.GetPath(),
+ sizeof(struct lldb_copy_dyld_cache_mapping_info),
+ mappingOffset);
+
DataExtractor dsc_mapping_info_data(dsc_mapping_info_data_sp,
byte_order, addr_byte_size);
offset = 0;
@@ -2750,9 +2768,12 @@ size_t ObjectFileMachO::ParseSymtab() {
if (localSymbolsOffset && localSymbolsSize) {
// Map the local symbols
- if (DataBufferSP dsc_local_symbols_data_sp =
- dsc_filespec.MemoryMapFileContentsIfLocal(
- localSymbolsOffset, localSymbolsSize)) {
+ DataBufferSP dsc_local_symbols_data_sp =
+ DataBufferLLVM::CreateSliceFromPath(dsc_filespec.GetPath(),
+ localSymbolsSize,
+ localSymbolsOffset);
+
+ if (dsc_local_symbols_data_sp) {
DataExtractor dsc_local_symbols_data(dsc_local_symbols_data_sp,
byte_order, addr_byte_size);
@@ -5034,6 +5055,7 @@ uint32_t ObjectFileMachO::GetDependentModules(FileSpecList &files) {
lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
std::vector<std::string> rpath_paths;
std::vector<std::string> rpath_relative_paths;
+ std::vector<std::string> at_exec_relative_paths;
const bool resolve_path = false; // Don't resolve the dependent file paths
// since they may not reside on this system
uint32_t i;
@@ -5059,6 +5081,10 @@ uint32_t ObjectFileMachO::GetDependentModules(FileSpecList &files) {
if (path[0] == '@') {
if (strncmp(path, "@rpath", strlen("@rpath")) == 0)
rpath_relative_paths.push_back(path + strlen("@rpath"));
+ else if (strncmp(path, "@executable_path",
+ strlen("@executable_path")) == 0)
+ at_exec_relative_paths.push_back(path
+ + strlen("@executable_path"));
} else {
FileSpec file_spec(path, resolve_path);
if (files.AppendIfUnique(file_spec))
@@ -5074,10 +5100,11 @@ uint32_t ObjectFileMachO::GetDependentModules(FileSpecList &files) {
offset = cmd_offset + load_cmd.cmdsize;
}
+ FileSpec this_file_spec(m_file);
+ this_file_spec.ResolvePath();
+
if (!rpath_paths.empty()) {
// Fixup all LC_RPATH values to be absolute paths
- FileSpec this_file_spec(m_file);
- this_file_spec.ResolvePath();
std::string loader_path("@loader_path");
std::string executable_path("@executable_path");
for (auto &rpath : rpath_paths) {
@@ -5107,6 +5134,23 @@ uint32_t ObjectFileMachO::GetDependentModules(FileSpecList &files) {
}
}
}
+
+ // We may have @executable_paths but no RPATHS. Figure those out here.
+ // Only do this if this object file is the executable. We have no way to
+ // get back to the actual executable otherwise, so we won't get the right
+ // path.
+ if (!at_exec_relative_paths.empty() && CalculateType() == eTypeExecutable) {
+ FileSpec exec_dir = this_file_spec.CopyByRemovingLastPathComponent();
+ for (const auto &at_exec_relative_path : at_exec_relative_paths) {
+ FileSpec file_spec =
+ exec_dir.CopyByAppendingPathComponent(at_exec_relative_path);
+ file_spec = file_spec.GetNormalizedPath();
+ if (file_spec.Exists() && files.AppendIfUnique(file_spec)) {
+ count++;
+ break;
+ }
+ }
+ }
}
return count;
}
@@ -5312,6 +5356,136 @@ uint32_t ObjectFileMachO::GetNumThreadContexts() {
return m_thread_context_offsets.GetSize();
}
+std::string ObjectFileMachO::GetIdentifierString() {
+ std::string result;
+ ModuleSP module_sp(GetModule());
+ if (module_sp) {
+ std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+
+ // First, look over the load commands for an LC_NOTE load command
+ // with data_owner string "kern ver str" & use that if found.
+ lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+ for (uint32_t i = 0; i < m_header.ncmds; ++i) {
+ const uint32_t cmd_offset = offset;
+ load_command lc;
+ if (m_data.GetU32(&offset, &lc.cmd, 2) == NULL)
+ break;
+ if (lc.cmd == LC_NOTE)
+ {
+ char data_owner[17];
+ m_data.CopyData (offset, 16, data_owner);
+ data_owner[16] = '\0';
+ offset += 16;
+ uint64_t fileoff = m_data.GetU64_unchecked (&offset);
+ uint64_t size = m_data.GetU64_unchecked (&offset);
+
+ // "kern ver str" has a uint32_t version and then a
+ // nul terminated c-string.
+ if (strcmp ("kern ver str", data_owner) == 0)
+ {
+ offset = fileoff;
+ uint32_t version;
+ if (m_data.GetU32 (&offset, &version, 1) != nullptr)
+ {
+ if (version == 1)
+ {
+ uint32_t strsize = size - sizeof (uint32_t);
+ char *buf = (char*) malloc (strsize);
+ if (buf)
+ {
+ m_data.CopyData (offset, strsize, buf);
+ buf[strsize - 1] = '\0';
+ result = buf;
+ if (buf)
+ free (buf);
+ return result;
+ }
+ }
+ }
+ }
+ }
+ offset = cmd_offset + lc.cmdsize;
+ }
+
+ // Second, make a pass over the load commands looking for an
+ // obsolete LC_IDENT load command.
+ offset = MachHeaderSizeFromMagic(m_header.magic);
+ for (uint32_t i = 0; i < m_header.ncmds; ++i) {
+ const uint32_t cmd_offset = offset;
+ struct ident_command ident_command;
+ if (m_data.GetU32(&offset, &ident_command, 2) == NULL)
+ break;
+ if (ident_command.cmd == LC_IDENT && ident_command.cmdsize != 0) {
+ char *buf = (char *) malloc (ident_command.cmdsize);
+ if (buf != nullptr
+ && m_data.CopyData (offset, ident_command.cmdsize, buf) == ident_command.cmdsize) {
+ buf[ident_command.cmdsize - 1] = '\0';
+ result = buf;
+ }
+ if (buf)
+ free (buf);
+ }
+ offset = cmd_offset + ident_command.cmdsize;
+ }
+
+ }
+ return result;
+}
+
+bool ObjectFileMachO::GetCorefileMainBinaryInfo (addr_t &address, UUID &uuid) {
+ address = LLDB_INVALID_ADDRESS;
+ uuid.Clear();
+ ModuleSP module_sp(GetModule());
+ if (module_sp) {
+ std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
+ lldb::offset_t offset = MachHeaderSizeFromMagic(m_header.magic);
+ for (uint32_t i = 0; i < m_header.ncmds; ++i) {
+ const uint32_t cmd_offset = offset;
+ load_command lc;
+ if (m_data.GetU32(&offset, &lc.cmd, 2) == NULL)
+ break;
+ if (lc.cmd == LC_NOTE)
+ {
+ char data_owner[17];
+ memset (data_owner, 0, sizeof (data_owner));
+ m_data.CopyData (offset, 16, data_owner);
+ offset += 16;
+ uint64_t fileoff = m_data.GetU64_unchecked (&offset);
+ uint64_t size = m_data.GetU64_unchecked (&offset);
+
+ // "main bin spec" (main binary specification) data payload is formatted:
+ // uint32_t version [currently 1]
+ // uint32_t type [0 == unspecified, 1 == kernel, 2 == user process]
+ // uint64_t address [ UINT64_MAX if address not specified ]
+ // uuid_t uuid [ all zero's if uuid not specified ]
+ // uint32_t log2_pagesize [ process page size in log base 2, e.g. 4k pages are 12. 0 for unspecified ]
+
+ if (strcmp ("main bin spec", data_owner) == 0 && size >= 32)
+ {
+ offset = fileoff;
+ uint32_t version;
+ if (m_data.GetU32 (&offset, &version, 1) != nullptr && version == 1)
+ {
+ uint32_t type = 0;
+ uuid_t raw_uuid;
+ memset (raw_uuid, 0, sizeof (uuid_t));
+
+ if (m_data.GetU32 (&offset, &type, 1)
+ && m_data.GetU64 (&offset, &address, 1)
+ && m_data.CopyData (offset, sizeof (uuid_t), raw_uuid) != 0
+ && uuid.SetBytes (raw_uuid, sizeof (uuid_t)))
+ {
+ return true;
+ }
+ }
+ }
+ }
+ offset = cmd_offset + lc.cmdsize;
+ }
+ }
+ return false;
+}
+
lldb::RegisterContextSP
ObjectFileMachO::GetThreadContextAtIndex(uint32_t idx,
lldb_private::Thread &thread) {
diff --git a/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h b/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
index cac176fe2ca6..96379a4db411 100644
--- a/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
+++ b/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
@@ -17,9 +17,10 @@
#include "lldb/Core/Address.h"
#include "lldb/Core/FileSpecList.h"
#include "lldb/Core/RangeMap.h"
-#include "lldb/Host/FileSpec.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
@@ -111,6 +112,10 @@ public:
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;
diff --git a/source/Plugins/ObjectFile/PECOFF/CMakeLists.txt b/source/Plugins/ObjectFile/PECOFF/CMakeLists.txt
index 5c7c488f362f..1e8fb85c72c9 100644
--- a/source/Plugins/ObjectFile/PECOFF/CMakeLists.txt
+++ b/source/Plugins/ObjectFile/PECOFF/CMakeLists.txt
@@ -1,4 +1,12 @@
-add_lldb_library(lldbPluginObjectFilePECOFF
+add_lldb_library(lldbPluginObjectFilePECOFF PLUGIN
ObjectFilePECOFF.cpp
WindowsMiniDump.cpp
+
+ LINK_LIBS
+ lldbCore
+ lldbHost
+ lldbSymbol
+ lldbTarget
+ LINK_COMPONENTS
+ Support
)
diff --git a/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
index f0647e02158b..c89383a7b7ba 100644
--- a/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ b/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -13,22 +13,24 @@
#include "llvm/Support/COFF.h"
#include "lldb/Core/ArchSpec.h"
-#include "lldb/Core/DataBuffer.h"
-#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/FileSpecList.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/Section.h"
#include "lldb/Core/StreamFile.h"
-#include "lldb/Core/StreamString.h"
#include "lldb/Core/Timer.h"
-#include "lldb/Core/UUID.h"
-#include "lldb/Host/FileSpec.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
+#include "lldb/Utility/DataBufferHeap.h"
+#include "lldb/Utility/DataBufferLLVM.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/StreamString.h"
+#include "lldb/Utility/UUID.h"
+
+#include "llvm/Support/MemoryBuffer.h"
#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
#define IMAGE_NT_SIGNATURE 0x00004550 // PE00
@@ -65,20 +67,30 @@ ObjectFile *ObjectFilePECOFF::CreateInstance(const lldb::ModuleSP &module_sp,
lldb::offset_t file_offset,
lldb::offset_t length) {
if (!data_sp) {
- data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
+ data_sp =
+ DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset);
+ if (!data_sp)
+ return nullptr;
data_offset = 0;
}
- if (ObjectFilePECOFF::MagicBytesMatch(data_sp)) {
- // Update the data to contain the entire file if it doesn't already
- if (data_sp->GetByteSize() < length)
- data_sp = file->MemoryMapFileContentsIfLocal(file_offset, length);
- std::unique_ptr<ObjectFile> objfile_ap(new ObjectFilePECOFF(
- module_sp, data_sp, data_offset, file, file_offset, length));
- if (objfile_ap.get() && objfile_ap->ParseHeader())
- return objfile_ap.release();
+ if (!ObjectFilePECOFF::MagicBytesMatch(data_sp))
+ return nullptr;
+
+ // Update the data to contain the entire file if it doesn't already
+ if (data_sp->GetByteSize() < length) {
+ data_sp =
+ DataBufferLLVM::CreateSliceFromPath(file->GetPath(), length, file_offset);
+ if (!data_sp)
+ return nullptr;
}
- return NULL;
+
+ auto objfile_ap = llvm::make_unique<ObjectFilePECOFF>(
+ module_sp, data_sp, data_offset, file, file_offset, length);
+ if (!objfile_ap || !objfile_ap->ParseHeader())
+ return nullptr;
+
+ return objfile_ap.release();
}
ObjectFile *ObjectFilePECOFF::CreateMemoryInstance(
@@ -418,7 +430,10 @@ bool ObjectFilePECOFF::ParseCOFFOptionalHeader(lldb::offset_t *offset_ptr) {
DataExtractor ObjectFilePECOFF::ReadImageData(uint32_t offset, size_t size) {
if (m_file) {
- DataBufferSP buffer_sp(m_file.ReadFileContents(offset, size));
+ // A bit of a hack, but we intend to write to this buffer, so we can't
+ // mmap it.
+ auto buffer_sp =
+ DataBufferLLVM::CreateSliceFromPath(m_file.GetPath(), size, offset, true);
return DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize());
}
ProcessSP process_sp(m_process_wp.lock());
diff --git a/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp b/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp
index 3fd6cdc5c9a7..094e258a7a03 100644
--- a/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp
+++ b/source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp
@@ -11,7 +11,7 @@
// collisions with WinAPI preprocessor macros.
#include "WindowsMiniDump.h"
-#include "lldb/Host/FileSpec.h"
+#include "lldb/Utility/FileSpec.h"
#include "llvm/Support/ConvertUTF.h"
#ifdef _WIN32