LLDB  mainline
SymbolVendor.cpp
Go to the documentation of this file.
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 
10 
11 #include "lldb/Core/Module.h"
14 #include "lldb/Symbol/ObjectFile.h"
15 #include "lldb/Symbol/SymbolFile.h"
16 #include "lldb/Utility/Stream.h"
17 
18 using namespace lldb;
19 using 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.
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;
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
60 SymbolVendor::SymbolVendor(const lldb::ModuleSP &module_sp)
61  : ModuleChild(module_sp), m_sym_file_up() {}
62 
63 // Add a representation given an object file.
64 void 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 
73 // PluginInterface protocol
75  static ConstString g_name("vendor-default");
76  return g_name;
77 }
78 
lldb_private::SymbolFile::FindPlugin
static SymbolFile * FindPlugin(lldb::ObjectFileSP objfile_sp)
Definition: SymbolFile.cpp:40
lldb_private::SymbolVendor::AddSymbolFileRepresentation
void AddSymbolFileRepresentation(const lldb::ObjectFileSP &objfile_sp)
Definition: SymbolVendor.cpp:64
lldb_private::ModuleChild
Definition: ModuleChild.h:19
CompileUnit.h
lldb_private::SymbolVendor::m_sym_file_up
std::unique_ptr< SymbolFile > m_sym_file_up
Definition: SymbolVendor.h:49
Module.h
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::Stream
Definition: Stream.h:28
lldb_private::SymbolVendor
Definition: SymbolVendor.h:31
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::ConstString
Definition: ConstString.h:40
ObjectFile.h
uint32_t
lldb_private::SymbolVendor::GetPluginVersion
uint32_t GetPluginVersion() override
Definition: SymbolVendor.cpp:79
lldb_private::ModuleChild::GetModule
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:24
PluginManager.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Stream.h
SymbolVendor.h
lldb
Definition: SBAddress.h:15
SymbolFile.h
lldb_private::SymbolVendor::GetPluginName
ConstString GetPluginName() override
Definition: SymbolVendor.cpp:74