blob: d0082925a3ced9b28220359e82e24e20211ac4f5 [file] [log] [blame]
Zachary Turner74e08ca2016-03-02 22:05:52 +00001//===-- SymbolFilePDB.cpp ---------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "SymbolFilePDB.h"
11
Zachary Turner42dff792016-04-15 00:21:26 +000012#include "clang/Lex/Lexer.h"
13
Zachary Turner74e08ca2016-03-02 22:05:52 +000014#include "lldb/Core/Module.h"
15#include "lldb/Core/PluginManager.h"
Zachary Turner42dff792016-04-15 00:21:26 +000016#include "lldb/Symbol/ClangASTContext.h"
Zachary Turner74e08ca2016-03-02 22:05:52 +000017#include "lldb/Symbol/CompileUnit.h"
18#include "lldb/Symbol/LineTable.h"
19#include "lldb/Symbol/ObjectFile.h"
20#include "lldb/Symbol/SymbolContext.h"
Aaron Smith10a02572018-01-13 06:58:18 +000021#include "lldb/Symbol/SymbolVendor.h"
Zachary Turner42dff792016-04-15 00:21:26 +000022#include "lldb/Symbol/TypeMap.h"
Aaron Smith563799b2018-01-19 21:55:44 +000023#include "lldb/Symbol/TypeList.h"
Aaron Smith86e94342017-12-22 05:26:50 +000024#include "lldb/Utility/RegularExpression.h"
Zachary Turner74e08ca2016-03-02 22:05:52 +000025
Pavel Labathb8d8c622016-05-09 11:07:43 +000026#include "llvm/DebugInfo/PDB/GenericError.h"
Aaron Smith1f8552a2017-12-22 00:04:36 +000027#include "llvm/DebugInfo/PDB/IPDBDataStream.h"
Zachary Turner74e08ca2016-03-02 22:05:52 +000028#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
29#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
30#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
Aaron Smith1f8552a2017-12-22 00:04:36 +000031#include "llvm/DebugInfo/PDB/IPDBTable.h"
Zachary Turner74e08ca2016-03-02 22:05:52 +000032#include "llvm/DebugInfo/PDB/PDBSymbol.h"
33#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
34#include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
Aaron Smith1f8552a2017-12-22 00:04:36 +000035#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
Zachary Turner74e08ca2016-03-02 22:05:52 +000036#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
37#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
38#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
39#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
Zachary Turner42dff792016-04-15 00:21:26 +000040#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
41#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
42#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
43
44#include "Plugins/SymbolFile/PDB/PDBASTParser.h"
45
46#include <regex>
Zachary Turner74e08ca2016-03-02 22:05:52 +000047
Aaron Smith10a02572018-01-13 06:58:18 +000048using namespace lldb;
Zachary Turner74e08ca2016-03-02 22:05:52 +000049using namespace lldb_private;
Zachary Turner54fd7ff2016-05-04 20:33:53 +000050using namespace llvm::pdb;
Zachary Turner74e08ca2016-03-02 22:05:52 +000051
Kate Stoneb9c1b512016-09-06 20:57:50 +000052namespace {
53lldb::LanguageType TranslateLanguage(PDB_Lang lang) {
54 switch (lang) {
55 case PDB_Lang::Cpp:
56 return lldb::LanguageType::eLanguageTypeC_plus_plus;
57 case PDB_Lang::C:
58 return lldb::LanguageType::eLanguageTypeC;
59 default:
60 return lldb::LanguageType::eLanguageTypeUnknown;
61 }
Zachary Turner74e08ca2016-03-02 22:05:52 +000062}
63
Kate Stoneb9c1b512016-09-06 20:57:50 +000064bool ShouldAddLine(uint32_t requested_line, uint32_t actual_line,
65 uint32_t addr_length) {
66 return ((requested_line == 0 || actual_line == requested_line) &&
67 addr_length > 0);
68}
Zachary Turner74e08ca2016-03-02 22:05:52 +000069}
70
Kate Stoneb9c1b512016-09-06 20:57:50 +000071void SymbolFilePDB::Initialize() {
72 PluginManager::RegisterPlugin(GetPluginNameStatic(),
73 GetPluginDescriptionStatic(), CreateInstance,
74 DebuggerInitialize);
Zachary Turner74e08ca2016-03-02 22:05:52 +000075}
76
Kate Stoneb9c1b512016-09-06 20:57:50 +000077void SymbolFilePDB::Terminate() {
78 PluginManager::UnregisterPlugin(CreateInstance);
Zachary Turner74e08ca2016-03-02 22:05:52 +000079}
80
Kate Stoneb9c1b512016-09-06 20:57:50 +000081void SymbolFilePDB::DebuggerInitialize(lldb_private::Debugger &debugger) {}
82
83lldb_private::ConstString SymbolFilePDB::GetPluginNameStatic() {
84 static ConstString g_name("pdb");
85 return g_name;
Zachary Turner74e08ca2016-03-02 22:05:52 +000086}
87
Kate Stoneb9c1b512016-09-06 20:57:50 +000088const char *SymbolFilePDB::GetPluginDescriptionStatic() {
89 return "Microsoft PDB debug symbol file reader.";
Zachary Turner74e08ca2016-03-02 22:05:52 +000090}
91
92lldb_private::SymbolFile *
Kate Stoneb9c1b512016-09-06 20:57:50 +000093SymbolFilePDB::CreateInstance(lldb_private::ObjectFile *obj_file) {
94 return new SymbolFilePDB(obj_file);
Zachary Turner74e08ca2016-03-02 22:05:52 +000095}
96
97SymbolFilePDB::SymbolFilePDB(lldb_private::ObjectFile *object_file)
Aaron Smith10a02572018-01-13 06:58:18 +000098 : SymbolFile(object_file), m_session_up(), m_global_scope_up(),
99 m_cached_compile_unit_count(0), m_tu_decl_ctx_up() {}
Zachary Turner74e08ca2016-03-02 22:05:52 +0000100
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101SymbolFilePDB::~SymbolFilePDB() {}
Zachary Turner74e08ca2016-03-02 22:05:52 +0000102
Kate Stoneb9c1b512016-09-06 20:57:50 +0000103uint32_t SymbolFilePDB::CalculateAbilities() {
Aaron Smith1f8552a2017-12-22 00:04:36 +0000104 uint32_t abilities = 0;
105 if (!m_obj_file)
106 return 0;
107
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108 if (!m_session_up) {
109 // Lazily load and match the PDB file, but only do this once.
110 std::string exePath = m_obj_file->GetFileSpec().GetPath();
111 auto error = loadDataForEXE(PDB_ReaderType::DIA, llvm::StringRef(exePath),
112 m_session_up);
113 if (error) {
114 llvm::consumeError(std::move(error));
Aaron Smith1f8552a2017-12-22 00:04:36 +0000115 auto module_sp = m_obj_file->GetModule();
116 if (!module_sp)
117 return 0;
118 // See if any symbol file is specified through `--symfile` option.
119 FileSpec symfile = module_sp->GetSymbolFileFileSpec();
120 if (!symfile)
121 return 0;
122 error = loadDataForPDB(PDB_ReaderType::DIA,
123 llvm::StringRef(symfile.GetPath()),
124 m_session_up);
125 if (error) {
126 llvm::consumeError(std::move(error));
127 return 0;
128 }
Zachary Turner74e08ca2016-03-02 22:05:52 +0000129 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000130 }
Aaron Smith1f8552a2017-12-22 00:04:36 +0000131 if (!m_session_up.get())
132 return 0;
133
134 auto enum_tables_up = m_session_up->getEnumTables();
135 if (!enum_tables_up)
136 return 0;
137 while (auto table_up = enum_tables_up->getNext()) {
138 if (table_up->getItemCount() == 0)
139 continue;
140 auto type = table_up->getTableType();
141 switch (type) {
142 case PDB_TableType::Symbols:
143 // This table represents a store of symbols with types listed in
144 // PDBSym_Type
145 abilities |= (CompileUnits | Functions | Blocks |
146 GlobalVariables | LocalVariables | VariableTypes);
147 break;
148 case PDB_TableType::LineNumbers:
149 abilities |= LineTables;
150 break;
151 default: break;
152 }
153 }
154 return abilities;
Zachary Turner74e08ca2016-03-02 22:05:52 +0000155}
156
Kate Stoneb9c1b512016-09-06 20:57:50 +0000157void SymbolFilePDB::InitializeObject() {
158 lldb::addr_t obj_load_address = m_obj_file->GetFileOffset();
Aaron Smith10a02572018-01-13 06:58:18 +0000159 lldbassert(obj_load_address &&
160 obj_load_address != LLDB_INVALID_ADDRESS);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000161 m_session_up->setLoadAddress(obj_load_address);
Aaron Smith10a02572018-01-13 06:58:18 +0000162 if (!m_global_scope_up)
163 m_global_scope_up = m_session_up->getGlobalScope();
164 lldbassert(m_global_scope_up.get());
Zachary Turner42dff792016-04-15 00:21:26 +0000165
Kate Stoneb9c1b512016-09-06 20:57:50 +0000166 TypeSystem *type_system =
167 GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus);
168 ClangASTContext *clang_type_system =
169 llvm::dyn_cast_or_null<ClangASTContext>(type_system);
Aaron Smith10a02572018-01-13 06:58:18 +0000170 lldbassert(clang_type_system);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000171 m_tu_decl_ctx_up = llvm::make_unique<CompilerDeclContext>(
172 type_system, clang_type_system->GetTranslationUnitDecl());
Zachary Turner74e08ca2016-03-02 22:05:52 +0000173}
174
Kate Stoneb9c1b512016-09-06 20:57:50 +0000175uint32_t SymbolFilePDB::GetNumCompileUnits() {
176 if (m_cached_compile_unit_count == 0) {
Aaron Smith10a02572018-01-13 06:58:18 +0000177 auto compilands = m_global_scope_up->findAllChildren<PDBSymbolCompiland>();
178 if (!compilands)
179 return 0;
180
181 // The linker could link *.dll (compiland language = LINK), or import
182 // *.dll. For example, a compiland with name `Import:KERNEL32.dll`
183 // could be found as a child of the global scope (PDB executable).
184 // Usually, such compilands contain `thunk` symbols in which we are not
185 // interested for now. However we still count them in the compiland list.
186 // If we perform any compiland related activity, like finding symbols
187 // through llvm::pdb::IPDBSession methods, such compilands will all be
188 // searched automatically no matter whether we include them or not.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000189 m_cached_compile_unit_count = compilands->getChildCount();
Zachary Turner74e08ca2016-03-02 22:05:52 +0000190
Kate Stoneb9c1b512016-09-06 20:57:50 +0000191 // The linker can inject an additional "dummy" compilation unit into the
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000192 // PDB. Ignore this special compile unit for our purposes, if it is there.
193 // It is always the last one.
Aaron Smith10a02572018-01-13 06:58:18 +0000194 auto last_compiland_up =
195 compilands->getChildAtIndex(m_cached_compile_unit_count - 1);
196 lldbassert(last_compiland_up.get());
197 std::string name = last_compiland_up->getName();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000198 if (name == "* Linker *")
199 --m_cached_compile_unit_count;
200 }
201 return m_cached_compile_unit_count;
202}
Zachary Turner74e08ca2016-03-02 22:05:52 +0000203
Aaron Smith10a02572018-01-13 06:58:18 +0000204void SymbolFilePDB::GetCompileUnitIndex(
205 const llvm::pdb::PDBSymbolCompiland *pdb_compiland,
206 uint32_t &index) {
207 if (!pdb_compiland)
208 return;
209
210 auto results_up = m_global_scope_up->findAllChildren<PDBSymbolCompiland>();
211 if (!results_up)
212 return;
213 auto uid = pdb_compiland->getSymIndexId();
Raphael Isemannfbdf0b92018-01-22 06:56:09 +0000214 for (uint32_t cu_idx = 0; cu_idx < GetNumCompileUnits(); ++cu_idx) {
Aaron Smith10a02572018-01-13 06:58:18 +0000215 auto compiland_up = results_up->getChildAtIndex(cu_idx);
216 if (!compiland_up)
217 continue;
218 if (compiland_up->getSymIndexId() == uid) {
219 index = cu_idx;
220 return;
221 }
222 }
223 index = UINT32_MAX;
224 return;
225}
226
227std::unique_ptr<llvm::pdb::PDBSymbolCompiland>
228SymbolFilePDB::GetPDBCompilandByUID(uint32_t uid) {
229 return m_session_up->getConcreteSymbolById<PDBSymbolCompiland>(uid);
230}
231
Kate Stoneb9c1b512016-09-06 20:57:50 +0000232lldb::CompUnitSP SymbolFilePDB::ParseCompileUnitAtIndex(uint32_t index) {
Aaron Smith10a02572018-01-13 06:58:18 +0000233 if (index >= GetNumCompileUnits())
234 return CompUnitSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000235
Aaron Smith10a02572018-01-13 06:58:18 +0000236 // Assuming we always retrieve same compilands listed in same order through
237 // `PDBSymbolExe::findAllChildren` method, otherwise using `index` to get a
238 // compile unit makes no sense.
239 auto results = m_global_scope_up->findAllChildren<PDBSymbolCompiland>();
240 if (!results)
241 return CompUnitSP();
242 auto compiland_up = results->getChildAtIndex(index);
243 if (!compiland_up)
244 return CompUnitSP();
245 return ParseCompileUnitForUID(compiland_up->getSymIndexId(), index);
Zachary Turner74e08ca2016-03-02 22:05:52 +0000246}
247
248lldb::LanguageType
Kate Stoneb9c1b512016-09-06 20:57:50 +0000249SymbolFilePDB::ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) {
250 // What fields should I expect to be filled out on the SymbolContext? Is it
251 // safe to assume that `sc.comp_unit` is valid?
252 if (!sc.comp_unit)
253 return lldb::eLanguageTypeUnknown;
Zachary Turner74e08ca2016-03-02 22:05:52 +0000254
Aaron Smith10a02572018-01-13 06:58:18 +0000255 auto compiland_up = GetPDBCompilandByUID(sc.comp_unit->GetID());
256 if (!compiland_up)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000257 return lldb::eLanguageTypeUnknown;
Aaron Smith10a02572018-01-13 06:58:18 +0000258 auto details = compiland_up->findOneChild<PDBSymbolCompilandDetails>();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000259 if (!details)
260 return lldb::eLanguageTypeUnknown;
261 return TranslateLanguage(details->getLanguage());
Zachary Turner74e08ca2016-03-02 22:05:52 +0000262}
263
Kate Stoneb9c1b512016-09-06 20:57:50 +0000264size_t SymbolFilePDB::ParseCompileUnitFunctions(
265 const lldb_private::SymbolContext &sc) {
266 // TODO: Implement this
267 return size_t();
Zachary Turner74e08ca2016-03-02 22:05:52 +0000268}
269
Kate Stoneb9c1b512016-09-06 20:57:50 +0000270bool SymbolFilePDB::ParseCompileUnitLineTable(
271 const lldb_private::SymbolContext &sc) {
Aaron Smith10a02572018-01-13 06:58:18 +0000272 lldbassert(sc.comp_unit);
273 if (sc.comp_unit->GetLineTable())
274 return true;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000275 return ParseCompileUnitLineTable(sc, 0);
Zachary Turner74e08ca2016-03-02 22:05:52 +0000276}
277
Kate Stoneb9c1b512016-09-06 20:57:50 +0000278bool SymbolFilePDB::ParseCompileUnitDebugMacros(
279 const lldb_private::SymbolContext &sc) {
280 // PDB doesn't contain information about macros
281 return false;
282}
283
284bool SymbolFilePDB::ParseCompileUnitSupportFiles(
285 const lldb_private::SymbolContext &sc,
286 lldb_private::FileSpecList &support_files) {
Aaron Smith10a02572018-01-13 06:58:18 +0000287 lldbassert(sc.comp_unit);
Zachary Turner74e08ca2016-03-02 22:05:52 +0000288
Kate Stoneb9c1b512016-09-06 20:57:50 +0000289 // In theory this is unnecessary work for us, because all of this information
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000290 // is easily (and quickly) accessible from DebugInfoPDB, so caching it a
291 // second time seems like a waste. Unfortunately, there's no good way around
292 // this short of a moderate refactor since SymbolVendor depends on being able
293 // to cache this list.
Aaron Smith10a02572018-01-13 06:58:18 +0000294 auto compiland_up = GetPDBCompilandByUID(sc.comp_unit->GetID());
295 if (!compiland_up)
Zachary Turner74e08ca2016-03-02 22:05:52 +0000296 return false;
Aaron Smith10a02572018-01-13 06:58:18 +0000297 auto files = m_session_up->getSourceFilesForCompiland(*compiland_up);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000298 if (!files || files->getChildCount() == 0)
Zachary Turner74e08ca2016-03-02 22:05:52 +0000299 return false;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000300
301 while (auto file = files->getNext()) {
Aaron Smith10a02572018-01-13 06:58:18 +0000302 FileSpec spec(file->getFileName(), false, FileSpec::ePathSyntaxWindows);
303 support_files.AppendIfUnique(spec);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000304 }
305 return true;
Zachary Turner74e08ca2016-03-02 22:05:52 +0000306}
307
Kate Stoneb9c1b512016-09-06 20:57:50 +0000308bool SymbolFilePDB::ParseImportedModules(
309 const lldb_private::SymbolContext &sc,
310 std::vector<lldb_private::ConstString> &imported_modules) {
311 // PDB does not yet support module debug info
312 return false;
Zachary Turner74e08ca2016-03-02 22:05:52 +0000313}
314
315size_t
Kate Stoneb9c1b512016-09-06 20:57:50 +0000316SymbolFilePDB::ParseFunctionBlocks(const lldb_private::SymbolContext &sc) {
317 // TODO: Implement this
318 return size_t();
Zachary Turner74e08ca2016-03-02 22:05:52 +0000319}
320
Kate Stoneb9c1b512016-09-06 20:57:50 +0000321size_t SymbolFilePDB::ParseTypes(const lldb_private::SymbolContext &sc) {
Aaron Smith563799b2018-01-19 21:55:44 +0000322 lldbassert(sc.module_sp.get());
323 size_t num_added = 0;
324 auto results_up = m_session_up->getGlobalScope()->findAllChildren();
325 if (!results_up)
326 return 0;
327 while (auto symbol_up = results_up->getNext()) {
328 switch (symbol_up->getSymTag()) {
329 case PDB_SymType::Enum:
330 case PDB_SymType::UDT:
331 case PDB_SymType::Typedef:
332 break;
333 default:
334 continue;
335 }
336
337 auto type_uid = symbol_up->getSymIndexId();
338 if (m_types.find(type_uid) != m_types.end())
339 continue;
340
341 // This should cause the type to get cached and stored in the `m_types`
342 // lookup.
343 if (!ResolveTypeUID(symbol_up->getSymIndexId()))
344 continue;
345
346 ++num_added;
347 }
348 return num_added;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000349}
350
351size_t
352SymbolFilePDB::ParseVariablesForContext(const lldb_private::SymbolContext &sc) {
353 // TODO: Implement this
354 return size_t();
355}
356
357lldb_private::Type *SymbolFilePDB::ResolveTypeUID(lldb::user_id_t type_uid) {
358 auto find_result = m_types.find(type_uid);
359 if (find_result != m_types.end())
360 return find_result->second.get();
361
362 TypeSystem *type_system =
363 GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus);
364 ClangASTContext *clang_type_system =
365 llvm::dyn_cast_or_null<ClangASTContext>(type_system);
366 if (!clang_type_system)
Zachary Turner74e08ca2016-03-02 22:05:52 +0000367 return nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000368 PDBASTParser *pdb =
369 llvm::dyn_cast<PDBASTParser>(clang_type_system->GetPDBParser());
370 if (!pdb)
371 return nullptr;
372
373 auto pdb_type = m_session_up->getSymbolById(type_uid);
374 if (pdb_type == nullptr)
375 return nullptr;
376
377 lldb::TypeSP result = pdb->CreateLLDBTypeFromPDBType(*pdb_type);
Aaron Smith563799b2018-01-19 21:55:44 +0000378 if (result.get()) {
Aaron Smith86e94342017-12-22 05:26:50 +0000379 m_types.insert(std::make_pair(type_uid, result));
Aaron Smith563799b2018-01-19 21:55:44 +0000380 auto type_list = GetTypeList();
381 type_list->Insert(result);
382 }
Kate Stoneb9c1b512016-09-06 20:57:50 +0000383 return result.get();
Zachary Turner74e08ca2016-03-02 22:05:52 +0000384}
385
Kate Stoneb9c1b512016-09-06 20:57:50 +0000386bool SymbolFilePDB::CompleteType(lldb_private::CompilerType &compiler_type) {
387 // TODO: Implement this
388 return false;
389}
390
391lldb_private::CompilerDecl SymbolFilePDB::GetDeclForUID(lldb::user_id_t uid) {
392 return lldb_private::CompilerDecl();
393}
394
395lldb_private::CompilerDeclContext
396SymbolFilePDB::GetDeclContextForUID(lldb::user_id_t uid) {
397 // PDB always uses the translation unit decl context for everything. We can
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000398 // improve this later but it's not easy because PDB doesn't provide a high
399 // enough level of type fidelity in this area.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000400 return *m_tu_decl_ctx_up;
401}
402
403lldb_private::CompilerDeclContext
404SymbolFilePDB::GetDeclContextContainingUID(lldb::user_id_t uid) {
405 return *m_tu_decl_ctx_up;
406}
407
408void SymbolFilePDB::ParseDeclsForContext(
409 lldb_private::CompilerDeclContext decl_ctx) {}
410
411uint32_t
412SymbolFilePDB::ResolveSymbolContext(const lldb_private::Address &so_addr,
413 uint32_t resolve_scope,
414 lldb_private::SymbolContext &sc) {
415 return uint32_t();
416}
417
Aaron Smith10a02572018-01-13 06:58:18 +0000418std::string SymbolFilePDB::GetSourceFileNameForPDBCompiland(
419 const PDBSymbolCompiland *pdb_compiland) {
420 if (!pdb_compiland)
421 return std::string();
422
423 std::string source_file_name;
424 // `getSourceFileName` returns the basename of the original source file
425 // used to generate this compiland. It does not return the full path.
426 // Currently the only way to get that is to do a basename lookup to get the
427 // IPDBSourceFile, but this is ambiguous in the case of two source files
428 // with the same name contributing to the same compiland. This is an edge
429 // case that we ignore for now, although we need to a long-term solution.
430 std::string file_name = pdb_compiland->getSourceFileName();
431 if (!file_name.empty()) {
432 auto one_src_file_up =
433 m_session_up->findOneSourceFile(pdb_compiland, file_name,
434 PDB_NameSearchFlags::NS_CaseInsensitive);
435 if (one_src_file_up)
436 source_file_name = one_src_file_up->getFileName();
437 }
438 // For some reason, source file name could be empty, so we will walk through
439 // all source files of this compiland, and determine the right source file
440 // if any that is used to generate this compiland based on language
441 // indicated in compilanddetails language field.
442 if (!source_file_name.empty())
443 return source_file_name;
444
445 auto details_up = pdb_compiland->findOneChild<PDBSymbolCompilandDetails>();
446 PDB_Lang pdb_lang = details_up ? details_up->getLanguage() : PDB_Lang::Cpp;
447 auto src_files_up =
448 m_session_up->getSourceFilesForCompiland(*pdb_compiland);
449 if (src_files_up) {
450 while (auto file_up = src_files_up->getNext()) {
451 FileSpec file_spec(file_up->getFileName(), false,
452 FileSpec::ePathSyntaxWindows);
453 auto file_extension = file_spec.GetFileNameExtension();
454 if (pdb_lang == PDB_Lang::Cpp || pdb_lang == PDB_Lang::C) {
455 static const char* exts[] = { "cpp", "c", "cc", "cxx" };
456 if (llvm::is_contained(exts, file_extension.GetStringRef().lower()))
457 source_file_name = file_up->getFileName();
458 break;
459 } else if (pdb_lang == PDB_Lang::Masm &&
460 ConstString::Compare(file_extension, ConstString("ASM"),
461 false) == 0) {
462 source_file_name = file_up->getFileName();
463 break;
464 }
465 }
466 }
467 return source_file_name;
468}
469
Kate Stoneb9c1b512016-09-06 20:57:50 +0000470uint32_t SymbolFilePDB::ResolveSymbolContext(
471 const lldb_private::FileSpec &file_spec, uint32_t line, bool check_inlines,
472 uint32_t resolve_scope, lldb_private::SymbolContextList &sc_list) {
Aaron Smith10a02572018-01-13 06:58:18 +0000473 const size_t old_size = sc_list.GetSize();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000474 if (resolve_scope & lldb::eSymbolContextCompUnit) {
475 // Locate all compilation units with line numbers referencing the specified
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000476 // file. For example, if `file_spec` is <vector>, then this should return
477 // all source files and header files that reference <vector>, either
478 // directly or indirectly.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000479 auto compilands = m_session_up->findCompilandsForSourceFile(
480 file_spec.GetPath(), PDB_NameSearchFlags::NS_CaseInsensitive);
481
Aaron Smith10a02572018-01-13 06:58:18 +0000482 if (!compilands)
483 return 0;
484
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000485 // For each one, either find its previously parsed data or parse it afresh
486 // and add it to the symbol context list.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000487 while (auto compiland = compilands->getNext()) {
488 // If we're not checking inlines, then don't add line information for this
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000489 // file unless the FileSpec matches.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000490 if (!check_inlines) {
491 // `getSourceFileName` returns the basename of the original source file
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000492 // used to generate this compiland. It does not return the full path.
493 // Currently the only way to get that is to do a basename lookup to get
494 // the IPDBSourceFile, but this is ambiguous in the case of two source
495 // files with the same name contributing to the same compiland. This is
496 // a moderately extreme edge case, so we consider this OK for now,
497 // although we need to find a long-term solution.
Aaron Smith10a02572018-01-13 06:58:18 +0000498 std::string source_file =
499 GetSourceFileNameForPDBCompiland(compiland.get());
500 if (source_file.empty())
501 continue;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000502 FileSpec this_spec(source_file, false, FileSpec::ePathSyntaxWindows);
Aaron Smith10a02572018-01-13 06:58:18 +0000503 bool need_full_match = !file_spec.GetDirectory().IsEmpty();
504 if (FileSpec::Compare(file_spec, this_spec, need_full_match) != 0)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000505 continue;
506 }
507
508 SymbolContext sc;
Aaron Smith10a02572018-01-13 06:58:18 +0000509 auto cu = ParseCompileUnitForUID(compiland->getSymIndexId());
510 if (!cu.get())
511 continue;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000512 sc.comp_unit = cu.get();
513 sc.module_sp = cu->GetModule();
514 sc_list.Append(sc);
515
516 // If we were asked to resolve line entries, add all entries to the line
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000517 // table that match the requested line (or all lines if `line` == 0).
Kate Stoneb9c1b512016-09-06 20:57:50 +0000518 if (resolve_scope & lldb::eSymbolContextLineEntry)
519 ParseCompileUnitLineTable(sc, line);
520 }
521 }
Aaron Smith10a02572018-01-13 06:58:18 +0000522 return sc_list.GetSize() - old_size;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000523}
524
525uint32_t SymbolFilePDB::FindGlobalVariables(
526 const lldb_private::ConstString &name,
527 const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append,
528 uint32_t max_matches, lldb_private::VariableList &variables) {
529 return uint32_t();
530}
531
532uint32_t
533SymbolFilePDB::FindGlobalVariables(const lldb_private::RegularExpression &regex,
534 bool append, uint32_t max_matches,
535 lldb_private::VariableList &variables) {
536 return uint32_t();
537}
538
539uint32_t SymbolFilePDB::FindFunctions(
540 const lldb_private::ConstString &name,
541 const lldb_private::CompilerDeclContext *parent_decl_ctx,
542 uint32_t name_type_mask, bool include_inlines, bool append,
543 lldb_private::SymbolContextList &sc_list) {
544 return uint32_t();
545}
546
547uint32_t
548SymbolFilePDB::FindFunctions(const lldb_private::RegularExpression &regex,
549 bool include_inlines, bool append,
550 lldb_private::SymbolContextList &sc_list) {
551 return uint32_t();
552}
553
554void SymbolFilePDB::GetMangledNamesForFunction(
555 const std::string &scope_qualified_name,
556 std::vector<lldb_private::ConstString> &mangled_names) {}
557
558uint32_t SymbolFilePDB::FindTypes(
559 const lldb_private::SymbolContext &sc,
560 const lldb_private::ConstString &name,
561 const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append,
562 uint32_t max_matches,
563 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
564 lldb_private::TypeMap &types) {
565 if (!append)
566 types.Clear();
567 if (!name)
568 return 0;
569
570 searched_symbol_files.clear();
571 searched_symbol_files.insert(this);
572
573 std::string name_str = name.AsCString();
574
Aaron Smith86e94342017-12-22 05:26:50 +0000575 // There is an assumption 'name' is not a regex
576 FindTypesByName(name_str, max_matches, types);
577
Kate Stoneb9c1b512016-09-06 20:57:50 +0000578 return types.GetSize();
579}
580
Aaron Smith86e94342017-12-22 05:26:50 +0000581void
582SymbolFilePDB::FindTypesByRegex(const lldb_private::RegularExpression &regex,
583 uint32_t max_matches,
584 lldb_private::TypeMap &types) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000585 // When searching by regex, we need to go out of our way to limit the search
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000586 // space as much as possible since this searches EVERYTHING in the PDB,
587 // manually doing regex comparisons. PDB library isn't optimized for regex
588 // searches or searches across multiple symbol types at the same time, so the
Kate Stoneb9c1b512016-09-06 20:57:50 +0000589 // best we can do is to search enums, then typedefs, then classes one by one,
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000590 // and do a regex comparison against each of them.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000591 PDB_SymType tags_to_search[] = {PDB_SymType::Enum, PDB_SymType::Typedef,
592 PDB_SymType::UDT};
Kate Stoneb9c1b512016-09-06 20:57:50 +0000593 std::unique_ptr<IPDBEnumSymbols> results;
594
Kate Stoneb9c1b512016-09-06 20:57:50 +0000595 uint32_t matches = 0;
596
597 for (auto tag : tags_to_search) {
Aaron Smith10a02572018-01-13 06:58:18 +0000598 results = m_global_scope_up->findAllChildren(tag);
599 if (!results)
600 continue;
601
Kate Stoneb9c1b512016-09-06 20:57:50 +0000602 while (auto result = results->getNext()) {
603 if (max_matches > 0 && matches >= max_matches)
604 break;
605
606 std::string type_name;
607 if (auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(result.get()))
608 type_name = enum_type->getName();
609 else if (auto typedef_type =
610 llvm::dyn_cast<PDBSymbolTypeTypedef>(result.get()))
611 type_name = typedef_type->getName();
612 else if (auto class_type = llvm::dyn_cast<PDBSymbolTypeUDT>(result.get()))
613 type_name = class_type->getName();
614 else {
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000615 // We're looking only for types that have names. Skip symbols, as well
616 // as unnamed types such as arrays, pointers, etc.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000617 continue;
618 }
619
Aaron Smith86e94342017-12-22 05:26:50 +0000620 if (!regex.Execute(type_name))
Kate Stoneb9c1b512016-09-06 20:57:50 +0000621 continue;
622
623 // This should cause the type to get cached and stored in the `m_types`
624 // lookup.
625 if (!ResolveTypeUID(result->getSymIndexId()))
626 continue;
627
628 auto iter = m_types.find(result->getSymIndexId());
629 if (iter == m_types.end())
630 continue;
631 types.Insert(iter->second);
632 ++matches;
633 }
634 }
635}
636
637void SymbolFilePDB::FindTypesByName(const std::string &name,
638 uint32_t max_matches,
639 lldb_private::TypeMap &types) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000640 std::unique_ptr<IPDBEnumSymbols> results;
Aaron Smith10a02572018-01-13 06:58:18 +0000641 results = m_global_scope_up->findChildren(PDB_SymType::None, name,
642 PDB_NameSearchFlags::NS_Default);
643 if (!results)
644 return;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000645
646 uint32_t matches = 0;
647
648 while (auto result = results->getNext()) {
649 if (max_matches > 0 && matches >= max_matches)
650 break;
651 switch (result->getSymTag()) {
652 case PDB_SymType::Enum:
653 case PDB_SymType::UDT:
654 case PDB_SymType::Typedef:
655 break;
656 default:
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000657 // We're looking only for types that have names. Skip symbols, as well as
Kate Stoneb9c1b512016-09-06 20:57:50 +0000658 // unnamed types such as arrays, pointers, etc.
659 continue;
660 }
661
662 // This should cause the type to get cached and stored in the `m_types`
663 // lookup.
664 if (!ResolveTypeUID(result->getSymIndexId()))
665 continue;
666
667 auto iter = m_types.find(result->getSymIndexId());
668 if (iter == m_types.end())
669 continue;
670 types.Insert(iter->second);
671 ++matches;
672 }
673}
674
675size_t SymbolFilePDB::FindTypes(
676 const std::vector<lldb_private::CompilerContext> &contexts, bool append,
677 lldb_private::TypeMap &types) {
678 return 0;
679}
680
Aaron Smith563799b2018-01-19 21:55:44 +0000681lldb_private::TypeList *SymbolFilePDB::GetTypeList() {
682 return m_obj_file->GetModule()->GetTypeList();
683}
Kate Stoneb9c1b512016-09-06 20:57:50 +0000684
685size_t SymbolFilePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope,
686 uint32_t type_mask,
687 lldb_private::TypeList &type_list) {
688 return size_t();
Zachary Turner74e08ca2016-03-02 22:05:52 +0000689}
690
691lldb_private::TypeSystem *
Kate Stoneb9c1b512016-09-06 20:57:50 +0000692SymbolFilePDB::GetTypeSystemForLanguage(lldb::LanguageType language) {
693 auto type_system =
694 m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
695 if (type_system)
696 type_system->SetSymbolFile(this);
697 return type_system;
Zachary Turner74e08ca2016-03-02 22:05:52 +0000698}
699
Kate Stoneb9c1b512016-09-06 20:57:50 +0000700lldb_private::CompilerDeclContext SymbolFilePDB::FindNamespace(
701 const lldb_private::SymbolContext &sc,
702 const lldb_private::ConstString &name,
703 const lldb_private::CompilerDeclContext *parent_decl_ctx) {
704 return lldb_private::CompilerDeclContext();
Zachary Turner74e08ca2016-03-02 22:05:52 +0000705}
706
Kate Stoneb9c1b512016-09-06 20:57:50 +0000707lldb_private::ConstString SymbolFilePDB::GetPluginName() {
708 static ConstString g_name("pdb");
709 return g_name;
Zachary Turner74e08ca2016-03-02 22:05:52 +0000710}
711
Kate Stoneb9c1b512016-09-06 20:57:50 +0000712uint32_t SymbolFilePDB::GetPluginVersion() { return 1; }
713
714IPDBSession &SymbolFilePDB::GetPDBSession() { return *m_session_up; }
715
716const IPDBSession &SymbolFilePDB::GetPDBSession() const {
717 return *m_session_up;
Zachary Turner74e08ca2016-03-02 22:05:52 +0000718}
719
Aaron Smith10a02572018-01-13 06:58:18 +0000720lldb::CompUnitSP
721SymbolFilePDB::ParseCompileUnitForUID(uint32_t id, uint32_t index) {
Kate Stoneb9c1b512016-09-06 20:57:50 +0000722 auto found_cu = m_comp_units.find(id);
723 if (found_cu != m_comp_units.end())
724 return found_cu->second;
725
Aaron Smith10a02572018-01-13 06:58:18 +0000726 auto compiland_up = GetPDBCompilandByUID(id);
727 if (!compiland_up)
728 return CompUnitSP();
729 std::string path = GetSourceFileNameForPDBCompiland(compiland_up.get());
730 if (path.empty())
731 return CompUnitSP();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000732
733 lldb::LanguageType lang;
Aaron Smith10a02572018-01-13 06:58:18 +0000734 auto details = compiland_up->findOneChild<PDBSymbolCompilandDetails>();
Kate Stoneb9c1b512016-09-06 20:57:50 +0000735 if (!details)
736 lang = lldb::eLanguageTypeC_plus_plus;
737 else
738 lang = TranslateLanguage(details->getLanguage());
739
740 // Don't support optimized code for now, DebugInfoPDB does not return this
741 // information.
742 LazyBool optimized = eLazyBoolNo;
Aaron Smith10a02572018-01-13 06:58:18 +0000743 auto cu_sp = std::make_shared<CompileUnit>(
Kate Stoneb9c1b512016-09-06 20:57:50 +0000744 m_obj_file->GetModule(), nullptr, path.c_str(), id, lang, optimized);
Aaron Smith10a02572018-01-13 06:58:18 +0000745
746 if (!cu_sp)
747 return CompUnitSP();
748
749 m_comp_units.insert(std::make_pair(id, cu_sp));
750 if (index == UINT32_MAX)
751 GetCompileUnitIndex(compiland_up.get(), index);
752 lldbassert(index != UINT32_MAX);
753 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(
754 index, cu_sp);
755 return cu_sp;
Zachary Turner42dff792016-04-15 00:21:26 +0000756}
757
Kate Stoneb9c1b512016-09-06 20:57:50 +0000758bool SymbolFilePDB::ParseCompileUnitLineTable(
759 const lldb_private::SymbolContext &sc, uint32_t match_line) {
Aaron Smith10a02572018-01-13 06:58:18 +0000760 lldbassert(sc.comp_unit);
761
762 auto compiland_up = GetPDBCompilandByUID(sc.comp_unit->GetID());
763 if (!compiland_up)
764 return false;
Zachary Turner42dff792016-04-15 00:21:26 +0000765
Kate Stoneb9c1b512016-09-06 20:57:50 +0000766 // LineEntry needs the *index* of the file into the list of support files
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000767 // returned by ParseCompileUnitSupportFiles. But the underlying SDK gives us
768 // a globally unique idenfitifier in the namespace of the PDB. So, we have to
769 // do a mapping so that we can hand out indices.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000770 llvm::DenseMap<uint32_t, uint32_t> index_map;
Aaron Smith10a02572018-01-13 06:58:18 +0000771 BuildSupportFileIdToSupportFileIndexMap(*compiland_up, index_map);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000772 auto line_table = llvm::make_unique<LineTable>(sc.comp_unit);
Zachary Turner74e08ca2016-03-02 22:05:52 +0000773
Aaron Smith10a02572018-01-13 06:58:18 +0000774 // Find contributions to `compiland` from all source and header files.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000775 std::string path = sc.comp_unit->GetPath();
Aaron Smith10a02572018-01-13 06:58:18 +0000776 auto files = m_session_up->getSourceFilesForCompiland(*compiland_up);
777 if (!files)
778 return false;
Zachary Turner74e08ca2016-03-02 22:05:52 +0000779
Kate Stoneb9c1b512016-09-06 20:57:50 +0000780 // For each source and header file, create a LineSequence for contributions to
Aaron Smith10a02572018-01-13 06:58:18 +0000781 // the compiland from that file, and add the sequence.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000782 while (auto file = files->getNext()) {
783 std::unique_ptr<LineSequence> sequence(
784 line_table->CreateLineSequenceContainer());
Aaron Smith10a02572018-01-13 06:58:18 +0000785 auto lines = m_session_up->findLineNumbers(*compiland_up, *file);
786 if (!lines)
787 continue;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000788 int entry_count = lines->getChildCount();
Zachary Turner74e08ca2016-03-02 22:05:52 +0000789
Kate Stoneb9c1b512016-09-06 20:57:50 +0000790 uint64_t prev_addr;
791 uint32_t prev_length;
792 uint32_t prev_line;
793 uint32_t prev_source_idx;
Zachary Turner74e08ca2016-03-02 22:05:52 +0000794
Kate Stoneb9c1b512016-09-06 20:57:50 +0000795 for (int i = 0; i < entry_count; ++i) {
796 auto line = lines->getChildAtIndex(i);
Zachary Turner74e08ca2016-03-02 22:05:52 +0000797
Kate Stoneb9c1b512016-09-06 20:57:50 +0000798 uint64_t lno = line->getLineNumber();
799 uint64_t addr = line->getVirtualAddress();
800 uint32_t length = line->getLength();
801 uint32_t source_id = line->getSourceFileId();
802 uint32_t col = line->getColumnNumber();
803 uint32_t source_idx = index_map[source_id];
Zachary Turner74e08ca2016-03-02 22:05:52 +0000804
Kate Stoneb9c1b512016-09-06 20:57:50 +0000805 // There was a gap between the current entry and the previous entry if the
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000806 // addresses don't perfectly line up.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000807 bool is_gap = (i > 0) && (prev_addr + prev_length < addr);
Zachary Turner74e08ca2016-03-02 22:05:52 +0000808
Kate Stoneb9c1b512016-09-06 20:57:50 +0000809 // Before inserting the current entry, insert a terminal entry at the end
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000810 // of the previous entry's address range if the current entry resulted in
811 // a gap from the previous entry.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000812 if (is_gap && ShouldAddLine(match_line, prev_line, prev_length)) {
813 line_table->AppendLineEntryToSequence(
814 sequence.get(), prev_addr + prev_length, prev_line, 0,
815 prev_source_idx, false, false, false, false, true);
816 }
Zachary Turner74e08ca2016-03-02 22:05:52 +0000817
Kate Stoneb9c1b512016-09-06 20:57:50 +0000818 if (ShouldAddLine(match_line, lno, length)) {
819 bool is_statement = line->isStatement();
820 bool is_prologue = false;
821 bool is_epilogue = false;
822 auto func =
823 m_session_up->findSymbolByAddress(addr, PDB_SymType::Function);
824 if (func) {
825 auto prologue = func->findOneChild<PDBSymbolFuncDebugStart>();
Aaron Smith10a02572018-01-13 06:58:18 +0000826 if (prologue)
827 is_prologue = (addr == prologue->getVirtualAddress());
Zachary Turner74e08ca2016-03-02 22:05:52 +0000828
Kate Stoneb9c1b512016-09-06 20:57:50 +0000829 auto epilogue = func->findOneChild<PDBSymbolFuncDebugEnd>();
Aaron Smith10a02572018-01-13 06:58:18 +0000830 if (epilogue)
831 is_epilogue = (addr == epilogue->getVirtualAddress());
Zachary Turner74e08ca2016-03-02 22:05:52 +0000832 }
Zachary Turner7e8c7be2016-03-10 00:06:26 +0000833
Kate Stoneb9c1b512016-09-06 20:57:50 +0000834 line_table->AppendLineEntryToSequence(sequence.get(), addr, lno, col,
835 source_idx, is_statement, false,
836 is_prologue, is_epilogue, false);
837 }
Zachary Turner7e8c7be2016-03-10 00:06:26 +0000838
Kate Stoneb9c1b512016-09-06 20:57:50 +0000839 prev_addr = addr;
840 prev_length = length;
841 prev_line = lno;
842 prev_source_idx = source_idx;
Zachary Turner74e08ca2016-03-02 22:05:52 +0000843 }
844
Kate Stoneb9c1b512016-09-06 20:57:50 +0000845 if (entry_count > 0 && ShouldAddLine(match_line, prev_line, prev_length)) {
846 // The end is always a terminal entry, so insert it regardless.
847 line_table->AppendLineEntryToSequence(
848 sequence.get(), prev_addr + prev_length, prev_line, 0,
849 prev_source_idx, false, false, false, false, true);
850 }
851
852 line_table->InsertSequence(sequence.release());
853 }
854
Aaron Smith10a02572018-01-13 06:58:18 +0000855 if (line_table->GetSize()) {
856 sc.comp_unit->SetLineTable(line_table.release());
857 return true;
858 }
859 return false;
Zachary Turner74e08ca2016-03-02 22:05:52 +0000860}
861
Kate Stoneb9c1b512016-09-06 20:57:50 +0000862void SymbolFilePDB::BuildSupportFileIdToSupportFileIndexMap(
Aaron Smith10a02572018-01-13 06:58:18 +0000863 const PDBSymbolCompiland &compiland,
Kate Stoneb9c1b512016-09-06 20:57:50 +0000864 llvm::DenseMap<uint32_t, uint32_t> &index_map) const {
865 // This is a hack, but we need to convert the source id into an index into the
Adrian McCarthy9d0eb9962017-01-27 21:42:28 +0000866 // support files array. We don't want to do path comparisons to avoid
867 // basename / full path issues that may or may not even be a problem, so we
868 // use the globally unique source file identifiers. Ideally we could use the
869 // global identifiers everywhere, but LineEntry currently assumes indices.
Aaron Smith10a02572018-01-13 06:58:18 +0000870 auto source_files = m_session_up->getSourceFilesForCompiland(compiland);
871 if (!source_files)
872 return;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000873 int index = 0;
Zachary Turner74e08ca2016-03-02 22:05:52 +0000874
Kate Stoneb9c1b512016-09-06 20:57:50 +0000875 while (auto file = source_files->getNext()) {
876 uint32_t source_id = file->getUniqueId();
877 index_map[source_id] = index++;
878 }
Zachary Turner74e08ca2016-03-02 22:05:52 +0000879}