Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | #include "lldb/Symbol/SymbolFile.h" |
Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 11 | |
| 12 | #include "lldb/lldb-private.h" |
| 13 | #include "lldb/Core/Log.h" |
Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Module.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include "lldb/Core/PluginManager.h" |
Greg Clayton | c982b3d | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 16 | #include "lldb/Core/StreamString.h" |
Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 17 | #include "lldb/Symbol/ObjectFile.h" |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame^] | 18 | #include "lldb/Symbol/TypeList.h" |
| 19 | #include "lldb/Symbol/VariableList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace lldb_private; |
| 22 | |
| 23 | SymbolFile* |
| 24 | SymbolFile::FindPlugin (ObjectFile* obj_file) |
| 25 | { |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 26 | std::unique_ptr<SymbolFile> best_symfile_ap; |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 27 | if (obj_file != nullptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | { |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | uint32_t best_symfile_abilities = 0; |
| 49 | |
| 50 | SymbolFileCreateInstance create_callback; |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 51 | for (uint32_t idx = 0; (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(idx)) != nullptr; ++idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | { |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 53 | std::unique_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | |
| 55 | if (curr_symfile_ap.get()) |
| 56 | { |
Greg Clayton | 9efa076 | 2012-04-26 16:53:42 +0000 | [diff] [blame] | 57 | const uint32_t sym_file_abilities = curr_symfile_ap->GetAbilities(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | if (sym_file_abilities > best_symfile_abilities) |
| 59 | { |
| 60 | best_symfile_abilities = sym_file_abilities; |
Greg Clayton | e01e07b | 2013-04-18 18:10:51 +0000 | [diff] [blame] | 61 | best_symfile_ap.reset (curr_symfile_ap.release()); |
Greg Clayton | 9efa076 | 2012-04-26 16:53:42 +0000 | [diff] [blame] | 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; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 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 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 76 | return best_symfile_ap.release(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 79 | TypeList * |
| 80 | SymbolFile::GetTypeList () |
| 81 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 82 | if (m_obj_file) |
| 83 | return m_obj_file->GetModule()->GetTypeList(); |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 84 | return nullptr; |
Greg Clayton | 2d95dc9b | 2010-11-10 04:57:04 +0000 | [diff] [blame] | 85 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 86 | |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 87 | ClangASTContext & |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 88 | SymbolFile::GetClangASTContext () |
| 89 | { |
| 90 | return m_obj_file->GetModule()->GetClangASTContext(); |
| 91 | } |
Greg Clayton | 8b4edba | 2015-08-14 20:02:05 +0000 | [diff] [blame] | 92 | |
| 93 | TypeSystem * |
| 94 | SymbolFile::GetTypeSystemForLanguage (lldb::LanguageType language) |
| 95 | { |
| 96 | return m_obj_file->GetModule()->GetTypeSystemForLanguage (language); |
| 97 | } |
| 98 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame^] | 99 | uint32_t |
| 100 | SymbolFile::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 | |
| 107 | uint32_t |
| 108 | SymbolFile::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 | |
| 116 | uint32_t |
| 117 | SymbolFile::FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables) |
| 118 | { |
| 119 | if (!append) |
| 120 | variables.Clear(); |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | uint32_t |
| 125 | SymbolFile::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 | |
| 132 | uint32_t |
| 133 | SymbolFile::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 | |
| 140 | uint32_t |
| 141 | SymbolFile::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 | |