LLDB mainline
SymbolVendorPECOFF.cpp
Go to the documentation of this file.
1//===-- SymbolVendorPECOFF.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
10
11#include <cstring>
12
14#include "lldb/Core/Module.h"
17#include "lldb/Core/Section.h"
18#include "lldb/Host/Host.h"
20#include "lldb/Target/Target.h"
22#include "lldb/Utility/Timer.h"
23
24using namespace lldb;
25using namespace lldb_private;
26
28
29// SymbolVendorPECOFF constructor
31 : SymbolVendor(module_sp) {}
32
37
41
43 return "Symbol vendor for PE/COFF that looks for dSYM files that match "
44 "executables.";
45}
46
47// CreateInstance
48//
49// Platforms can register a callback to use when creating symbol vendors to
50// allow for complex debug information file setups, and to also allow for
51// finding separate debug information files.
54 lldb_private::Stream *feedback_strm) {
55 if (!module_sp)
56 return nullptr;
57
58 ObjectFilePECOFF *obj_file =
59 llvm::dyn_cast_or_null<ObjectFilePECOFF>(module_sp->GetObjectFile());
60 if (!obj_file)
61 return nullptr;
62
63 lldb_private::UUID uuid = obj_file->GetUUID();
64 if (!uuid)
65 return nullptr;
66
67 // If the main object file already contains debug info, then we are done.
68 if (obj_file->GetSectionList()->FindSectionByType(
70 return nullptr;
71
72 // Otherwise, we try to locate it.
74
75 // If the module specified a filespec, use that.
76 FileSpec fspec = module_sp->GetSymbolFileFileSpec();
77 // Otherwise, if this is CodeView, use the PDB path and set the module
78 // directory as the first fallback lookup location.
79 if (!fspec) {
80 if (auto pdb_spec = obj_file->GetPDBPath()) {
81 fspec = *pdb_spec;
82 if (ConstString dir = obj_file->GetFileSpec().GetDirectory())
83 search_paths.Insert(0, FileSpec(dir));
84 }
85 }
86 // Otherwise, try gnu_debuglink, if one exists.
87 if (!fspec)
88 fspec = obj_file->GetDebugLink().value_or(FileSpec());
89
90 LLDB_SCOPED_TIMERF("SymbolVendorPECOFF::CreateInstance (module = %s)",
91 module_sp->GetFileSpec().GetPath().c_str());
92
93 ModuleSpec module_spec;
94
95 module_spec.GetFileSpec() = obj_file->GetFileSpec();
97 module_spec.GetSymbolFileSpec() = fspec;
98 module_spec.GetUUID() = uuid;
100 module_spec, search_paths, module_sp->GetSymbolLocatorStatistics());
101 if (!dsym_fspec)
102 return nullptr;
103
104 DataExtractorSP dsym_file_extractor_sp;
105 lldb::offset_t dsym_file_data_offset = 0;
106 ObjectFileSP dsym_objfile_sp = ObjectFile::FindPlugin(
107 module_sp, &dsym_fspec, 0, FileSystem::Instance().GetByteSize(dsym_fspec),
108 dsym_file_extractor_sp, dsym_file_data_offset);
109 if (!dsym_objfile_sp)
110 return nullptr;
111
112 // This objfile is for debugging purposes.
113 dsym_objfile_sp->SetType(ObjectFile::eTypeDebugInfo);
114
115 // For DWARF get the module unified section list and add our debug sections
116 // to that.
117 SectionList *module_section_list = module_sp->GetSectionList();
118 SectionList *objfile_section_list = dsym_objfile_sp->GetSectionList();
119 if (objfile_section_list && module_section_list) {
120 static const SectionType g_sections[] = {
128 };
129 for (SectionType section_type : g_sections) {
130 if (SectionSP section_sp =
131 objfile_section_list->FindSectionByType(section_type, true)) {
132 if (SectionSP module_section_sp =
133 module_section_list->FindSectionByType(section_type, true))
134 module_section_list->ReplaceSection(module_section_sp->GetID(),
135 section_sp);
136 else
137 module_section_list->AddSection(section_sp);
138 }
139 }
140 }
141
142 SymbolVendorPECOFF *symbol_vendor = new SymbolVendorPECOFF(module_sp);
143 symbol_vendor->AddSymbolFileRepresentation(dsym_objfile_sp);
144 return symbol_vendor;
145}
#define LLDB_PLUGIN_DEFINE(PluginName)
#define LLDB_SCOPED_TIMERF(...)
Definition Timer.h:86
lldb_private::UUID GetUUID() override
Gets the UUID for this object file.
std::optional< lldb_private::FileSpec > GetDebugLink()
Return the contents of the .gnu_debuglink section, if the object file contains it.
std::optional< lldb_private::FileSpec > GetPDBPath()
SymbolVendorPECOFF(const lldb::ModuleSP &module_sp)
static lldb_private::SymbolVendor * CreateInstance(const lldb::ModuleSP &module_sp, lldb_private::Stream *feedback_strm)
static llvm::StringRef GetPluginNameStatic()
static llvm::StringRef GetPluginDescriptionStatic()
A uniqued constant string class.
Definition ConstString.h:40
A file collection class.
bool Insert(size_t idx, const FileSpec &file)
A file utility class.
Definition FileSpec.h:57
const ConstString & GetDirectory() const
Directory string const get accessor.
Definition FileSpec.h:234
static FileSystem & Instance()
void Resolve(llvm::SmallVectorImpl< char > &path, bool force_make_absolute=false)
Resolve path to make it canonical.
FileSpec & GetFileSpec()
Definition ModuleSpec.h:57
FileSpec & GetSymbolFileSpec()
Definition ModuleSpec.h:81
static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataExtractorSP extractor_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:57
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition ObjectFile.h:280
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static FileSpec LocateExecutableSymbolFile(const ModuleSpec &module_spec, const FileSpecList &default_search_paths, StatisticsMap &map)
static bool UnregisterPlugin(ABICreateInstance create_callback)
size_t AddSection(const lldb::SectionSP &section_sp)
Definition Section.cpp:483
bool ReplaceSection(lldb::user_id_t sect_id, const lldb::SectionSP &section_sp, uint32_t depth=UINT32_MAX)
Definition Section.cpp:523
lldb::SectionSP FindSectionByType(lldb::SectionType sect_type, bool check_children, size_t start_idx=0) const
Definition Section.cpp:599
A stream class that can stream formatted output to a file.
Definition Stream.h:28
void AddSymbolFileRepresentation(const lldb::ObjectFileSP &objfile_sp)
SymbolVendor(const lldb::ModuleSP &module_sp)
static FileSpecList GetDefaultDebugFileSearchPaths()
Definition Target.cpp:2799
Represents UUID's of various sizes.
Definition UUID.h:27
A class that represents a running process on the host machine.
uint64_t offset_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
std::shared_ptr< lldb_private::Section > SectionSP
@ eSectionTypeDWARFDebugPubNames
@ eSectionTypeDWARFDebugFrame
@ eSectionTypeDWARFDebugLocLists
DWARF v5 .debug_loclists.
@ eSectionTypeDWARFDebugTypes
DWARF .debug_types section.
@ eSectionTypeDWARFDebugMacInfo
@ eSectionTypeDWARFDebugNames
DWARF v5 .debug_names.
@ eSectionTypeDWARFDebugInfo
@ eSectionTypeDWARFDebugRanges
@ eSectionTypeDWARFDebugLine
@ eSectionTypeDWARFDebugPubTypes
@ eSectionTypeDWARFDebugStr
@ eSectionTypeDWARFDebugLoc
@ eSectionTypeDWARFDebugAranges
@ eSectionTypeDWARFDebugAbbrev
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP