blob: 357cfbcd131c532297bef7763636a73d8bb2bd14 [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
12#include "lldb/lldb-private.h"
13#include "lldb/Core/Log.h"
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000014#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015#include "lldb/Core/PluginManager.h"
Greg Claytonc982b3d2011-11-28 01:45:00 +000016#include "lldb/Core/StreamString.h"
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000017#include "lldb/Symbol/ObjectFile.h"
Greg Clayton99558cc42015-08-24 23:46:31 +000018#include "lldb/Symbol/TypeList.h"
19#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
21using namespace lldb_private;
22
23SymbolFile*
24SymbolFile::FindPlugin (ObjectFile* obj_file)
25{
Greg Clayton7b0992d2013-04-18 22:45:39 +000026 std::unique_ptr<SymbolFile> best_symfile_ap;
Ed Masted4612ad2014-04-20 13:17:36 +000027 if (obj_file != nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028 {
Greg Clayton3046e662013-07-10 01:23:25 +000029
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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045 // 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048 uint32_t best_symfile_abilities = 0;
49
50 SymbolFileCreateInstance create_callback;
Ed Masted4612ad2014-04-20 13:17:36 +000051 for (uint32_t idx = 0; (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(idx)) != nullptr; ++idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052 {
Greg Clayton7b0992d2013-04-18 22:45:39 +000053 std::unique_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file));
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054
55 if (curr_symfile_ap.get())
56 {
Greg Clayton9efa0762012-04-26 16:53:42 +000057 const uint32_t sym_file_abilities = curr_symfile_ap->GetAbilities();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058 if (sym_file_abilities > best_symfile_abilities)
59 {
60 best_symfile_abilities = sym_file_abilities;
Greg Claytone01e07b2013-04-18 18:10:51 +000061 best_symfile_ap.reset (curr_symfile_ap.release());
Greg Clayton9efa0762012-04-26 16:53:42 +000062 // 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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066 }
67 }
68 }
Greg Clayton6beaaa62011-01-17 03:46:26 +000069 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 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075 }
Greg Clayton6beaaa62011-01-17 03:46:26 +000076 return best_symfile_ap.release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077}
78
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000079TypeList *
80SymbolFile::GetTypeList ()
81{
Greg Clayton6beaaa62011-01-17 03:46:26 +000082 if (m_obj_file)
83 return m_obj_file->GetModule()->GetTypeList();
Ed Masted4612ad2014-04-20 13:17:36 +000084 return nullptr;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000085}
Greg Clayton6beaaa62011-01-17 03:46:26 +000086
Greg Clayton8b4edba2015-08-14 20:02:05 +000087ClangASTContext &
Greg Clayton6beaaa62011-01-17 03:46:26 +000088SymbolFile::GetClangASTContext ()
89{
90 return m_obj_file->GetModule()->GetClangASTContext();
91}
Greg Clayton8b4edba2015-08-14 20:02:05 +000092
93TypeSystem *
94SymbolFile::GetTypeSystemForLanguage (lldb::LanguageType language)
95{
96 return m_obj_file->GetModule()->GetTypeSystemForLanguage (language);
97}
98
Greg Clayton99558cc42015-08-24 23:46:31 +000099uint32_t
100SymbolFile::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
101{
102 sc_list.Clear();
103 return 0;
104}
105
106
107uint32_t
108SymbolFile::FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, VariableList& variables)
109{
110 if (!append)
111 variables.Clear();
112 return 0;
113}
114
115
116uint32_t
117SymbolFile::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
118{
119 if (!append)
120 variables.Clear();
121 return 0;
122}
123
124uint32_t
125SymbolFile::FindFunctions (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list)
126{
127 if (!append)
128 sc_list.Clear();
129 return 0;
130}
131
132uint32_t
133SymbolFile::FindFunctions (const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
134{
135 if (!append)
136 sc_list.Clear();
137 return 0;
138}
139
140uint32_t
141SymbolFile::FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, TypeList& types)
142{
143 if (!append)
144 types.Clear();
145 return 0;
146}
147