Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lldb/include/lldb/Expression/ObjectFileJIT.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ class ObjectFileJIT : public ObjectFile {
}

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);
CreateInstance(const lldb::ModuleSP &module_sp,
lldb::DataExtractorSP extractor_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::WritableDataBufferSP data_sp,
Expand Down
10 changes: 5 additions & 5 deletions lldb/include/lldb/Symbol/ObjectContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ class ObjectContainer : public PluginInterface, public ModuleChild {
/// Attempts to parse the object header.
///
/// This function is used as a test to see if a given plug-in instance can
/// parse the header data already contained in ObjectContainer::m_data. If
/// an object file parser does not recognize that magic bytes in a header,
/// false should be returned and the next plug-in can attempt to parse an
/// object file.
/// parse the header data already contained in
/// ObjectContainer::m_extractor_sp. If an object file parser does not
/// recognize that magic bytes in a header, false should be returned and the
/// next plug-in can attempt to parse an object file.
///
/// \return
/// Returns \b true if the header was parsed successfully, \b
Expand Down Expand Up @@ -140,7 +140,7 @@ class ObjectContainer : public PluginInterface, public ModuleChild {
lldb::addr_t m_length;

/// The data for this object file so things can be parsed lazily.
DataExtractor m_data;
lldb::DataExtractorSP m_extractor_sp;

private:
ObjectContainer(const ObjectContainer &) = delete;
Expand Down
6 changes: 3 additions & 3 deletions lldb/include/lldb/Symbol/ObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
/// more than one architecture or object.
ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr,
lldb::offset_t file_offset, lldb::offset_t length,
lldb::DataBufferSP data_sp, lldb::offset_t data_offset);
lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset);

ObjectFile(const lldb::ModuleSP &module_sp, const lldb::ProcessSP &process_sp,
lldb::addr_t header_addr, lldb::DataBufferSP data_sp);
lldb::addr_t header_addr, lldb::DataExtractorSP extractor_sp);

/// Destructor.
///
Expand Down Expand Up @@ -152,7 +152,7 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
static lldb::ObjectFileSP
FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec,
lldb::offset_t file_offset, lldb::offset_t file_size,
lldb::DataBufferSP &data_sp, lldb::offset_t &data_offset);
lldb::DataExtractorSP extractor_sp, lldb::offset_t &data_offset);

/// Find a ObjectFile plug-in that can parse a file in memory.
///
Expand Down
23 changes: 19 additions & 4 deletions lldb/include/lldb/Utility/DataExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef LLDB_UTILITY_DATAEXTRACTOR_H
#define LLDB_UTILITY_DATAEXTRACTOR_H

