LLDB mainline
SymbolVendorELF.cpp
Go to the documentation of this file.
1//===-- SymbolVendorELF.cpp -----------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#include "SymbolVendorELF.h"
10
11#include <cstring>
12
14#include "lldb/Core/Module.h"
17#include "lldb/Core/Section.h"
18#include "lldb/Host/Host.h"
21#include "lldb/Target/Target.h"
23#include "lldb/Utility/Timer.h"
24
25using namespace lldb;
26using namespace lldb_private;
27
29
30// SymbolVendorELF constructor
31SymbolVendorELF::SymbolVendorELF(const lldb::ModuleSP &module_sp)
32 : SymbolVendor(module_sp) {}
33
37}
38
41}
42
44 return "Symbol vendor for ELF that looks for dSYM files that match "
45 "executables.";
46}
47
48// CreateInstance
49//
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.
54SymbolVendorELF::CreateInstance(const lldb::ModuleSP &module_sp,
55 lldb_private::Stream *feedback_strm) {
56 if (!module_sp)
57 return nullptr;
58
59 ObjectFileELF *obj_file =
60 llvm::dyn_cast_or_null<ObjectFileELF>(module_sp->GetObjectFile());
61 if (!obj_file)
62 return nullptr;
63
64 lldb_private::UUID uuid = obj_file->GetUUID();
65 if (!uuid)
66 return nullptr;
67
68 // If the main object file already contains debug info, then we are done.
69 if (obj_file->GetSectionList()->FindSectionByType(
71 return nullptr;
72
73 // If the module specified a filespec, use that.
74 FileSpec fspec = module_sp->GetSymbolFileFileSpec();
75 // Otherwise, try gnu_debuglink, if one exists.
76 if (!fspec)
77 fspec = obj_file->GetDebugLink().value_or(FileSpec());
78
79 LLDB_SCOPED_TIMERF("SymbolVendorELF::CreateInstance (module = %s)",
80 module_sp->GetFileSpec().GetPath().c_str());
81
82 ModuleSpec module_spec;
83
84 module_spec.GetFileSpec() = obj_file->GetFileSpec();
86 module_spec.GetSymbolFileSpec() = fspec;
87 module_spec.GetUUID() = uuid;
89 FileSpec dsym_fspec =
90 Symbols::LocateExecutableSymbolFile(module_spec, search_paths);
91 if (!dsym_fspec)
92 return nullptr;
93
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);
99 if (!dsym_objfile_sp)
100 return nullptr;
101
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);
106
107 SymbolVendorELF *symbol_vendor = new SymbolVendorELF(module_sp);
108
109 // Get the module unified section list and add our debug sections to
110 // that.
111 SectionList *module_section_list = module_sp->GetSectionList();
112 SectionList *objfile_section_list = dsym_objfile_sp->GetSectionList();
113
114 if (!module_section_list || !objfile_section_list)
115 return nullptr;
116
117 static const SectionType g_sections[] = {
129 };
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(),
136 section_sp);
137 else
138 module_section_list->AddSection(section_sp);
139 }
140 }
141
142 symbol_vendor->AddSymbolFileRepresentation(dsym_objfile_sp);
143 return symbol_vendor;
144}
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
#define LLDB_SCOPED_TIMERF(...)
Definition: Timer.h:86
Generic COFF object file reader.
Definition: ObjectFileELF.h:58
std::optional< lldb_private::FileSpec > GetDebugLink()
Return the contents of the .gnu_debuglink section, if the object file contains it.
lldb_private::UUID GetUUID() override
Gets the UUID for this object file.
static llvm::StringRef GetPluginDescriptionStatic()
static void Initialize()
static void Terminate()
static lldb_private::SymbolVendor * CreateInstance(const lldb::ModuleSP &module_sp, lldb_private::Stream *feedback_strm)
static llvm::StringRef GetPluginNameStatic()
A file collection class.
Definition: FileSpecList.h:24
A file utility class.
Definition: FileSpec.h:56
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
static FileSystem & Instance()
FileSpec & GetFileSpec()
Definition: ModuleSpec.h:53
FileSpec & GetSymbolFileSpec()
Definition: ModuleSpec.h:77
static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataBufferSP &data_sp, lldb::offset_t &data_offset)
Find a ObjectFile plug-in that can parse file_spec.
@ eTypeDebugInfo
An object file that contains only debug information.
Definition: ObjectFile.h:54
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition: ObjectFile.h:273
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
Definition: ObjectFile.cpp:588
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
size_t AddSection(const lldb::SectionSP &section_sp)
Definition: Section.cpp:469
bool ReplaceSection(lldb::user_id_t sect_id, const lldb::SectionSP &section_sp, uint32_t depth=UINT32_MAX)
Definition: Section.cpp:509
lldb::SectionSP FindSectionByType(lldb::SectionType sect_type, bool check_children, size_t start_idx=0) const
Definition: Section.cpp:586
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
void AddSymbolFileRepresentation(const lldb::ObjectFileSP &objfile_sp)
static FileSpec LocateExecutableSymbolFile(const ModuleSpec &module_spec, const FileSpecList &default_search_paths)
static FileSpecList GetDefaultDebugFileSearchPaths()
Definition: Target.cpp:2524
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
uint64_t offset_t
Definition: lldb-types.h:83
@ eSectionTypeDWARFDebugStrOffsets
@ eSectionTypeDWARFDebugPubNames
@ eSectionTypeDWARFDebugFrame
@ eSectionTypeDWARFDebugLocLists
DWARF v5 .debug_loclists.
@ eSectionTypeDWARFDebugTypes
DWARF .debug_types section.
@ eSectionTypeDWARFDebugMacInfo
@ eSectionTypeDWARFDebugNames
DWARF v5 .debug_names.
@ eSectionTypeDWARFDebugRngLists
DWARF v5 .debug_rnglists.
@ eSectionTypeDWARFDebugMacro
@ eSectionTypeDWARFDebugInfo
@ eSectionTypeDWARFDebugRanges
@ eSectionTypeDWARFDebugLine
@ eSectionTypeDWARFDebugPubTypes
@ eSectionTypeDWARFDebugStr
@ eSectionTypeDWARFDebugLineStr
DWARF v5 .debug_line_str.
@ eSectionTypeDWARFDebugLoc
@ eSectionTypeDWARFDebugCuIndex
@ eSectionTypeDWARFDebugAranges
@ eSectionTypeDWARFGNUDebugAltLink
@ eSectionTypeDWARFDebugAbbrev
@ eSectionTypeDWARFDebugAddr
@ eSectionTypeELFSymbolTable
Elf SHT_SYMTAB section.