1 //===-- SymbolVendorELF.cpp -----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "SymbolVendorELF.h"
13 #include "Plugins/ObjectFile/ELF/ObjectFileELF.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/Host/Host.h"
19 #include "lldb/Symbol/LocateSymbolFile.h"
20 #include "lldb/Symbol/ObjectFile.h"
21 #include "lldb/Target/Target.h"
22 #include "lldb/Utility/StreamString.h"
23 #include "lldb/Utility/Timer.h"
26 using namespace lldb_private
;
28 LLDB_PLUGIN_DEFINE(SymbolVendorELF
)
30 // SymbolVendorELF constructor
31 SymbolVendorELF::SymbolVendorELF(const lldb::ModuleSP
&module_sp
)
32 : SymbolVendor(module_sp
) {}
34 void SymbolVendorELF::Initialize() {
35 PluginManager::RegisterPlugin(GetPluginNameStatic(),
36 GetPluginDescriptionStatic(), CreateInstance
);
39 void SymbolVendorELF::Terminate() {
40 PluginManager::UnregisterPlugin(CreateInstance
);
43 llvm::StringRef
SymbolVendorELF::GetPluginDescriptionStatic() {
44 return "Symbol vendor for ELF that looks for dSYM files that match "
50 // Platforms can register a callback to use when creating symbol vendors to
51 // allow for complex debug information file setups, and to also allow for
52 // finding separate debug information files.
54 SymbolVendorELF::CreateInstance(const lldb::ModuleSP
&module_sp
,
55 lldb_private::Stream
*feedback_strm
) {
59 ObjectFileELF
*obj_file
=
60 llvm::dyn_cast_or_null
<ObjectFileELF
>(module_sp
->GetObjectFile());
64 lldb_private::UUID uuid
= obj_file
->GetUUID();
68 // If the main object file already contains debug info, then we are done.
69 if (obj_file
->GetSectionList()->FindSectionByType(
70 lldb::eSectionTypeDWARFDebugInfo
, true))
73 // If the module specified a filespec, use that.
74 FileSpec fspec
= module_sp
->GetSymbolFileFileSpec();
75 // Otherwise, try gnu_debuglink, if one exists.
77 fspec
= obj_file
->GetDebugLink().value_or(FileSpec());
79 LLDB_SCOPED_TIMERF("SymbolVendorELF::CreateInstance (module = %s)",
80 module_sp
->GetFileSpec().GetPath().c_str());
82 ModuleSpec module_spec
;
84 module_spec
.GetFileSpec() = obj_file
->GetFileSpec();
85 FileSystem::Instance().Resolve(module_spec
.GetFileSpec());
86 module_spec
.GetSymbolFileSpec() = fspec
;
87 module_spec
.GetUUID() = uuid
;
88 FileSpecList search_paths
= Target::GetDefaultDebugFileSearchPaths();
90 Symbols::LocateExecutableSymbolFile(module_spec
, search_paths
);
94 DataBufferSP dsym_file_data_sp
;
95 lldb::offset_t dsym_file_data_offset
= 0;
96 ObjectFileSP dsym_objfile_sp
= ObjectFile::FindPlugin(
97 module_sp
, &dsym_fspec
, 0, FileSystem::Instance().GetByteSize(dsym_fspec
),
98 dsym_file_data_sp
, dsym_file_data_offset
);
102 // This objfile is for debugging purposes. Sadly, ObjectFileELF won't
103 // be able to figure this out consistently as the symbol file may not
104 // have stripped the code sections, etc.
105 dsym_objfile_sp
->SetType(ObjectFile::eTypeDebugInfo
);
107 SymbolVendorELF
*symbol_vendor
= new SymbolVendorELF(module_sp
);
109 // Get the module unified section list and add our debug sections to
111 SectionList
*module_section_list
= module_sp
->GetSectionList();
112 SectionList
*objfile_section_list
= dsym_objfile_sp
->GetSectionList();
114 if (!module_section_list
|| !objfile_section_list
)
117 static const SectionType g_sections
[] = {
118 eSectionTypeDWARFDebugAbbrev
, eSectionTypeDWARFDebugAddr
,
119 eSectionTypeDWARFDebugAranges
, eSectionTypeDWARFDebugCuIndex
,
120 eSectionTypeDWARFDebugFrame
, eSectionTypeDWARFDebugInfo
,
121 eSectionTypeDWARFDebugLine
, eSectionTypeDWARFDebugLineStr
,
122 eSectionTypeDWARFDebugLoc
, eSectionTypeDWARFDebugLocLists
,
123 eSectionTypeDWARFDebugMacInfo
, eSectionTypeDWARFDebugMacro
,
124 eSectionTypeDWARFDebugNames
, eSectionTypeDWARFDebugPubNames
,
125 eSectionTypeDWARFDebugPubTypes
, eSectionTypeDWARFDebugRanges
,
126 eSectionTypeDWARFDebugRngLists
, eSectionTypeDWARFDebugStr
,
127 eSectionTypeDWARFDebugStrOffsets
, eSectionTypeDWARFDebugTypes
,
128 eSectionTypeELFSymbolTable
, eSectionTypeDWARFGNUDebugAltLink
,
130 for (SectionType section_type
: g_sections
) {
131 if (SectionSP section_sp
=
132 objfile_section_list
->FindSectionByType(section_type
, true)) {
133 if (SectionSP module_section_sp
=
134 module_section_list
->FindSectionByType(section_type
, true))
135 module_section_list
->ReplaceSection(module_section_sp
->GetID(),
138 module_section_list
->AddSection(section_sp
);
142 symbol_vendor
->AddSymbolFileRepresentation(dsym_objfile_sp
);
143 return symbol_vendor
;