This PR replaces the Get*CallbackAtIndex pattern in the PluginManager with returning a snapshot of callbacks that the caller can iterate over using a range-based for loop. This is a continuation of #184452 which added thread safety by using snapshots. However, that introduced a bunch of unnecessary copies which are largely eliminated again by getting the snapshot once when gather all the callbacks, rather than doing that on each iteration when querying a plugin for a given index. It also eliminates the possibility of the snapshot changing underneath you when iterating over the plugins. This change was largely mechanical and I used Claude to do the menial work of updating the signatures and call sites.
59 lines
2.2 KiB
C++
59 lines
2.2 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);
|
|
|
|
for (auto &cbs : PluginManager::GetObjectContainerCallbacks()) {
|
|
if (!cbs.create_memory_callback)
|
|
continue;
|
|
ObjectContainerSP object_container_sp(cbs.create_memory_callback(
|
|
module_sp, data_sp, process_sp, header_addr));
|
|
if (object_container_sp)
|
|
return object_container_sp;
|
|
}
|
|
|
|
return {};
|
|
}
|