blob: a5b138bb52afb1aa8e962e6d7f09a82470a87cac [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 Clayton7b0992d2013-04-18 22:45:39 +000024 std::unique_ptr<SymbolFile> best_symfile_ap;
Ed Masted4612ad2014-04-20 13:17:36 +000025 if (obj_file != nullptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026 {
Greg Clayton3046e662013-07-10 01:23:25 +000027
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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043 // 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000046 uint32_t best_symfile_abilities = 0;
47
48 SymbolFileCreateInstance create_callback;
Ed Masted4612ad2014-04-20 13:17:36 +000049 for (uint32_t idx = 0; (create_callback = PluginManager::GetSymbolFileCreateCallbackAtIndex(idx)) != nullptr; ++idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050 {
Greg Clayton7b0992d2013-04-18 22:45:39 +000051 std::unique_ptr<SymbolFile> curr_symfile_ap(create_callback(obj_file));
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052
53 if (curr_symfile_ap.get())
54 {
Greg Clayton9efa0762012-04-26 16:53:42 +000055 const uint32_t sym_file_abilities = curr_symfile_ap->GetAbilities();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056 if (sym_file_abilities > best_symfile_abilities)
57 {
58 best_symfile_abilities = sym_file_abilities;
Greg Claytone01e07b2013-04-18 18:10:51 +000059 best_symfile_ap.reset (curr_symfile_ap.release());
Greg Clayton9efa0762012-04-26 16:53:42 +000060 // 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;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064 }
65 }
66 }
Greg Clayton6beaaa62011-01-17 03:46:26 +000067 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 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073 }
Greg Clayton6beaaa62011-01-17 03:46:26 +000074 return best_symfile_ap.release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000075}
76
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000077TypeList *
78SymbolFile::GetTypeList ()
79{
Greg Clayton6beaaa62011-01-17 03:46:26 +000080 if (m_obj_file)
81 return m_obj_file->GetModule()->GetTypeList();
Ed Masted4612ad2014-04-20 13:17:36 +000082 return nullptr;
Greg Clayton2d95dc9b2010-11-10 04:57:04 +000083}
Greg Clayton6beaaa62011-01-17 03:46:26 +000084
85lldb_private::ClangASTContext &
86SymbolFile::GetClangASTContext ()
87{
88 return m_obj_file->GetModule()->GetClangASTContext();
89}