blob: 808830e1f1559756ff2e70925e335653d176a479 [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"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018
19using namespace lldb_private;
20
21SymbolFile*
22SymbolFile::FindPlugin (ObjectFile* obj_file)
23{
Greg Clayton6beaaa62011-01-17 03:46:26 +000024 std::auto_ptr<SymbolFile> best_symfile_ap;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025 if (obj_file != NULL)
26 {
27 // TODO: Load any plug-ins in the appropriate plug-in search paths and
28 // iterate over all of them to find the best one for the job.
29
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030 uint32_t best_symfile_abilities = 0;
31
32 SymbolFileCreateInstance create_callback;
33 for (uint32_t idx = 0; (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(idx)) != NULL; ++idx)
34 {
35 std::auto_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file));
36
37 if (curr_symfile_ap.get())
38 {
Greg Clayton9efa0762012-04-26 16:53:42 +000039 const uint32_t sym_file_abilities = curr_symfile_ap->GetAbilities();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040 if (sym_file_abilities > best_symfile_abilities)
41 {
42 best_symfile_abilities = sym_file_abilities;
Greg Clayton6beaaa62011-01-17 03:46:26 +000043 best_symfile_ap = curr_symfile_ap;
Greg Clayton9efa0762012-04-26 16:53:42 +000044 // If any symbol file parser has all of the abilities, then
45 // we should just stop looking.
46 if ((kAllAbilities & sym_file_abilities) == kAllAbilities)
47 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048 }
49 }
50 }
Greg Clayton6beaaa62011-01-17 03:46:26 +000051 if (best_symfile_ap.get())
52 {
53 // Let the winning symbol file parser initialize itself more
54 // completely now that it has been chosen
55 best_symfile_ap->InitializeObject();
56 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057 }
Greg Clayton6beaaa62011-01-17 03:46:26 +000058 return best_symfile_ap.release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059}
60
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000061TypeList *
62SymbolFile::GetTypeList ()
63{
Greg Clayton6beaaa62011-01-17 03:46:26 +000064 if (m_obj_file)
65 return m_obj_file->GetModule()->GetTypeList();
66 return NULL;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000067}
Greg Clayton6beaaa62011-01-17 03:46:26 +000068
69lldb_private::ClangASTContext &
70SymbolFile::GetClangASTContext ()
71{
72 return m_obj_file->GetModule()->GetClangASTContext();
73}