mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 11:02:04 +08:00
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>
72 lines
2.6 KiB
C++
72 lines
2.6 KiB
C++
//===-- SymbolVendor.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/SymbolVendor.h"
|
|
|
|
#include "lldb/Core/Module.h"
|
|
#include "lldb/Core/PluginManager.h"
|
|
#include "lldb/Symbol/CompileUnit.h"
|
|
#include "lldb/Symbol/ObjectFile.h"
|
|
#include "lldb/Symbol/SymbolFile.h"
|
|
#include "lldb/Utility/Stream.h"
|
|
|
|
using namespace lldb;
|
|
using namespace lldb_private;
|
|
|
|
// FindPlugin
|
|
//
|
|
// Platforms can register a callback to use when creating symbol vendors to
|
|
// allow for complex debug information file setups, and to also allow for
|
|
// finding separate debug information files.
|
|
SymbolVendor *SymbolVendor::FindPlugin(const lldb::ModuleSP &module_sp,
|
|
lldb_private::Stream *feedback_strm) {
|
|
std::unique_ptr<SymbolVendor> instance_up;
|
|
SymbolVendorCreateInstance create_callback;
|
|
|
|
for (size_t idx = 0;
|
|
(create_callback = PluginManager::GetSymbolVendorCreateCallbackAtIndex(
|
|
idx)) != nullptr;
|
|
++idx) {
|
|
instance_up.reset(create_callback(module_sp, feedback_strm));
|
|
|
|
if (instance_up) {
|
|
return instance_up.release();
|
|
}
|
|
}
|
|
// The default implementation just tries to create debug information using
|
|
// the file representation for the module.
|
|
ObjectFileSP sym_objfile_sp;
|
|
FileSpec sym_spec = module_sp->GetSymbolFileFileSpec();
|
|
if (sym_spec && sym_spec != module_sp->GetObjectFile()->GetFileSpec()) {
|
|
DataExtractorSP extractor_sp;
|
|
offset_t data_offset = 0;
|
|
sym_objfile_sp = ObjectFile::FindPlugin(
|
|
module_sp, &sym_spec, 0, FileSystem::Instance().GetByteSize(sym_spec),
|
|
extractor_sp, data_offset);
|
|
}
|
|
if (!sym_objfile_sp)
|
|
sym_objfile_sp = module_sp->GetObjectFile()->shared_from_this();
|
|
instance_up = std::make_unique<SymbolVendor>(module_sp);
|
|
instance_up->AddSymbolFileRepresentation(sym_objfile_sp);
|
|
return instance_up.release();
|
|
}
|
|
|
|
// SymbolVendor constructor
|
|
SymbolVendor::SymbolVendor(const lldb::ModuleSP &module_sp)
|
|
: ModuleChild(module_sp), m_sym_file_up() {}
|
|
|
|
// Add a representation given an object file.
|
|
void SymbolVendor::AddSymbolFileRepresentation(const ObjectFileSP &objfile_sp) {
|
|
ModuleSP module_sp(GetModule());
|
|
if (module_sp) {
|
|
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
|
|
if (objfile_sp)
|
|
m_sym_file_up.reset(SymbolFile::FindPlugin(objfile_sp));
|
|
}
|
|
}
|