1 //===-- SymbolVendorELF.cpp ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "SymbolVendorELF.h"
14 #include "lldb/Core/Module.h"
15 #include "lldb/Core/ModuleSpec.h"
16 #include "lldb/Core/PluginManager.h"
17 #include "lldb/Core/Section.h"
18 #include "lldb/Core/StreamString.h"
19 #include "lldb/Core/Timer.h"
20 #include "lldb/Host/Host.h"
21 #include "lldb/Host/Symbols.h"
22 #include "lldb/Symbol/ObjectFile.h"
25 using namespace lldb_private;
27 //----------------------------------------------------------------------
28 // SymbolVendorELF constructor
29 //----------------------------------------------------------------------
30 SymbolVendorELF::SymbolVendorELF(const lldb::ModuleSP &module_sp) :
31 SymbolVendor (module_sp)
35 //----------------------------------------------------------------------
37 //----------------------------------------------------------------------
38 SymbolVendorELF::~SymbolVendorELF()
43 SymbolVendorELF::Initialize()
45 PluginManager::RegisterPlugin (GetPluginNameStatic(),
46 GetPluginDescriptionStatic(),
51 SymbolVendorELF::Terminate()
53 PluginManager::UnregisterPlugin (CreateInstance);
57 lldb_private::ConstString
58 SymbolVendorELF::GetPluginNameStatic()
60 static ConstString g_name("ELF");
65 SymbolVendorELF::GetPluginDescriptionStatic()
67 return "Symbol vendor for ELF that looks for dSYM files that match executables.";
72 //----------------------------------------------------------------------
75 // Platforms can register a callback to use when creating symbol
76 // vendors to allow for complex debug information file setups, and to
77 // also allow for finding separate debug information files.
78 //----------------------------------------------------------------------
80 SymbolVendorELF::CreateInstance (const lldb::ModuleSP &module_sp, lldb_private::Stream *feedback_strm)
85 ObjectFile *obj_file = module_sp->GetObjectFile();
89 static ConstString obj_file_elf("elf");
90 ConstString obj_name = obj_file->GetPluginName();
91 if (obj_name != obj_file_elf)
94 lldb_private::UUID uuid;
95 if (!obj_file->GetUUID (&uuid))
98 // Get the .gnu_debuglink file (if specified).
99 FileSpecList file_spec_list = obj_file->GetDebugSymbolFilePaths();
101 // If the module specified a filespec, use it first.
102 FileSpec debug_symbol_fspec (module_sp->GetSymbolFileFileSpec());
103 if (debug_symbol_fspec)
104 file_spec_list.Insert (0, debug_symbol_fspec);
106 // If we have no debug symbol files, then nothing to do.
107 if (file_spec_list.IsEmpty())
110 Timer scoped_timer (__PRETTY_FUNCTION__,
111 "SymbolVendorELF::CreateInstance (module = %s)",
112 module_sp->GetFileSpec().GetPath().c_str());
114 for (size_t idx = 0; idx < file_spec_list.GetSize(); ++idx)
116 ModuleSpec module_spec;
117 const FileSpec fspec = file_spec_list.GetFileSpecAtIndex (idx);
119 module_spec.GetFileSpec() = obj_file->GetFileSpec();
120 module_spec.GetFileSpec().ResolvePath();
121 module_spec.GetSymbolFileSpec() = fspec;
122 module_spec.GetUUID() = uuid;
123 FileSpec dsym_fspec = Symbols::LocateExecutableSymbolFile (module_spec);
126 DataBufferSP dsym_file_data_sp;
127 lldb::offset_t dsym_file_data_offset = 0;
128 ObjectFileSP dsym_objfile_sp = ObjectFile::FindPlugin(module_sp, &dsym_fspec, 0, dsym_fspec.GetByteSize(), dsym_file_data_sp, dsym_file_data_offset);
131 // This objfile is for debugging purposes. Sadly, ObjectFileELF won't be able
132 // to figure this out consistently as the symbol file may not have stripped the
133 // code sections, etc.
134 dsym_objfile_sp->SetType (ObjectFile::eTypeDebugInfo);
136 SymbolVendorELF* symbol_vendor = new SymbolVendorELF(module_sp);
139 // Get the module unified section list and add our debug sections to that.
140 SectionList *module_section_list = module_sp->GetSectionList();
141 SectionList *objfile_section_list = dsym_objfile_sp->GetSectionList();
143 static const SectionType g_sections[] =
145 eSectionTypeDWARFDebugAranges,
146 eSectionTypeDWARFDebugInfo,
147 eSectionTypeDWARFDebugAbbrev,
148 eSectionTypeDWARFDebugFrame,
149 eSectionTypeDWARFDebugLine,
150 eSectionTypeDWARFDebugStr,
151 eSectionTypeDWARFDebugLoc,
152 eSectionTypeDWARFDebugMacInfo,
153 eSectionTypeDWARFDebugPubNames,
154 eSectionTypeDWARFDebugPubTypes,
155 eSectionTypeDWARFDebugRanges,
156 eSectionTypeELFSymbolTable,
158 for (size_t idx = 0; idx < sizeof(g_sections) / sizeof(g_sections[0]); ++idx)
160 SectionType section_type = g_sections[idx];
161 SectionSP section_sp (objfile_section_list->FindSectionByType (section_type, true));
164 SectionSP module_section_sp (module_section_list->FindSectionByType (section_type, true));
165 if (module_section_sp)
166 module_section_list->ReplaceSection (module_section_sp->GetID(), section_sp);
168 module_section_list->AddSection (section_sp);
172 symbol_vendor->AddSymbolFileRepresentation (dsym_objfile_sp);
173 return symbol_vendor;
181 //------------------------------------------------------------------
182 // PluginInterface protocol
183 //------------------------------------------------------------------
185 SymbolVendorELF::GetPluginName()
187 return GetPluginNameStatic();
191 SymbolVendorELF::GetPluginVersion()