1 //===-- SymbolFile.cpp ------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/Symbol/SymbolFile.h"
11 
12 #include "lldb/lldb-private.h"
13 #include "lldb/Core/Log.h"
14 #include "lldb/Core/Module.h"
15 #include "lldb/Core/PluginManager.h"
16 #include "lldb/Core/StreamString.h"
17 #include "lldb/Symbol/ObjectFile.h"
18 #include "lldb/Symbol/TypeList.h"
19 #include "lldb/Symbol/TypeSystem.h"
20 #include "lldb/Symbol/VariableList.h"
21 
22 using namespace lldb_private;
23 
24 SymbolFile*
25 SymbolFile::FindPlugin (ObjectFile* obj_file)
26 {
27     std::unique_ptr<SymbolFile> best_symfile_ap;
28     if (obj_file != nullptr)
29     {
30 
31         // We need to test the abilities of this section list. So create what it would
32         // be with this new obj_file.
33         lldb::ModuleSP module_sp(obj_file->GetModule());
34         if (module_sp)
35         {
36             // Default to the main module section list.
37             ObjectFile *module_obj_file = module_sp->GetObjectFile();
38             if (module_obj_file != obj_file)
39             {
40                 // Make sure the main object file's sections are created
41                 module_obj_file->GetSectionList();
42                 obj_file->CreateSections (*module_sp->GetUnifiedSectionList());
43             }
44         }
45 
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.
48 
49         uint32_t best_symfile_abilities = 0;
50 
51         SymbolFileCreateInstance create_callback;
52         for (uint32_t idx = 0; (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(idx)) != nullptr; ++idx)
53         {
54             std::unique_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file));
55 
56             if (curr_symfile_ap.get())
57             {
58                 const uint32_t sym_file_abilities = curr_symfile_ap->GetAbilities();
59                 if (sym_file_abilities > best_symfile_abilities)
60                 {
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)
66                         break;
67                 }
68             }
69         }
70         if (best_symfile_ap.get())
71         {
72             // Let the winning symbol file parser initialize itself more
73             // completely now that it has been chosen
74             best_symfile_ap->InitializeObject();
75         }
76     }
77     return best_symfile_ap.release();
78 }
79 
80 TypeList *
81 SymbolFile::GetTypeList ()
82 {
83     if (m_obj_file)
84         return m_obj_file->GetModule()->GetTypeList();
85     return nullptr;
86 }
87 
88 TypeSystem *
89 SymbolFile::GetTypeSystemForLanguage (lldb::LanguageType language)
90 {
91     TypeSystem *type_system = m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
92     if (type_system)
93         type_system->SetSymbolFile(this);
94     return type_system;
95 }
96 
97 uint32_t
98 SymbolFile::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
99 {
100     return 0;
101 }
102 
103 
104 uint32_t
105 SymbolFile::FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, VariableList& variables)
106 {
107     if (!append)
108         variables.Clear();
109     return 0;
110 }
111 
112 
113 uint32_t
114 SymbolFile::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
115 {
116     if (!append)
117         variables.Clear();
118         return 0;
119 }
120 
121 uint32_t
122 SymbolFile::FindFunctions (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list)
123 {
124     if (!append)
125         sc_list.Clear();
126     return 0;
127 }
128 
129 uint32_t
130 SymbolFile::FindFunctions (const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
131 {
132     if (!append)
133         sc_list.Clear();
134     return 0;
135 }
136 
137 uint32_t
138 SymbolFile::FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, TypeList& types)
139 {
140     if (!append)
141         types.Clear();
142     return 0;
143 }
144 
145