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"
12 //#include <libxml/parser.h>
13 // #include <libxml/tree.h>
16 // #include <AvailabilityMacros.h>
18 #include "lldb/Core/Module.h"
19 #include "lldb/Core/ModuleSpec.h"
20 #include "lldb/Core/PluginManager.h"
21 #include "lldb/Core/Section.h"
22 #include "lldb/Core/StreamString.h"
23 #include "lldb/Core/Timer.h"
24 #include "lldb/Host/Host.h"
25 #include "lldb/Host/Symbols.h"
26 #include "lldb/Symbol/ObjectFile.h"
29 using namespace lldb_private;
31 //----------------------------------------------------------------------
32 // SymbolVendorELF constructor
33 //----------------------------------------------------------------------
34 SymbolVendorELF::SymbolVendorELF(const lldb::ModuleSP &module_sp) :
35 SymbolVendor (module_sp)
39 //----------------------------------------------------------------------
41 //----------------------------------------------------------------------
42 SymbolVendorELF::~SymbolVendorELF()
47 SymbolVendorELF::Initialize()
49 PluginManager::RegisterPlugin (GetPluginNameStatic(),
50 GetPluginDescriptionStatic(),
55 SymbolVendorELF::Terminate()
57 PluginManager::UnregisterPlugin (CreateInstance);
61 lldb_private::ConstString
62 SymbolVendorELF::GetPluginNameStatic()
64 static ConstString g_name("ELF");
69 SymbolVendorELF::GetPluginDescriptionStatic()
71 return "Symbol vendor for ELF that looks for dSYM files that match executables.";
76 //----------------------------------------------------------------------
79 // Platforms can register a callback to use when creating symbol
80 // vendors to allow for complex debug information file setups, and to
81 // also allow for finding separate debug information files.
82 //----------------------------------------------------------------------
84 SymbolVendorELF::CreateInstance (const lldb::ModuleSP &module_sp, lldb_private::Stream *feedback_strm)
89 ObjectFile *obj_file = module_sp->GetObjectFile();
93 static ConstString obj_file_elf("elf");
94 ConstString obj_name = obj_file->GetPluginName();
95 if (obj_name != obj_file_elf)
98 lldb_private::UUID uuid;
99 if (!obj_file->GetUUID (&uuid))
102 // Get the .gnu_debuglink file (if specified).
103 FileSpecList file_spec_list = obj_file->GetDebugSymbolFilePaths();
105 // If the module specified a filespec, use it first.
106 FileSpec debug_symbol_fspec (module_sp->GetSymbolFileFileSpec());
107 if (debug_symbol_fspec)
108 file_spec_list.Insert (0, debug_symbol_fspec);
110 // If we have no debug symbol files, then nothing to do.
111 if (file_spec_list.IsEmpty())
114 Timer scoped_timer (__PRETTY_FUNCTION__,
115 "SymbolVendorELF::CreateInstance (module = %s)",
116 module_sp->GetFileSpec().GetPath().c_str());
118 for (size_t idx = 0; idx < file_spec_list.GetSize(); ++idx)
120 ModuleSpec module_spec;
121 const FileSpec fspec = file_spec_list.GetFileSpecAtIndex (idx);
123 module_spec.GetFileSpec() = obj_file->GetFileSpec();
124 module_spec.GetFileSpec().ResolvePath();
125 module_spec.GetSymbolFileSpec() = fspec;
126 module_spec.GetUUID() = uuid;
127 FileSpec dsym_fspec = Symbols::LocateExecutableSymbolFile (module_spec);
130 DataBufferSP dsym_file_data_sp;
131 lldb::offset_t dsym_file_data_offset = 0;
132 ObjectFileSP dsym_objfile_sp = ObjectFile::FindPlugin(module_sp, &dsym_fspec, 0, dsym_fspec.GetByteSize(), dsym_file_data_sp, dsym_file_data_offset);
135 // This objfile is for debugging purposes. Sadly, ObjectFileELF won't be able
136 // to figure this out consistently as the symbol file may not have stripped the
137 // code sections, etc.
138 dsym_objfile_sp->SetType (ObjectFile::eTypeDebugInfo);
140 SymbolVendorELF* symbol_vendor = new SymbolVendorELF(module_sp);
143 // Get the module unified section list and add our debug sections to that.
144 SectionList *module_section_list = module_sp->GetSectionList();
145 SectionList *objfile_section_list = dsym_objfile_sp->GetSectionList();
147 static const SectionType g_sections[] =
149 eSectionTypeDWARFDebugAranges,
150 eSectionTypeDWARFDebugInfo,
151 eSectionTypeDWARFDebugAbbrev,
152 eSectionTypeDWARFDebugFrame,
153 eSectionTypeDWARFDebugLine,
154 eSectionTypeDWARFDebugStr,
155 eSectionTypeDWARFDebugLoc,
156 eSectionTypeDWARFDebugMacInfo,
157 eSectionTypeDWARFDebugPubNames,
158 eSectionTypeDWARFDebugPubTypes,
159 eSectionTypeDWARFDebugRanges,
160 eSectionTypeELFSymbolTable,
162 for (size_t idx = 0; idx < sizeof(g_sections) / sizeof(g_sections[0]); ++idx)
164 SectionType section_type = g_sections[idx];
165 SectionSP section_sp (objfile_section_list->FindSectionByType (section_type, true));
168 SectionSP module_section_sp (module_section_list->FindSectionByType (section_type, true));
169 if (module_section_sp)
170 module_section_list->ReplaceSection (module_section_sp->GetID(), section_sp);
172 module_section_list->AddSection (section_sp);
176 symbol_vendor->AddSymbolFileRepresentation (dsym_objfile_sp);
177 return symbol_vendor;
185 //------------------------------------------------------------------
186 // PluginInterface protocol
187 //------------------------------------------------------------------
189 SymbolVendorELF::GetPluginName()
191 return GetPluginNameStatic();
195 SymbolVendorELF::GetPluginVersion()