1 //===-- SymbolFile.cpp ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Symbol/SymbolFile.h"
12 #include "lldb/Core/Module.h"
13 #include "lldb/Core/PluginManager.h"
14 #include "lldb/Symbol/ObjectFile.h"
15 #include "lldb/Symbol/TypeMap.h"
16 #include "lldb/Symbol/TypeSystem.h"
17 #include "lldb/Symbol/VariableList.h"
18 #include "lldb/Utility/Log.h"
19 #include "lldb/Utility/StreamString.h"
20 #include "lldb/lldb-private.h"
22 using namespace lldb_private;
24 void SymbolFile::PreloadSymbols() {
25 // No-op for most implementations.
28 SymbolFile *SymbolFile::FindPlugin(ObjectFile *obj_file) {
29 std::unique_ptr<SymbolFile> best_symfile_ap;
30 if (obj_file != nullptr) {
32 // We need to test the abilities of this section list. So create what it
34 // be with this new obj_file.
35 lldb::ModuleSP module_sp(obj_file->GetModule());
37 // Default to the main module section list.
38 ObjectFile *module_obj_file = module_sp->GetObjectFile();
39 if (module_obj_file != obj_file) {
40 // Make sure the main object file's sections are created
41 module_obj_file->GetSectionList();
42 obj_file->CreateSections(*module_sp->GetUnifiedSectionList());
46 // TODO: Load any plug-ins in the appropriate plug-in search paths and
47 // iterate over all of them to find the best one for the job.
49 uint32_t best_symfile_abilities = 0;
51 SymbolFileCreateInstance create_callback;
52 for (uint32_t idx = 0;
53 (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(
56 std::unique_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file));
58 if (curr_symfile_ap.get()) {
59 const uint32_t sym_file_abilities = curr_symfile_ap->GetAbilities();
60 if (sym_file_abilities > best_symfile_abilities) {
61 best_symfile_abilities = sym_file_abilities;
62 best_symfile_ap.reset(curr_symfile_ap.release());
63 // If any symbol file parser has all of the abilities, then
64 // we should just stop looking.
65 if ((kAllAbilities & sym_file_abilities) == kAllAbilities)
70 if (best_symfile_ap.get()) {
71 // Let the winning symbol file parser initialize itself more
72 // completely now that it has been chosen
73 best_symfile_ap->InitializeObject();
76 return best_symfile_ap.release();
79 TypeList *SymbolFile::GetTypeList() {
81 return m_obj_file->GetModule()->GetTypeList();
85 TypeSystem *SymbolFile::GetTypeSystemForLanguage(lldb::LanguageType language) {
86 TypeSystem *type_system =
87 m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
89 type_system->SetSymbolFile(this);
93 uint32_t SymbolFile::ResolveSymbolContext(const FileSpec &file_spec,
94 uint32_t line, bool check_inlines,
95 uint32_t resolve_scope,
96 SymbolContextList &sc_list) {
100 uint32_t SymbolFile::FindGlobalVariables(
101 const ConstString &name, const CompilerDeclContext *parent_decl_ctx,
102 bool append, uint32_t max_matches, VariableList &variables) {
108 uint32_t SymbolFile::FindGlobalVariables(const RegularExpression ®ex,
109 bool append, uint32_t max_matches,
110 VariableList &variables) {
116 uint32_t SymbolFile::FindFunctions(const ConstString &name,
117 const CompilerDeclContext *parent_decl_ctx,
118 uint32_t name_type_mask,
119 bool include_inlines, bool append,
120 SymbolContextList &sc_list) {
126 uint32_t SymbolFile::FindFunctions(const RegularExpression ®ex,
127 bool include_inlines, bool append,
128 SymbolContextList &sc_list) {
134 void SymbolFile::GetMangledNamesForFunction(
135 const std::string &scope_qualified_name,
136 std::vector<ConstString> &mangled_names) {
140 uint32_t SymbolFile::FindTypes(
141 const SymbolContext &sc, const ConstString &name,
142 const CompilerDeclContext *parent_decl_ctx, bool append,
143 uint32_t max_matches,
144 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
151 size_t SymbolFile::FindTypes(const std::vector<CompilerContext> &context,
152 bool append, TypeMap &types) {