Home | History | Annotate | Download | only in Symbol
      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 
     10 #include "lldb/Symbol/SymbolFile.h"
     11 
     12 #include "lldb/lldb-private.h"
     13 #include "lldb/Core/Log.h"
     14 #include "lldb/Core/Module.h"
     15 #include "lldb/Core/PluginManager.h"
     16 #include "lldb/Core/StreamString.h"
     17 #include "lldb/Symbol/ObjectFile.h"
     18 
     19 using namespace lldb_private;
     20 
     21 SymbolFile*
     22 SymbolFile::FindPlugin (ObjectFile* obj_file)
     23 {
     24     std::unique_ptr<SymbolFile> best_symfile_ap;
     25     if (obj_file != NULL)
     26     {
     27 
     28         // We need to test the abilities of this section list. So create what it would
     29         // be with this new obj_file.
     30         lldb::ModuleSP module_sp(obj_file->GetModule());
     31         if (module_sp)
     32         {
     33             // Default to the main module section list.
     34             ObjectFile *module_obj_file = module_sp->GetObjectFile();
     35             if (module_obj_file != obj_file)
     36             {
     37                 // Make sure the main object file's sections are created
     38                 module_obj_file->GetSectionList();
     39                 obj_file->CreateSections (*module_sp->GetUnifiedSectionList());
     40             }
     41         }
     42 
     43         // TODO: Load any plug-ins in the appropriate plug-in search paths and
     44         // iterate over all of them to find the best one for the job.
     45 
     46         uint32_t best_symfile_abilities = 0;
     47 
     48         SymbolFileCreateInstance create_callback;
     49         for (uint32_t idx = 0; (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(idx)) != NULL; ++idx)
     50         {
     51             std::unique_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file));
     52 
     53             if (curr_symfile_ap.get())
     54             {
     55                 const uint32_t sym_file_abilities = curr_symfile_ap->GetAbilities();
     56                 if (sym_file_abilities > best_symfile_abilities)
     57                 {
     58                     best_symfile_abilities = sym_file_abilities;
     59                     best_symfile_ap.reset (curr_symfile_ap.release());
     60                     // If any symbol file parser has all of the abilities, then
     61                     // we should just stop looking.
     62                     if ((kAllAbilities & sym_file_abilities) == kAllAbilities)
     63                         break;
     64                 }
     65             }
     66         }
     67         if (best_symfile_ap.get())
     68         {
     69             // Let the winning symbol file parser initialize itself more
     70             // completely now that it has been chosen
     71             best_symfile_ap->InitializeObject();
     72         }
     73     }
     74     return best_symfile_ap.release();
     75 }
     76 
     77 TypeList *
     78 SymbolFile::GetTypeList ()
     79 {
     80     if (m_obj_file)
     81         return m_obj_file->GetModule()->GetTypeList();
     82     return NULL;
     83 }
     84 
     85 lldb_private::ClangASTContext &
     86 SymbolFile::GetClangASTContext ()
     87 {
     88     return m_obj_file->GetModule()->GetClangASTContext();
     89 }
     90