Files
llvm/lldb/source/Symbol/ObjectContainer.cpp
Jason Molenda e4c83b7b11 [lldb][NFC] Change ObjectFile argument type (#171574)
The ObjectFile plugin interface accepts an optional DataBufferSP
argument. If the caller has the contents of the binary, it can provide
this in that DataBufferSP. The ObjectFile subclasses in their
CreateInstance methods will fill in the DataBufferSP with the actual
binary contents if it is not set.
ObjectFile base class creates an ivar DataExtractor from the
DataBufferSP passed in.

My next patch will be a caller that creates a VirtualDataExtractor with
the binary data, and needs to pass that in to the ObjectFile plugin,
instead of the bag-of-bytes DataBufferSP. It builds on the previous
patch changing ObjectFile's ivar from DataExtractor to DataExtractorSP
so I could pass in a subclass in the shared ptr. And it will be using
the VirtualDataExtractor that Jonas added in
https://github.com/llvm/llvm-project/pull/168802

No behavior is changed by the patch; we're simply moving the creation of
the DataExtractor to the caller, instead of a DataBuffer that is
immediately used to set up the ObjectFile DataExtractor. The patch is a
bit complicated because all of the ObjectFile subclasses have to
initialize their DataExtractor to pass in to the base class.

I ran the testsuite on macOS and on AArch64 Ubutnu. (btw David, I ran it
under qemu on my M4 mac with SME-no-SVE again, Ubuntu 25.10, checked
lshw(1) cpu capabilities, and qemu doesn't seem to be virtualizing the
SME, that explains why the testsuite passes)

rdar://148939795

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-12-11 10:08:56 -08:00

62 lines
2.3 KiB
C++

//===-- ObjectContainer.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lldb/Symbol/ObjectContainer.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/Timer.h"
using namespace lldb;
using namespace lldb_private;
ObjectContainer::ObjectContainer(const lldb::ModuleSP &module_sp,
const FileSpec *file,
lldb::offset_t file_offset,
lldb::offset_t length,
lldb::DataBufferSP data_sp,
lldb::offset_t data_offset)
: ModuleChild(module_sp),
m_file(), // This file can be different than the module's file spec
m_offset(file_offset), m_length(length),
m_extractor_sp(std::make_shared<DataExtractor>()) {
if (file)
m_file = *file;
if (data_sp) {
m_extractor_sp->SetData(data_sp, data_offset, length);
}
}
ObjectContainerSP ObjectContainer::FindPlugin(const lldb::ModuleSP &module_sp,
const ProcessSP &process_sp,
lldb::addr_t header_addr,
WritableDataBufferSP data_sp) {
if (!module_sp)
return {};
LLDB_SCOPED_TIMERF("ObjectContainer::FindPlugin (module = "
"%s, process = %p, header_addr = "
"0x%" PRIx64 ")",
module_sp->GetFileSpec().GetPath().c_str(),
static_cast<void *>(process_sp.get()), header_addr);
ObjectContainerCreateMemoryInstance create_callback;
for (size_t idx = 0;
(create_callback =
PluginManager::GetObjectContainerCreateMemoryCallbackAtIndex(
idx)) != nullptr;
++idx) {
ObjectContainerSP object_container_sp(
create_callback(module_sp, data_sp, process_sp, header_addr));
if (object_container_sp)
return object_container_sp;
}
return {};
}