1254721Semaste//===-- SymbolFile.cpp ------------------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#include "lldb/Symbol/SymbolFile.h" 11254721Semaste 12254721Semaste#include "lldb/lldb-private.h" 13254721Semaste#include "lldb/Core/Log.h" 14254721Semaste#include "lldb/Core/Module.h" 15254721Semaste#include "lldb/Core/PluginManager.h" 16254721Semaste#include "lldb/Core/StreamString.h" 17254721Semaste#include "lldb/Symbol/ObjectFile.h" 18254721Semaste 19254721Semasteusing namespace lldb_private; 20254721Semaste 21254721SemasteSymbolFile* 22254721SemasteSymbolFile::FindPlugin (ObjectFile* obj_file) 23254721Semaste{ 24254721Semaste std::unique_ptr<SymbolFile> best_symfile_ap; 25254721Semaste if (obj_file != NULL) 26254721Semaste { 27254721Semaste 28254721Semaste // We need to test the abilities of this section list. So create what it would 29254721Semaste // be with this new obj_file. 30254721Semaste lldb::ModuleSP module_sp(obj_file->GetModule()); 31254721Semaste if (module_sp) 32254721Semaste { 33254721Semaste // Default to the main module section list. 34254721Semaste ObjectFile *module_obj_file = module_sp->GetObjectFile(); 35254721Semaste if (module_obj_file != obj_file) 36254721Semaste { 37254721Semaste // Make sure the main object file's sections are created 38254721Semaste module_obj_file->GetSectionList(); 39254721Semaste obj_file->CreateSections (*module_sp->GetUnifiedSectionList()); 40254721Semaste } 41254721Semaste } 42254721Semaste 43254721Semaste // TODO: Load any plug-ins in the appropriate plug-in search paths and 44254721Semaste // iterate over all of them to find the best one for the job. 45254721Semaste 46254721Semaste uint32_t best_symfile_abilities = 0; 47254721Semaste 48254721Semaste SymbolFileCreateInstance create_callback; 49254721Semaste for (uint32_t idx = 0; (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(idx)) != NULL; ++idx) 50254721Semaste { 51254721Semaste std::unique_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file)); 52254721Semaste 53254721Semaste if (curr_symfile_ap.get()) 54254721Semaste { 55254721Semaste const uint32_t sym_file_abilities = curr_symfile_ap->GetAbilities(); 56254721Semaste if (sym_file_abilities > best_symfile_abilities) 57254721Semaste { 58254721Semaste best_symfile_abilities = sym_file_abilities; 59254721Semaste best_symfile_ap.reset (curr_symfile_ap.release()); 60254721Semaste // If any symbol file parser has all of the abilities, then 61254721Semaste // we should just stop looking. 62254721Semaste if ((kAllAbilities & sym_file_abilities) == kAllAbilities) 63254721Semaste break; 64254721Semaste } 65254721Semaste } 66254721Semaste } 67254721Semaste if (best_symfile_ap.get()) 68254721Semaste { 69254721Semaste // Let the winning symbol file parser initialize itself more 70254721Semaste // completely now that it has been chosen 71254721Semaste best_symfile_ap->InitializeObject(); 72254721Semaste } 73254721Semaste } 74254721Semaste return best_symfile_ap.release(); 75254721Semaste} 76254721Semaste 77254721SemasteTypeList * 78254721SemasteSymbolFile::GetTypeList () 79254721Semaste{ 80254721Semaste if (m_obj_file) 81254721Semaste return m_obj_file->GetModule()->GetTypeList(); 82254721Semaste return NULL; 83254721Semaste} 84254721Semaste 85254721Semastelldb_private::ClangASTContext & 86254721SemasteSymbolFile::GetClangASTContext () 87254721Semaste{ 88254721Semaste return m_obj_file->GetModule()->GetClangASTContext(); 89254721Semaste} 90