1 //===-- SymbolVendor.cpp --------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Symbol/SymbolVendor.h"
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"
19 using namespace lldb_private
;
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.
26 SymbolVendor
*SymbolVendor::FindPlugin(const lldb::ModuleSP
&module_sp
,
27 lldb_private::Stream
*feedback_strm
) {
28 std::unique_ptr
<SymbolVendor
> instance_up
;
29 SymbolVendorCreateInstance create_callback
;
32 (create_callback
= PluginManager::GetSymbolVendorCreateCallbackAtIndex(
35 instance_up
.reset(create_callback(module_sp
, feedback_strm
));
38 return instance_up
.release();
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()) {
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
);
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();
59 // SymbolVendor constructor
60 SymbolVendor::SymbolVendor(const lldb::ModuleSP
&module_sp
)
61 : ModuleChild(module_sp
), m_sym_file_up() {}
63 // Add a representation given an object file.
64 void SymbolVendor::AddSymbolFileRepresentation(const ObjectFileSP
&objfile_sp
) {
65 ModuleSP
module_sp(GetModule());
67 std::lock_guard
<std::recursive_mutex
> guard(module_sp
->GetMutex());
69 m_sym_file_up
.reset(SymbolFile::FindPlugin(objfile_sp
));