blob: eb20b80f49167d9f1d8cb4053dda1b53c6fb1288 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000010#include "lldb/Symbol/SymbolFile.h"
Greg Claytonc982b3d2011-11-28 01:45:00 +000011
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000012#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013#include "lldb/Core/PluginManager.h"
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000014#include "lldb/Symbol/ObjectFile.h"
Ravitheja Addepally40697302015-10-08 09:45:41 +000015#include "lldb/Symbol/TypeMap.h"
Greg Clayton56939cb2015-09-17 22:23:34 +000016#include "lldb/Symbol/TypeSystem.h"
Greg Clayton99558cc42015-08-24 23:46:31 +000017#include "lldb/Symbol/VariableList.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000018#include "lldb/Utility/Log.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000019#include "lldb/Utility/StreamString.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000020#include "lldb/lldb-private.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
22using namespace lldb_private;
23
Jim Ingham7fca8c02017-04-28 00:51:06 +000024void SymbolFile::PreloadSymbols() {
25 // No-op for most implementations.
26}
27
Kate Stoneb9c1b512016-09-06 20:57:50 +000028SymbolFile *SymbolFile::FindPlugin(ObjectFile *obj_file) {
29 std::unique_ptr<SymbolFile> best_symfile_ap;
30 if (obj_file != nullptr) {
Greg Clayton3046e662013-07-10 01:23:25 +000031
Kate Stoneb9c1b512016-09-06 20:57:50 +000032 // We need to test the abilities of this section list. So create what it
33 // would
34 // be with this new obj_file.
35 lldb::ModuleSP module_sp(obj_file->GetModule());
36 if (module_sp) {
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());
43 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000045
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;
53 (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(
54 idx)) != nullptr;
55 ++idx) {
56 std::unique_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file));
57
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)
66 break;
67 }
68 }
69 }
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();
74 }
75 }
76 return best_symfile_ap.release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077}
78
Kate Stoneb9c1b512016-09-06 20:57:50 +000079TypeList *SymbolFile::GetTypeList() {
80 if (m_obj_file)
81 return m_obj_file->GetModule()->GetTypeList();
82 return nullptr;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000083}
Greg Clayton6beaaa62011-01-17 03:46:26 +000084
Kate Stoneb9c1b512016-09-06 20:57:50 +000085TypeSystem *SymbolFile::GetTypeSystemForLanguage(lldb::LanguageType language) {
86 TypeSystem *type_system =
87 m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
88 if (type_system)
89 type_system->SetSymbolFile(this);
90 return type_system;
Greg Clayton8b4edba2015-08-14 20:02:05 +000091}
92
Kate Stoneb9c1b512016-09-06 20:57:50 +000093uint32_t SymbolFile::ResolveSymbolContext(const FileSpec &file_spec,
94 uint32_t line, bool check_inlines,
95 uint32_t resolve_scope,
96 SymbolContextList &sc_list) {
97 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +000098}
99
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100uint32_t SymbolFile::FindGlobalVariables(
101 const ConstString &name, const CompilerDeclContext *parent_decl_ctx,
102 bool append, uint32_t max_matches, VariableList &variables) {
103 if (!append)
104 variables.Clear();
105 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000106}
107
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108uint32_t SymbolFile::FindGlobalVariables(const RegularExpression &regex,
109 bool append, uint32_t max_matches,
110 VariableList &variables) {
111 if (!append)
112 variables.Clear();
113 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000114}
115
Kate Stoneb9c1b512016-09-06 20:57:50 +0000116uint32_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) {
121 if (!append)
122 sc_list.Clear();
123 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000124}
125
Kate Stoneb9c1b512016-09-06 20:57:50 +0000126uint32_t SymbolFile::FindFunctions(const RegularExpression &regex,
127 bool include_inlines, bool append,
128 SymbolContextList &sc_list) {
129 if (!append)
130 sc_list.Clear();
131 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000132}
133
Kate Stoneb9c1b512016-09-06 20:57:50 +0000134void SymbolFile::GetMangledNamesForFunction(
135 const std::string &scope_qualified_name,
136 std::vector<ConstString> &mangled_names) {
137 return;
Siva Chandra9293fc42016-01-07 23:32:34 +0000138}
139
Kate Stoneb9c1b512016-09-06 20:57:50 +0000140uint32_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,
145 TypeMap &types) {
146 if (!append)
147 types.Clear();
148 return 0;
Greg Clayton99558cc42015-08-24 23:46:31 +0000149}
150
Kate Stoneb9c1b512016-09-06 20:57:50 +0000151size_t SymbolFile::FindTypes(const std::vector<CompilerContext> &context,
152 bool append, TypeMap &types) {
153 if (!append)
154 types.Clear();
155 return 0;
Greg Claytone6b36cd2015-12-08 01:02:08 +0000156}