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/VariableList.h"
20 
21 using namespace lldb_private;
22 
23 SymbolFile*
24 SymbolFile::FindPlugin (ObjectFile* obj_file)
25 {
26     std::unique_ptr<SymbolFile> best_symfile_ap;
27     if (obj_file != nullptr)
28     {
29 
30         // We need to test the abilities of this section list. So create what it would
31         // be with this new obj_file.
32         lldb::ModuleSP module_sp(obj_file->GetModule());
33         if (module_sp)
34         {
35             // Default to the main module section list.
36             ObjectFile *module_obj_file = module_sp->GetObjectFile();
37             if (module_obj_file != obj_file)
38             {
39                 // Make sure the main object file's sections are created
40                 module_obj_file->GetSectionList();
41                 obj_file->CreateSections (*module_sp->GetUnifiedSectionList());
42             }
43         }
44 
45         // TODO: Load any plug-ins in the appropriate plug-in search paths and
46         // iterate over all of them to find the best one for the job.
47 
48         uint32_t best_symfile_abilities = 0;
49 
50         SymbolFileCreateInstance create_callback;
51         for (uint32_t idx = 0; (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(idx)) != nullptr; ++idx)
52         {
53             std::unique_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file));
54 
55             if (curr_symfile_ap.get())
56             {
57                 const uint32_t sym_file_abilities = curr_symfile_ap->GetAbilities();
58                 if (sym_file_abilities > best_symfile_abilities)
59                 {
60                     best_symfile_abilities = sym_file_abilities;
61                     best_symfile_ap.reset (curr_symfile_ap.release());
62                     // If any symbol file parser has all of the abilities, then
63                     // we should just stop looking.
64                     if ((kAllAbilities & sym_file_abilities) == kAllAbilities)
65                         break;
66                 }
67             }
68         }
69         if (best_symfile_ap.get())
70         {
71             // Let the winning symbol file parser initialize itself more
72             // completely now that it has been chosen
73             best_symfile_ap->InitializeObject();
74         }
75     }
76     return best_symfile_ap.release();
77 }
78 
79 TypeList *
80 SymbolFile::GetTypeList ()
81 {
82     if (m_obj_file)
83         return m_obj_file->GetModule()->GetTypeList();
84     return nullptr;
85 }
86 
87 ClangASTContext &
88 SymbolFile::GetClangASTContext ()
89 {
90     return m_obj_file->GetModule()->GetClangASTContext();
91 }
92 
93 TypeSystem *
94 SymbolFile::GetTypeSystemForLanguage (lldb::LanguageType language)
95 {
96     TypeSystem *type_system = m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
97     if (type_system)
98         type_system->SetSymbolFile(this);
99     return type_system;
100 }
101 
102 uint32_t
103 SymbolFile::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
104 {
105     return 0;
106 }
107 
108 
109 uint32_t
110 SymbolFile::FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, VariableList& variables)
111 {
112     if (!append)
113         variables.Clear();
114     return 0;
115 }
116 
117 
118 uint32_t
119 SymbolFile::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
120 {
121     if (!append)
122         variables.Clear();
123         return 0;
124 }
125 
126 uint32_t
127 SymbolFile::FindFunctions (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list)
128 {
129     if (!append)
130         sc_list.Clear();
131     return 0;
132 }
133 
134 uint32_t
135 SymbolFile::FindFunctions (const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
136 {
137     if (!append)
138         sc_list.Clear();
139     return 0;
140 }
141 
142 uint32_t
143 SymbolFile::FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, TypeList& types)
144 {
145     if (!append)
146         types.Clear();
147     return 0;
148 }
149 
150