blob: 5486468181fae18540949b4ab534097e67f95c03 [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"
Ravitheja Addepally40697302015-10-08 09:45:41 +000018#include "lldb/Symbol/TypeMap.h"
Greg Clayton56939cb2015-09-17 22:23:34 +000019#include "lldb/Symbol/TypeSystem.h"
Greg Clayton99558cc42015-08-24 23:46:31 +000020#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
22using namespace lldb_private;
23
24SymbolFile*
25SymbolFile::FindPlugin (ObjectFile* obj_file)
26{
Greg Clayton7b0992d2013-04-18 22:45:39 +000027 std::unique_ptr<SymbolFile> best_symfile_ap;
Ed Masted4612ad2014-04-20 13:17:36 +000028 if (obj_file != nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029 {
Greg Clayton3046e662013-07-10 01:23:25 +000030
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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046 // 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049 uint32_t best_symfile_abilities = 0;
50
51 SymbolFileCreateInstance create_callback;
Ed Masted4612ad2014-04-20 13:17:36 +000052 for (uint32_t idx = 0; (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(idx)) != nullptr; ++idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053 {
Greg Clayton7b0992d2013-04-18 22:45:39 +000054 std::unique_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file));
Chris Lattner30fdc8d2010-06-08 16:52:24 +000055
56 if (curr_symfile_ap.get())
57 {
Greg Clayton9efa0762012-04-26 16:53:42 +000058 const uint32_t sym_file_abilities = curr_symfile_ap->GetAbilities();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059 if (sym_file_abilities > best_symfile_abilities)
60 {
61 best_symfile_abilities = sym_file_abilities;
Greg Claytone01e07b2013-04-18 18:10:51 +000062 best_symfile_ap.reset (curr_symfile_ap.release());
Greg Clayton9efa0762012-04-26 16:53:42 +000063 // 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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067 }
68 }
69 }
Greg Clayton6beaaa62011-01-17 03:46:26 +000070 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 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076 }
Greg Clayton6beaaa62011-01-17 03:46:26 +000077 return best_symfile_ap.release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000078}
79
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000080TypeList *
81SymbolFile::GetTypeList ()
82{
Greg Clayton6beaaa62011-01-17 03:46:26 +000083 if (m_obj_file)
84 return m_obj_file->GetModule()->GetTypeList();
Ed Masted4612ad2014-04-20 13:17:36 +000085 return nullptr;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000086}
Greg Clayton6beaaa62011-01-17 03:46:26 +000087
Greg Clayton8b4edba2015-08-14 20:02:05 +000088TypeSystem *
89SymbolFile::GetTypeSystemForLanguage (lldb::LanguageType language)
90{
Ryan Brown57bee1e2015-09-14 22:45:11 +000091 TypeSystem *type_system = m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
92 if (type_system)
93 type_system->SetSymbolFile(this);
94 return type_system;
Greg Clayton8b4edba2015-08-14 20:02:05 +000095}
96
Greg Clayton99558cc42015-08-24 23:46:31 +000097uint32_t
98SymbolFile::ResolveSymbolContext (const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
99{
Greg Clayton99558cc42015-08-24 23:46:31 +0000100 return 0;
101}
102
103
104uint32_t
105SymbolFile::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
113uint32_t
114SymbolFile::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
115{
116 if (!append)
117 variables.Clear();
118 return 0;
119}
120
121uint32_t
122SymbolFile::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
129uint32_t
130SymbolFile::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
137uint32_t
Ravitheja Addepally40697302015-10-08 09:45:41 +0000138SymbolFile::FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, TypeMap& types)
Greg Clayton99558cc42015-08-24 23:46:31 +0000139{
140 if (!append)
141 types.Clear();
142 return 0;
143}
144