1//===-- SymbolVendor.cpp --------------------------------------------------===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9#include "lldb/Symbol/SymbolVendor.h" 10 11#include "lldb/Core/Module.h" 12#include "lldb/Core/PluginManager.h" 13#include "lldb/Symbol/CompileUnit.h" 14#include "lldb/Symbol/ObjectFile.h" 15#include "lldb/Symbol/SymbolFile.h" 16#include "lldb/Utility/Stream.h" 17 18using namespace lldb; 19using namespace lldb_private; 20 21// FindPlugin 22// 23// Platforms can register a callback to use when creating symbol vendors to 24// allow for complex debug information file setups, and to also allow for 25// finding separate debug information files. 26SymbolVendor *SymbolVendor::FindPlugin(const lldb::ModuleSP &module_sp, 27 lldb_private::Stream *feedback_strm) { 28 std::unique_ptr<SymbolVendor> instance_up; 29 SymbolVendorCreateInstance create_callback; 30 31 for (size_t idx = 0; 32 (create_callback = PluginManager::GetSymbolVendorCreateCallbackAtIndex( 33 idx)) != nullptr; 34 ++idx) { 35 instance_up.reset(create_callback(module_sp, feedback_strm)); 36 37 if (instance_up) { 38 return instance_up.release(); 39 } 40 } 41 // The default implementation just tries to create debug information using 42 // the file representation for the module. 43 ObjectFileSP sym_objfile_sp; 44 FileSpec sym_spec = module_sp->GetSymbolFileFileSpec(); 45 if (sym_spec && sym_spec != module_sp->GetObjectFile()->GetFileSpec()) { 46 DataBufferSP data_sp; 47 offset_t data_offset = 0; 48 sym_objfile_sp = ObjectFile::FindPlugin( 49 module_sp, &sym_spec, 0, FileSystem::Instance().GetByteSize(sym_spec), 50 data_sp, data_offset); 51 } 52 if (!sym_objfile_sp) 53 sym_objfile_sp = module_sp->GetObjectFile()->shared_from_this(); 54 instance_up = std::make_unique<SymbolVendor>(module_sp); 55 instance_up->AddSymbolFileRepresentation(sym_objfile_sp); 56 return instance_up.release(); 57} 58 59// SymbolVendor constructor 60SymbolVendor::SymbolVendor(const lldb::ModuleSP &module_sp) 61 : ModuleChild(module_sp), m_sym_file_up() {} 62 63// Add a representation given an object file. 64void SymbolVendor::AddSymbolFileRepresentation(const ObjectFileSP &objfile_sp) { 65 ModuleSP module_sp(GetModule()); 66 if (module_sp) { 67 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); 68 if (objfile_sp) 69 m_sym_file_up.reset(SymbolFile::FindPlugin(objfile_sp)); 70 } 71} 72