#include "lldb/Utility/DataBuffer.h"
#include "lldb/Utility/Endian.h"
#include "lldb/lldb-defines.h"
#include "lldb/lldb-enumerations.h"
Expand Down Expand Up @@ -90,10 +91,10 @@ class DataExtractor {

/// Construct with shared data.
///
/// Copies the data shared pointer which adds a reference to the contained
/// in \a data_sp. The shared data reference is reference counted to ensure
/// the data lives as long as anyone still has a valid shared pointer to the
/// data in \a data_sp.
/// Copies the data shared pointer which adds a reference to the data
/// contained in \a data_sp. The shared data reference is reference counted to
/// ensure the data lives as long as anyone still has a valid shared pointer
/// to the data in \a data_sp.
///
/// \param[in] data_sp
/// A shared pointer to data.
Expand All @@ -109,6 +110,18 @@ class DataExtractor {
DataExtractor(const lldb::DataBufferSP &data_sp, lldb::ByteOrder byte_order,
uint32_t addr_size, uint32_t target_byte_size = 1);

/// Construct with shared data, but byte-order & addr-size are unspecified.
///
/// Copies the data shared pointer which adds a reference to the data
/// contained in \a data_sp. The shared data reference is reference counted to
/// ensure the data lives as long as anyone still has a valid shared pointer
/// to the data in \a data_sp.
///
/// \param[in] data_sp
/// A shared pointer to data.
DataExtractor(const lldb::DataBufferSP &data_sp,
uint32_t target_byte_size = 1);

/// Construct with a subset of \a data.
///
/// Initialize this object with a subset of the data bytes in \a data. If \a
Expand Down Expand Up @@ -807,6 +820,8 @@ class DataExtractor {

lldb::DataBufferSP &GetSharedDataBuffer() { return m_data_sp; }

bool HasData() { return m_start && m_end && m_end - m_start > 0; }

/// Peek at a C string at \a offset.
///
/// Peeks at a string in the contained data. No verification is done to make
Expand Down
10 changes: 4 additions & 6 deletions lldb/include/lldb/lldb-private-interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ typedef size_t (*ObjectFileGetModuleSpecifications)(
const FileSpec &file, lldb::DataBufferSP &data_sp,
lldb::offset_t data_offset, lldb::offset_t file_offset,
lldb::offset_t length, ModuleSpecList &module_specs);
typedef ObjectFile *(*ObjectFileCreateInstance)(const lldb::ModuleSP &module_sp,
lldb::DataBufferSP data_sp,
lldb::offset_t data_offset,
const FileSpec *file,
lldb::offset_t file_offset,
lldb::offset_t length);
typedef ObjectFile *(*ObjectFileCreateInstance)(
const lldb::ModuleSP &module_sp, lldb::DataExtractorSP extractor_sp,
lldb::offset_t data_offset, const FileSpec *file,
lldb::offset_t file_offset, lldb::offset_t length);
typedef ObjectFile *(*ObjectFileCreateMemoryInstance)(
const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
const lldb::ProcessSP &process_sp, lldb::addr_t offset);
Expand Down
6 changes: 4 additions & 2 deletions lldb/source/Core/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1206,10 +1206,12 @@ ObjectFile *Module::GetObjectFile() {
m_did_load_objfile = true;
// FindPlugin will modify its data_sp argument. Do not let it
// modify our m_data_sp member.
auto data_sp = m_data_sp;
DataExtractorSP extractor_sp;
if (m_data_sp)
extractor_sp = std::make_shared<DataExtractor>(m_data_sp);
m_objfile_sp = ObjectFile::FindPlugin(
shared_from_this(), &m_file, m_object_offset,
file_size - m_object_offset, data_sp, data_offset);
file_size - m_object_offset, extractor_sp, data_offset);
if (m_objfile_sp) {
// Once we get the object file, update our module with the object
// file's architecture since it might differ in vendor/os if some
Expand Down
5 changes: 3 additions & 2 deletions lldb/source/Expression/ObjectFileJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void ObjectFileJIT::Terminate() {
}

ObjectFile *ObjectFileJIT::CreateInstance(const lldb::ModuleSP &module_sp,
DataBufferSP data_sp,
DataExtractorSP extractor_sp,
lldb::offset_t data_offset,
const FileSpec *file,
lldb::offset_t file_offset,
Expand Down Expand Up @@ -70,7 +70,8 @@ size_t ObjectFileJIT::GetModuleSpecifications(

ObjectFileJIT::ObjectFileJIT(const lldb::ModuleSP &module_sp,
const ObjectFileJITDelegateSP &delegate_sp)
: ObjectFile(module_sp, nullptr, 0, 0, DataBufferSP(), 0), m_delegate_wp() {
: ObjectFile(module_sp, nullptr, 0, 0, DataExtractorSP(), 0),
m_delegate_wp() {
if (delegate_sp) {
m_delegate_wp = delegate_sp;
m_data_nsp->SetByteOrder(delegate_sp->GetByteOrder());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,19 @@ void ObjectContainerBSDArchive::Object::Dump() const {
ObjectContainerBSDArchive::Archive::Archive(const lldb_private::ArchSpec &arch,
const llvm::sys::TimePoint<> &time,
lldb::offset_t file_offset,
lldb_private::DataExtractor &data,
lldb::DataExtractorSP extractor_sp,
ArchiveType archive_type)
: m_arch(arch), m_modification_time(time), m_file_offset(file_offset),
m_objects(), m_data(data), m_archive_type(archive_type) {}
m_objects(), m_extractor_sp(extractor_sp), m_archive_type(archive_type) {}

Log *l = GetLog(LLDBLog::Object);
ObjectContainerBSDArchive::Archive::~Archive() = default;

size_t ObjectContainerBSDArchive::Archive::ParseObjects() {
DataExtractor &data = m_data;

std::unique_ptr<llvm::MemoryBuffer> mem_buffer =
llvm::MemoryBuffer::getMemBuffer(
llvm::StringRef((const char *)data.GetDataStart(),
data.GetByteSize()),
llvm::StringRef((const char *)m_extractor_sp->GetDataStart(),
m_extractor_sp->GetByteSize()),
llvm::StringRef(),
/*RequiresNullTerminator=*/false);

Expand Down Expand Up @@ -221,9 +219,9 @@ ObjectContainerBSDArchive::Archive::shared_ptr
ObjectContainerBSDArchive::Archive::ParseAndCacheArchiveForFile(
const FileSpec &file, const ArchSpec &arch,
const llvm::sys::TimePoint<> &time, lldb::offset_t file_offset,
DataExtractor &data, ArchiveType archive_type) {
DataExtractorSP extractor_sp, ArchiveType archive_type) {
shared_ptr archive_sp(
new Archive(arch, time, file_offset, data, archive_type));
new Archive(arch, time, file_offset, extractor_sp, archive_type));
if (archive_sp) {
const size_t num_objects = archive_sp->ParseObjects();
if (num_objects > 0) {
Expand Down Expand Up @@ -368,16 +366,17 @@ ObjectContainerBSDArchive::~ObjectContainerBSDArchive() = default;

bool ObjectContainerBSDArchive::ParseHeader() {
if (m_archive_sp.get() == nullptr) {
if (m_data.GetByteSize() > 0) {
if (m_extractor_sp->GetByteSize() > 0) {
ModuleSP module_sp(GetModule());
if (module_sp) {
m_archive_sp = Archive::ParseAndCacheArchiveForFile(
m_file, module_sp->GetArchitecture(),
module_sp->GetModificationTime(), m_offset, m_data, m_archive_type);
module_sp->GetModificationTime(), m_offset, m_extractor_sp,
m_archive_type);
}
// Clear the m_data that contains the entire archive data and let our
// m_archive_sp hold onto the data.
m_data.Clear();
// Clear the m_extractor_sp that contains the entire archive data and let
// our m_archive_sp hold onto the data.
m_extractor_sp = std::make_shared<DataExtractor>();
}
}
return m_archive_sp.get() != nullptr;
Expand Down Expand Up @@ -416,14 +415,18 @@ ObjectFileSP ObjectContainerBSDArchive::GetObjectFile(const FileSpec *file) {
child_data_sp->GetByteSize() != object->file_size)
return ObjectFileSP();
lldb::offset_t data_offset = 0;
DataExtractorSP extractor_sp =
std::make_shared<DataExtractor>(child_data_sp);
return ObjectFile::FindPlugin(
module_sp, &child, m_offset + object->file_offset,
object->file_size, child_data_sp, data_offset);
object->file_size, extractor_sp, data_offset);
}
lldb::offset_t data_offset = object->file_offset;
DataExtractorSP extractor_sp =
std::make_shared<DataExtractor>(m_archive_sp->GetData());
return ObjectFile::FindPlugin(
module_sp, file, m_offset + object->file_offset, object->file_size,
m_archive_sp->GetData().GetSharedDataBuffer(), data_offset);
extractor_sp, data_offset);
}
}
}
Expand All @@ -438,9 +441,10 @@ size_t ObjectContainerBSDArchive::GetModuleSpecifications(
// We have data, which means this is the first 512 bytes of the file Check to
// see if the magic bytes match and if they do, read the entire table of
// contents for the archive and cache it
DataExtractor data;
data.SetData(data_sp, data_offset, data_sp->GetByteSize());
ArchiveType archive_type = ObjectContainerBSDArchive::MagicBytesMatch(data);
DataExtractorSP extractor_sp = std::make_shared<DataExtractor>();
extractor_sp->SetData(data_sp, data_offset, data_sp->GetByteSize());
ArchiveType archive_type =
ObjectContainerBSDArchive::MagicBytesMatch(*extractor_sp.get());
if (!file || !data_sp || archive_type == ArchiveType::Invalid)
return 0;

Expand All @@ -455,9 +459,10 @@ size_t ObjectContainerBSDArchive::GetModuleSpecifications(
data_sp =
FileSystem::Instance().CreateDataBuffer(file, file_size, file_offset);
if (data_sp) {
data.SetData(data_sp, 0, data_sp->GetByteSize());
extractor_sp->SetData(data_sp);
archive_sp = Archive::ParseAndCacheArchiveForFile(
file, ArchSpec(), file_mod_time, file_offset, data, archive_type);
file, ArchSpec(), file_mod_time, file_offset, extractor_sp,
archive_type);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#include "lldb/Symbol/ObjectContainer.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/NonNullSharedPtr.h"

#include "llvm/Object/Archive.h"
#include "llvm/Support/Chrono.h"
Expand Down Expand Up @@ -59,7 +61,8 @@ class ObjectContainerBSDArchive : public lldb_private::ObjectContainer {
lldb::offset_t length,
lldb_private::ModuleSpecList &specs);

static ArchiveType MagicBytesMatch(const lldb_private::DataExtractor &data);
static ArchiveType
MagicBytesMatch(const lldb_private::DataExtractor &extractor);

// Member Functions
bool ParseHeader() override;
Expand All @@ -81,11 +84,11 @@ class ObjectContainerBSDArchive : public lldb_private::ObjectContainer {

void Clear();

lldb::offset_t ExtractFromThin(const lldb_private::DataExtractor &data,
lldb::offset_t ExtractFromThin(const lldb_private::DataExtractor &extractor,
lldb::offset_t offset,
llvm::StringRef stringTable);

lldb::offset_t Extract(const lldb_private::DataExtractor &data,
lldb::offset_t Extract(const lldb_private::DataExtractor &extractor,
lldb::offset_t offset);
/// Object name in the archive.
lldb_private::ConstString ar_name;
Expand All @@ -112,7 +115,7 @@ class ObjectContainerBSDArchive : public lldb_private::ObjectContainer {

Archive(const lldb_private::ArchSpec &arch,
const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset,
lldb_private::DataExtractor &data, ArchiveType archive_type);
lldb::DataExtractorSP extractor_sp, ArchiveType archive_type);

~Archive();

Expand All @@ -127,7 +130,7 @@ class ObjectContainerBSDArchive : public lldb_private::ObjectContainer {
static Archive::shared_ptr ParseAndCacheArchiveForFile(
const lldb_private::FileSpec &file, const lldb_private::ArchSpec &arch,
const llvm::sys::TimePoint<> &mod_time, lldb::offset_t file_offset,
lldb_private::DataExtractor &data, ArchiveType archive_type);
lldb::DataExtractorSP extractor_sp, ArchiveType archive_type);

size_t GetNumObjects() const { return m_objects.size(); }

Expand All @@ -154,7 +157,8 @@ class ObjectContainerBSDArchive : public lldb_private::ObjectContainer {

bool HasNoExternalReferences() const;

lldb_private::DataExtractor &GetData() { return m_data; }
lldb_private::DataExtractor &GetData() { return *m_extractor_sp.get(); }
lldb::DataExtractorSP &GetDataSP() { return m_extractor_sp; }

ArchiveType GetArchiveType() { return m_archive_type; }

Expand All @@ -166,9 +170,9 @@ class ObjectContainerBSDArchive : public lldb_private::ObjectContainer {
lldb::offset_t m_file_offset;
std::vector<Object> m_objects;
ObjectNameToIndexMap m_object_name_to_index_map;
lldb_private::DataExtractor m_data; ///< The data for this object container
///so we don't lose data if the .a files
///gets modified
/// The data for this object container so we don't lose data if the .a files
/// gets modified.
lldb::DataExtractorSP m_extractor_sp;
ArchiveType m_archive_type;
};

Expand Down
Loading
Loading