LLDB mainline
SymbolFilePDB.cpp
Go to the documentation of this file.
1//===-- SymbolFilePDB.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 "SymbolFilePDB.h"
10
11#include "PDBASTParser.h"
13
14#include "clang/Lex/Lexer.h"
15
17#include "lldb/Core/Module.h"
25#include "lldb/Symbol/TypeMap.h"
28#include "lldb/Utility/Log.h"
30
31#include "llvm/Config/llvm-config.h" // for LLVM_ENABLE_DIA_SDK
32#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
33#include "llvm/DebugInfo/PDB/GenericError.h"
34#include "llvm/DebugInfo/PDB/IPDBDataStream.h"
35#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
36#include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
37#include "llvm/DebugInfo/PDB/IPDBSectionContrib.h"
38#include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
39#include "llvm/DebugInfo/PDB/IPDBTable.h"
40#include "llvm/DebugInfo/PDB/PDBSymbol.h"
41#include "llvm/DebugInfo/PDB/PDBSymbolBlock.h"
42#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
43#include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
44#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
45#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
46#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
47#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
48#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
49#include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
50#include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
51#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
52#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
53#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
54#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
55
59
60#if defined(_WIN32)
61#include "llvm/Config/llvm-config.h"
62#include <optional>
63#endif
64
65using namespace lldb;
66using namespace lldb_private;
67using namespace llvm::pdb;
68
70
72
73namespace {
75 switch (lang) {
76 case PDB_Lang::Cpp:
78 case PDB_Lang::C:
80 case PDB_Lang::Swift:
82 case PDB_Lang::Rust:
84 case PDB_Lang::ObjC:
86 case PDB_Lang::ObjCpp:
88 default:
90 }
91}
92
93bool ShouldAddLine(uint32_t requested_line, uint32_t actual_line,
94 uint32_t addr_length) {
95 return ((requested_line == 0 || actual_line == requested_line) &&
96 addr_length > 0);
97}
98} // namespace
99
101#if defined(_WIN32)
102#if LLVM_ENABLE_DIA_SDK
103 llvm::StringRef use_native = ::getenv("LLDB_USE_NATIVE_PDB_READER");
104 if (!use_native.equals_insensitive("on") &&
105 !use_native.equals_insensitive("yes") &&
106 !use_native.equals_insensitive("1") &&
107 !use_native.equals_insensitive("true"))
108 return false;
109#endif
110#endif
111 return true;
112}
113
115 if (ShouldUseNativeReader()) {
117 } else {
121 }
122}
123
125 if (ShouldUseNativeReader()) {
127 } else {
129 }
130}
131
133
135 return "Microsoft PDB debug symbol file reader.";
136}
137
140 return new SymbolFilePDB(std::move(objfile_sp));
141}
142
144 : SymbolFileCommon(std::move(objfile_sp)), m_session_up(), m_global_scope_up() {}
145
147
149 uint32_t abilities = 0;
150 if (!m_objfile_sp)
151 return 0;
152
153 if (!m_session_up) {
154 // Lazily load and match the PDB file, but only do this once.
155 std::string exePath = m_objfile_sp->GetFileSpec().GetPath();
156 auto error = loadDataForEXE(PDB_ReaderType::DIA, llvm::StringRef(exePath),
158 if (error) {
159 llvm::consumeError(std::move(error));
160 auto module_sp = m_objfile_sp->GetModule();
161 if (!module_sp)
162 return 0;
163 // See if any symbol file is specified through `--symfile` option.
164 FileSpec symfile = module_sp->GetSymbolFileFileSpec();
165 if (!symfile)
166 return 0;
167 error = loadDataForPDB(PDB_ReaderType::DIA,
168 llvm::StringRef(symfile.GetPath()), m_session_up);
169 if (error) {
170 llvm::consumeError(std::move(error));
171 return 0;
172 }
173 }
174 }
175 if (!m_session_up)
176 return 0;
177
178 auto enum_tables_up = m_session_up->getEnumTables();
179 if (!enum_tables_up)
180 return 0;
181 while (auto table_up = enum_tables_up->getNext()) {
182 if (table_up->getItemCount() == 0)
183 continue;
184 auto type = table_up->getTableType();
185 switch (type) {
186 case PDB_TableType::Symbols:
187 // This table represents a store of symbols with types listed in
188 // PDBSym_Type
189 abilities |= (CompileUnits | Functions | Blocks | GlobalVariables |
191 break;
192 case PDB_TableType::LineNumbers:
193 abilities |= LineTables;
194 break;
195 default:
196 break;
197 }
198 }
199 return abilities;
200}
201
203 lldb::addr_t obj_load_address =
204 m_objfile_sp->GetBaseAddress().GetFileAddress();
205 lldbassert(obj_load_address && obj_load_address != LLDB_INVALID_ADDRESS);
206 m_session_up->setLoadAddress(obj_load_address);
208 m_global_scope_up = m_session_up->getGlobalScope();
210}
211
213 auto compilands = m_global_scope_up->findAllChildren<PDBSymbolCompiland>();
214 if (!compilands)
215 return 0;
216
217 // The linker could link *.dll (compiland language = LINK), or import
218 // *.dll. For example, a compiland with name `Import:KERNEL32.dll` could be
219 // found as a child of the global scope (PDB executable). Usually, such
220 // compilands contain `thunk` symbols in which we are not interested for
221 // now. However we still count them in the compiland list. If we perform
222 // any compiland related activity, like finding symbols through
223 // llvm::pdb::IPDBSession methods, such compilands will all be searched
224 // automatically no matter whether we include them or not.
225 uint32_t compile_unit_count = compilands->getChildCount();
226
227 // The linker can inject an additional "dummy" compilation unit into the
228 // PDB. Ignore this special compile unit for our purposes, if it is there.
229 // It is always the last one.
230 auto last_compiland_up = compilands->getChildAtIndex(compile_unit_count - 1);
231 lldbassert(last_compiland_up.get());
232 std::string name = last_compiland_up->getName();
233 if (name == "* Linker *")
234 --compile_unit_count;
235 return compile_unit_count;
236}
237
239 const llvm::pdb::PDBSymbolCompiland &pdb_compiland, uint32_t &index) {
240 auto results_up = m_global_scope_up->findAllChildren<PDBSymbolCompiland>();
241 if (!results_up)
242 return;
243 auto uid = pdb_compiland.getSymIndexId();
244 for (uint32_t cu_idx = 0; cu_idx < GetNumCompileUnits(); ++cu_idx) {
245 auto compiland_up = results_up->getChildAtIndex(cu_idx);
246 if (!compiland_up)
247 continue;
248 if (compiland_up->getSymIndexId() == uid) {
249 index = cu_idx;
250 return;
251 }
252 }
253 index = UINT32_MAX;
254}
255
256std::unique_ptr<llvm::pdb::PDBSymbolCompiland>
258 return m_session_up->getConcreteSymbolById<PDBSymbolCompiland>(uid);
259}
260
262 if (index >= GetNumCompileUnits())
263 return CompUnitSP();
264
265 // Assuming we always retrieve same compilands listed in same order through
266 // `PDBSymbolExe::findAllChildren` method, otherwise using `index` to get a
267 // compile unit makes no sense.
268 auto results = m_global_scope_up->findAllChildren<PDBSymbolCompiland>();
269 if (!results)
270 return CompUnitSP();
271 auto compiland_up = results->getChildAtIndex(index);
272 if (!compiland_up)
273 return CompUnitSP();
274 return ParseCompileUnitForUID(compiland_up->getSymIndexId(), index);
275}
276
278 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
279 auto compiland_up = GetPDBCompilandByUID(comp_unit.GetID());
280 if (!compiland_up)
282 auto details = compiland_up->findOneChild<PDBSymbolCompilandDetails>();
283 if (!details)
285 return TranslateLanguage(details->getLanguage());
286}
287
290 CompileUnit &comp_unit) {
291 if (FunctionSP result = comp_unit.FindFunctionByUID(pdb_func.getSymIndexId()))
292 return result.get();
293
294 auto file_vm_addr = pdb_func.getVirtualAddress();
295 if (file_vm_addr == LLDB_INVALID_ADDRESS || file_vm_addr == 0)
296 return nullptr;
297
298 auto func_length = pdb_func.getLength();
299 AddressRange func_range =
300 AddressRange(file_vm_addr, func_length,
301 GetObjectFile()->GetModule()->GetSectionList());
302 if (!func_range.GetBaseAddress().IsValid())
303 return nullptr;
304
305 lldb_private::Type *func_type = ResolveTypeUID(pdb_func.getSymIndexId());
306 if (!func_type)
307 return nullptr;
308
309 user_id_t func_type_uid = pdb_func.getSignatureId();
310
311 Mangled mangled = GetMangledForPDBFunc(pdb_func);
312
313 FunctionSP func_sp = std::make_shared<Function>(
314 &comp_unit, pdb_func.getSymIndexId(), func_type_uid, mangled, func_type,
315 AddressRanges{func_range});
316
317 comp_unit.AddFunction(func_sp);
318
319 LanguageType lang = ParseLanguage(comp_unit);
320 auto type_system_or_err = GetTypeSystemForLanguage(lang);
321 if (auto err = type_system_or_err.takeError()) {
322 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
323 "Unable to parse PDBFunc: {0}");
324 return nullptr;
325 }
326
327 auto ts = *type_system_or_err;
328 TypeSystemClang *clang_type_system =
329 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
330 if (!clang_type_system)
331 return nullptr;
332 clang_type_system->GetPDBParser()->GetDeclForSymbol(pdb_func);
333
334 return func_sp.get();
335}
336
338 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
339 size_t func_added = 0;
340 auto compiland_up = GetPDBCompilandByUID(comp_unit.GetID());
341 if (!compiland_up)
342 return 0;
343 auto results_up = compiland_up->findAllChildren<PDBSymbolFunc>();
344 if (!results_up)
345 return 0;
346 while (auto pdb_func_up = results_up->getNext()) {
347 auto func_sp = comp_unit.FindFunctionByUID(pdb_func_up->getSymIndexId());
348 if (!func_sp) {
349 if (ParseCompileUnitFunctionForPDBFunc(*pdb_func_up, comp_unit))
350 ++func_added;
351 }
352 }
353 return func_added;
354}
355
357 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
358 if (comp_unit.GetLineTable())
359 return true;
360 return ParseCompileUnitLineTable(comp_unit, 0);
361}
362
364 // PDB doesn't contain information about macros
365 return false;
366}
367
369 CompileUnit &comp_unit, lldb_private::SupportFileList &support_files) {
370
371 // In theory this is unnecessary work for us, because all of this information
372 // is easily (and quickly) accessible from DebugInfoPDB, so caching it a
373 // second time seems like a waste. Unfortunately, there's no good way around
374 // this short of a moderate refactor since SymbolVendor depends on being able
375 // to cache this list.
376 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
377 auto compiland_up = GetPDBCompilandByUID(comp_unit.GetID());
378 if (!compiland_up)
379 return false;
380 auto files = m_session_up->getSourceFilesForCompiland(*compiland_up);
381 if (!files || files->getChildCount() == 0)
382 return false;
383
384 while (auto file = files->getNext()) {
385 FileSpec spec(file->getFileName(), FileSpec::Style::windows);
386 support_files.AppendIfUnique(spec);
387 }
388
389 return true;
390}
391
394 std::vector<SourceModule> &imported_modules) {
395 // PDB does not yet support module debug info
396 return false;
397}
398
400 uint64_t func_file_vm_addr, const llvm::pdb::PDBSymbol *pdb_symbol,
401 lldb_private::Block *parent_block, bool is_top_parent) {
402 assert(pdb_symbol && parent_block);
403
404 size_t num_added = 0;
405
406 if (!is_top_parent) {
407 // Ranges for the top block were parsed together with the function.
408 if (pdb_symbol->getSymTag() != PDB_SymType::Block)
409 return num_added;
410
411 auto &raw_sym = pdb_symbol->getRawSymbol();
412 assert(llvm::isa<PDBSymbolBlock>(pdb_symbol));
413 auto uid = pdb_symbol->getSymIndexId();
414 if (parent_block->FindBlockByID(uid))
415 return num_added;
416 if (raw_sym.getVirtualAddress() < func_file_vm_addr)
417 return num_added;
418
419 Block *block = parent_block->CreateChild(pdb_symbol->getSymIndexId()).get();
420 block->AddRange(Block::Range(
421 raw_sym.getVirtualAddress() - func_file_vm_addr, raw_sym.getLength()));
422 block->FinalizeRanges();
423 }
424 auto results_up = pdb_symbol->findAllChildren();
425 if (!results_up)
426 return num_added;
427
428 while (auto symbol_up = results_up->getNext()) {
430 func_file_vm_addr, symbol_up.get(), parent_block, false);
431 }
432 return num_added;
433}
434
436 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
437 size_t num_added = 0;
438 auto uid = func.GetID();
439 auto pdb_func_up = m_session_up->getConcreteSymbolById<PDBSymbolFunc>(uid);
440 if (!pdb_func_up)
441 return 0;
442 Block &parent_block = func.GetBlock(false);
444 pdb_func_up->getVirtualAddress(), pdb_func_up.get(), &parent_block, true);
445 return num_added;
446}
447
449 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
450
451 size_t num_added = 0;
452 auto compiland = GetPDBCompilandByUID(comp_unit.GetID());
453 if (!compiland)
454 return 0;
455
456 auto ParseTypesByTagFn = [&num_added, this](const PDBSymbol &raw_sym) {
457 std::unique_ptr<IPDBEnumSymbols> results;
458 PDB_SymType tags_to_search[] = {PDB_SymType::Enum, PDB_SymType::Typedef,
459 PDB_SymType::UDT};
460 for (auto tag : tags_to_search) {
461 results = raw_sym.findAllChildren(tag);
462 if (!results || results->getChildCount() == 0)
463 continue;
464 while (auto symbol = results->getNext()) {
465 switch (symbol->getSymTag()) {
466 case PDB_SymType::Enum:
467 case PDB_SymType::UDT:
468 case PDB_SymType::Typedef:
469 break;
470 default:
471 continue;
472 }
473
474 // This should cause the type to get cached and stored in the `m_types`
475 // lookup.
476 if (auto type = ResolveTypeUID(symbol->getSymIndexId())) {
477 // Resolve the type completely to avoid a completion
478 // (and so a list change, which causes an iterators invalidation)
479 // during a TypeList dumping
480 type->GetFullCompilerType();
481 ++num_added;
482 }
483 }
484 }
485 };
486
487 ParseTypesByTagFn(*compiland);
488
489 // Also parse global types particularly coming from this compiland.
490 // Unfortunately, PDB has no compiland information for each global type. We
491 // have to parse them all. But ensure we only do this once.
492 static bool parse_all_global_types = false;
493 if (!parse_all_global_types) {
494 ParseTypesByTagFn(*m_global_scope_up);
495 parse_all_global_types = true;
496 }
497 return num_added;
498}
499
500size_t
502 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
503 if (!sc.comp_unit)
504 return 0;
505
506 size_t num_added = 0;
507 if (sc.function) {
508 auto pdb_func = m_session_up->getConcreteSymbolById<PDBSymbolFunc>(
509 sc.function->GetID());
510 if (!pdb_func)
511 return 0;
512
513 num_added += ParseVariables(sc, *pdb_func);
514 sc.function->GetBlock(false).SetDidParseVariables(true, true);
515 } else if (sc.comp_unit) {
516 auto compiland = GetPDBCompilandByUID(sc.comp_unit->GetID());
517 if (!compiland)
518 return 0;
519
520 if (sc.comp_unit->GetVariableList(false))
521 return 0;
522
523 auto results = m_global_scope_up->findAllChildren<PDBSymbolData>();
524 if (results && results->getChildCount()) {
525 while (auto result = results->getNext()) {
526 auto cu_id = GetCompilandId(*result);
527 // FIXME: We are not able to determine variable's compile unit.
528 if (cu_id == 0)
529 continue;
530
531 if (cu_id == sc.comp_unit->GetID())
532 num_added += ParseVariables(sc, *result);
533 }
534 }
535
536 // FIXME: A `file static` or `global constant` variable appears both in
537 // compiland's children and global scope's children with unexpectedly
538 // different symbol's Id making it ambiguous.
539
540 // FIXME: 'local constant', for example, const char var[] = "abc", declared
541 // in a function scope, can't be found in PDB.
542
543 // Parse variables in this compiland.
544 num_added += ParseVariables(sc, *compiland);
545 }
546
547 return num_added;
548}
549
551 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
552 auto find_result = m_types.find(type_uid);
553 if (find_result != m_types.end())
554 return find_result->second.get();
555
556 auto type_system_or_err =
558 if (auto err = type_system_or_err.takeError()) {
559 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
560 "Unable to ResolveTypeUID: {0}");
561 return nullptr;
562 }
563
564 auto ts = *type_system_or_err;
565 TypeSystemClang *clang_type_system =
566 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
567 if (!clang_type_system)
568 return nullptr;
569 PDBASTParser *pdb = clang_type_system->GetPDBParser();
570 if (!pdb)
571 return nullptr;
572
573 auto pdb_type = m_session_up->getSymbolById(type_uid);
574 if (pdb_type == nullptr)
575 return nullptr;
576
577 lldb::TypeSP result = pdb->CreateLLDBTypeFromPDBType(*pdb_type);
578 if (result) {
579 m_types.insert(std::make_pair(type_uid, result));
580 }
581 return result.get();
582}
583
584std::optional<SymbolFile::ArrayInfo> SymbolFilePDB::GetDynamicArrayInfoForUID(
585 lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) {
586 return std::nullopt;
587}
588
590 std::lock_guard<std::recursive_mutex> guard(
591 GetObjectFile()->GetModule()->GetMutex());
592
593 auto type_system_or_err =
595 if (auto err = type_system_or_err.takeError()) {
596 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
597 "Unable to get dynamic array info for UID: {0}");
598 return false;
599 }
600 auto ts = *type_system_or_err;
601 TypeSystemClang *clang_ast_ctx =
602 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
603
604 if (!clang_ast_ctx)
605 return false;
606
607 PDBASTParser *pdb = clang_ast_ctx->GetPDBParser();
608 if (!pdb)
609 return false;
610
611 return pdb->CompleteTypeFromPDB(compiler_type);
612}
613
615 auto type_system_or_err =
617 if (auto err = type_system_or_err.takeError()) {
618 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
619 "Unable to get decl for UID: {0}");
620 return CompilerDecl();
621 }
622 auto ts = *type_system_or_err;
623 TypeSystemClang *clang_ast_ctx =
624 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
625 if (!clang_ast_ctx)
626 return CompilerDecl();
627
628 PDBASTParser *pdb = clang_ast_ctx->GetPDBParser();
629 if (!pdb)
630 return CompilerDecl();
631
632 auto symbol = m_session_up->getSymbolById(uid);
633 if (!symbol)
634 return CompilerDecl();
635
636 auto decl = pdb->GetDeclForSymbol(*symbol);
637 if (!decl)
638 return CompilerDecl();
639
640 return clang_ast_ctx->GetCompilerDecl(decl);
641}
642
645 auto type_system_or_err =
647 if (auto err = type_system_or_err.takeError()) {
648 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
649 "Unable to get DeclContext for UID: {0}");
650 return CompilerDeclContext();
651 }
652
653 auto ts = *type_system_or_err;
654 TypeSystemClang *clang_ast_ctx =
655 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
656 if (!clang_ast_ctx)
657 return CompilerDeclContext();
658
659 PDBASTParser *pdb = clang_ast_ctx->GetPDBParser();
660 if (!pdb)
661 return CompilerDeclContext();
662
663 auto symbol = m_session_up->getSymbolById(uid);
664 if (!symbol)
665 return CompilerDeclContext();
666
667 auto decl_context = pdb->GetDeclContextForSymbol(*symbol);
668 if (!decl_context)
669 return GetDeclContextContainingUID(uid);
670
671 return clang_ast_ctx->CreateDeclContext(decl_context);
672}
673
676 auto type_system_or_err =
678 if (auto err = type_system_or_err.takeError()) {
679 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
680 "Unable to get DeclContext containing UID: {0}");
681 return CompilerDeclContext();
682 }
683
684 auto ts = *type_system_or_err;
685 TypeSystemClang *clang_ast_ctx =
686 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
687 if (!clang_ast_ctx)
688 return CompilerDeclContext();
689
690 PDBASTParser *pdb = clang_ast_ctx->GetPDBParser();
691 if (!pdb)
692 return CompilerDeclContext();
693
694 auto symbol = m_session_up->getSymbolById(uid);
695 if (!symbol)
696 return CompilerDeclContext();
697
698 auto decl_context = pdb->GetDeclContextContainingSymbol(*symbol);
699 assert(decl_context);
700
701 return clang_ast_ctx->CreateDeclContext(decl_context);
702}
703
706 auto type_system_or_err =
708 if (auto err = type_system_or_err.takeError()) {
709 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
710 "Unable to parse decls for context: {0}");
711 return;
712 }
713
714 auto ts = *type_system_or_err;
715 TypeSystemClang *clang_ast_ctx =
716 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
717 if (!clang_ast_ctx)
718 return;
719
720 PDBASTParser *pdb = clang_ast_ctx->GetPDBParser();
721 if (!pdb)
722 return;
723
725 static_cast<clang::DeclContext *>(decl_ctx.GetOpaqueDeclContext()));
726}
727
728uint32_t
730 SymbolContextItem resolve_scope,
732 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
733 uint32_t resolved_flags = 0;
734 if (resolve_scope & eSymbolContextCompUnit ||
735 resolve_scope & eSymbolContextVariable ||
736 resolve_scope & eSymbolContextFunction ||
737 resolve_scope & eSymbolContextBlock ||
738 resolve_scope & eSymbolContextLineEntry) {
739 auto cu_sp = GetCompileUnitContainsAddress(so_addr);
740 if (!cu_sp) {
741 if (resolved_flags & eSymbolContextVariable) {
742 // TODO: Resolve variables
743 }
744 return 0;
745 }
746 sc.comp_unit = cu_sp.get();
747 resolved_flags |= eSymbolContextCompUnit;
748 lldbassert(sc.module_sp == cu_sp->GetModule());
749 }
750
751 if (resolve_scope & eSymbolContextFunction ||
752 resolve_scope & eSymbolContextBlock) {
753 addr_t file_vm_addr = so_addr.GetFileAddress();
754 auto symbol_up =
755 m_session_up->findSymbolByAddress(file_vm_addr, PDB_SymType::Function);
756 if (symbol_up) {
757 auto *pdb_func = llvm::dyn_cast<PDBSymbolFunc>(symbol_up.get());
758 assert(pdb_func);
759 auto func_uid = pdb_func->getSymIndexId();
760 sc.function = sc.comp_unit->FindFunctionByUID(func_uid).get();
761 if (sc.function == nullptr)
762 sc.function =
764 if (sc.function) {
765 resolved_flags |= eSymbolContextFunction;
766 if (resolve_scope & eSymbolContextBlock) {
767 auto block_symbol = m_session_up->findSymbolByAddress(
768 file_vm_addr, PDB_SymType::Block);
769 auto block_id = block_symbol ? block_symbol->getSymIndexId()
770 : sc.function->GetID();
771 sc.block = sc.function->GetBlock(true).FindBlockByID(block_id);
772 if (sc.block)
773 resolved_flags |= eSymbolContextBlock;
774 }
775 }
776 }
777 }
778
779 if (resolve_scope & eSymbolContextLineEntry) {
780 if (auto *line_table = sc.comp_unit->GetLineTable()) {
781 Address addr(so_addr);
782 if (line_table->FindLineEntryByAddress(addr, sc.line_entry))
783 resolved_flags |= eSymbolContextLineEntry;
784 }
785 }
786
787 return resolved_flags;
788}
789
791 const lldb_private::SourceLocationSpec &src_location_spec,
792 SymbolContextItem resolve_scope, lldb_private::SymbolContextList &sc_list) {
793 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
794 const size_t old_size = sc_list.GetSize();
795 const FileSpec &file_spec = src_location_spec.GetFileSpec();
796 const uint32_t line = src_location_spec.GetLine().value_or(0);
797 if (resolve_scope & lldb::eSymbolContextCompUnit) {
798 // Locate all compilation units with line numbers referencing the specified
799 // file. For example, if `file_spec` is <vector>, then this should return
800 // all source files and header files that reference <vector>, either
801 // directly or indirectly.
802 auto compilands = m_session_up->findCompilandsForSourceFile(
803 file_spec.GetPath(), PDB_NameSearchFlags::NS_CaseInsensitive);
804
805 if (!compilands)
806 return 0;
807
808 // For each one, either find its previously parsed data or parse it afresh
809 // and add it to the symbol context list.
810 while (auto compiland = compilands->getNext()) {
811 // If we're not checking inlines, then don't add line information for
812 // this file unless the FileSpec matches. For inline functions, we don't
813 // have to match the FileSpec since they could be defined in headers
814 // other than file specified in FileSpec.
815 if (!src_location_spec.GetCheckInlines()) {
816 std::string source_file = compiland->getSourceFileFullPath();
817 if (source_file.empty())
818 continue;
819 FileSpec this_spec(source_file, FileSpec::Style::windows);
820 bool need_full_match = !file_spec.GetDirectory().IsEmpty();
821 if (FileSpec::Compare(file_spec, this_spec, need_full_match) != 0)
822 continue;
823 }
824
825 SymbolContext sc;
826 auto cu = ParseCompileUnitForUID(compiland->getSymIndexId());
827 if (!cu)
828 continue;
829 sc.comp_unit = cu.get();
830 sc.module_sp = cu->GetModule();
831
832 // If we were asked to resolve line entries, add all entries to the line
833 // table that match the requested line (or all lines if `line` == 0).
834 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock |
835 eSymbolContextLineEntry)) {
836 bool has_line_table = ParseCompileUnitLineTable(*sc.comp_unit, line);
837
838 if ((resolve_scope & eSymbolContextLineEntry) && !has_line_table) {
839 // The query asks for line entries, but we can't get them for the
840 // compile unit. This is not normal for `line` = 0. So just assert
841 // it.
842 assert(line && "Couldn't get all line entries!\n");
843
844 // Current compiland does not have the requested line. Search next.
845 continue;
846 }
847
848 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) {
849 if (!has_line_table)
850 continue;
851
852 auto *line_table = sc.comp_unit->GetLineTable();
853 lldbassert(line_table);
854
855 uint32_t num_line_entries = line_table->GetSize();
856 // Skip the terminal line entry.
857 --num_line_entries;
858
859 // If `line `!= 0, see if we can resolve function for each line entry
860 // in the line table.
861 for (uint32_t line_idx = 0; line && line_idx < num_line_entries;
862 ++line_idx) {
863 if (!line_table->GetLineEntryAtIndex(line_idx, sc.line_entry))
864 continue;
865
866 auto file_vm_addr =
868 if (file_vm_addr == LLDB_INVALID_ADDRESS || file_vm_addr == 0)
869 continue;
870
871 auto symbol_up = m_session_up->findSymbolByAddress(
872 file_vm_addr, PDB_SymType::Function);
873 if (symbol_up) {
874 auto func_uid = symbol_up->getSymIndexId();
875 sc.function = sc.comp_unit->FindFunctionByUID(func_uid).get();
876 if (sc.function == nullptr) {
877 auto pdb_func = llvm::dyn_cast<PDBSymbolFunc>(symbol_up.get());
878 assert(pdb_func);
880 *sc.comp_unit);
881 }
882 if (sc.function && (resolve_scope & eSymbolContextBlock)) {
883 Block &block = sc.function->GetBlock(true);
884 sc.block = block.FindBlockByID(sc.function->GetID());
885 }
886 }
887 sc_list.Append(sc);
888 }
889 } else if (has_line_table) {
890 // We can parse line table for the compile unit. But no query to
891 // resolve function or block. We append `sc` to the list anyway.
892 sc_list.Append(sc);
893 }
894 } else {
895 // No query for line entry, function or block. But we have a valid
896 // compile unit, append `sc` to the list.
897 sc_list.Append(sc);
898 }
899 }
900 }
901 return sc_list.GetSize() - old_size;
902}
903
904std::string SymbolFilePDB::GetMangledForPDBData(const PDBSymbolData &pdb_data) {
905 // Cache public names at first
906 if (m_public_names.empty())
907 if (auto result_up =
908 m_global_scope_up->findAllChildren(PDB_SymType::PublicSymbol))
909 while (auto symbol_up = result_up->getNext())
910 if (auto addr = symbol_up->getRawSymbol().getVirtualAddress())
911 m_public_names[addr] = symbol_up->getRawSymbol().getName();
912
913 // Look up the name in the cache
914 return m_public_names.lookup(pdb_data.getVirtualAddress());
915}
916
919 const llvm::pdb::PDBSymbolData &pdb_data) {
920 VariableSP var_sp;
921 uint32_t var_uid = pdb_data.getSymIndexId();
922 auto result = m_variables.find(var_uid);
923 if (result != m_variables.end())
924 return result->second;
925
927 bool is_static_member = false;
928 bool is_external = false;
929 bool is_artificial = false;
930
931 switch (pdb_data.getDataKind()) {
932 case PDB_DataKind::Global:
934 is_external = true;
935 break;
936 case PDB_DataKind::Local:
938 break;
939 case PDB_DataKind::FileStatic:
941 break;
942 case PDB_DataKind::StaticMember:
943 is_static_member = true;
945 break;
946 case PDB_DataKind::Member:
948 break;
949 case PDB_DataKind::Param:
951 break;
952 case PDB_DataKind::Constant:
953 scope = eValueTypeConstResult;
954 break;
955 default:
956 break;
957 }
958
959 switch (pdb_data.getLocationType()) {
960 case PDB_LocType::TLS:
962 break;
963 case PDB_LocType::RegRel: {
964 // It is a `this` pointer.
965 if (pdb_data.getDataKind() == PDB_DataKind::ObjectPtr) {
967 is_artificial = true;
968 }
969 } break;
970 default:
971 break;
972 }
973
974 Declaration decl;
975 if (!is_artificial && !pdb_data.isCompilerGenerated()) {
976 if (auto lines = pdb_data.getLineNumbers()) {
977 if (auto first_line = lines->getNext()) {
978 uint32_t src_file_id = first_line->getSourceFileId();
979 auto src_file = m_session_up->getSourceFileById(src_file_id);
980 if (src_file) {
981 FileSpec spec(src_file->getFileName());
982 decl.SetFile(spec);
983 decl.SetColumn(first_line->getColumnNumber());
984 decl.SetLine(first_line->getLineNumber());
985 }
986 }
987 }
988 }
989
990 Variable::RangeList ranges;
991 SymbolContextScope *context_scope = sc.comp_unit;
992 if (scope == eValueTypeVariableLocal || scope == eValueTypeVariableArgument) {
993 if (sc.function) {
994 Block &function_block = sc.function->GetBlock(true);
995 Block *block =
996 function_block.FindBlockByID(pdb_data.getLexicalParentId());
997 if (!block)
998 block = &function_block;
999
1000 context_scope = block;
1001
1002 for (size_t i = 0, num_ranges = block->GetNumRanges(); i < num_ranges;
1003 ++i) {
1004 AddressRange range;
1005 if (!block->GetRangeAtIndex(i, range))
1006 continue;
1007
1008 ranges.Append(range.GetBaseAddress().GetFileAddress(),
1009 range.GetByteSize());
1010 }
1011 }
1012 }
1013
1014 SymbolFileTypeSP type_sp =
1015 std::make_shared<SymbolFileType>(*this, pdb_data.getTypeId());
1016
1017 auto var_name = pdb_data.getName();
1018 auto mangled = GetMangledForPDBData(pdb_data);
1019 auto mangled_cstr = mangled.empty() ? nullptr : mangled.c_str();
1020
1021 bool is_constant;
1022 ModuleSP module_sp = GetObjectFile()->GetModule();
1023 DWARFExpressionList location(module_sp,
1025 module_sp, pdb_data, ranges, is_constant),
1026 nullptr);
1027
1028 var_sp = std::make_shared<Variable>(
1029 var_uid, var_name.c_str(), mangled_cstr, type_sp, scope, context_scope,
1030 ranges, &decl, location, is_external, is_artificial, is_constant,
1031 is_static_member);
1032
1033 m_variables.insert(std::make_pair(var_uid, var_sp));
1034 return var_sp;
1035}
1036
1037size_t
1039 const llvm::pdb::PDBSymbol &pdb_symbol,
1040 lldb_private::VariableList *variable_list) {
1041 size_t num_added = 0;
1042
1043 if (auto pdb_data = llvm::dyn_cast<PDBSymbolData>(&pdb_symbol)) {
1044 VariableListSP local_variable_list_sp;
1045
1046 auto result = m_variables.find(pdb_data->getSymIndexId());
1047 if (result != m_variables.end()) {
1048 if (variable_list)
1049 variable_list->AddVariableIfUnique(result->second);
1050 } else {
1051 // Prepare right VariableList for this variable.
1052 if (auto lexical_parent = pdb_data->getLexicalParent()) {
1053 switch (lexical_parent->getSymTag()) {
1054 case PDB_SymType::Exe:
1055 assert(sc.comp_unit);
1056 [[fallthrough]];
1057 case PDB_SymType::Compiland: {
1058 if (sc.comp_unit) {
1059 local_variable_list_sp = sc.comp_unit->GetVariableList(false);
1060 if (!local_variable_list_sp) {
1061 local_variable_list_sp = std::make_shared<VariableList>();
1062 sc.comp_unit->SetVariableList(local_variable_list_sp);
1063 }
1064 }
1065 } break;
1066 case PDB_SymType::Block:
1067 case PDB_SymType::Function: {
1068 if (sc.function) {
1069 Block *block = sc.function->GetBlock(true).FindBlockByID(
1070 lexical_parent->getSymIndexId());
1071 if (block) {
1072 local_variable_list_sp = block->GetBlockVariableList(false);
1073 if (!local_variable_list_sp) {
1074 local_variable_list_sp = std::make_shared<VariableList>();
1075 block->SetVariableList(local_variable_list_sp);
1076 }
1077 }
1078 }
1079 } break;
1080 default:
1081 break;
1082 }
1083 }
1084
1085 if (local_variable_list_sp) {
1086 if (auto var_sp = ParseVariableForPDBData(sc, *pdb_data)) {
1087 local_variable_list_sp->AddVariableIfUnique(var_sp);
1088 if (variable_list)
1089 variable_list->AddVariableIfUnique(var_sp);
1090 ++num_added;
1092 if (ast)
1093 ast->GetDeclForSymbol(*pdb_data);
1094 }
1095 }
1096 }
1097 }
1098
1099 if (auto results = pdb_symbol.findAllChildren()) {
1100 while (auto result = results->getNext())
1101 num_added += ParseVariables(sc, *result, variable_list);
1102 }
1103
1104 return num_added;
1105}
1106
1108 lldb_private::ConstString name, const CompilerDeclContext &parent_decl_ctx,
1109 uint32_t max_matches, lldb_private::VariableList &variables) {
1110 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1111 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
1112 return;
1113 if (name.IsEmpty())
1114 return;
1115
1116 auto results = m_global_scope_up->findAllChildren<PDBSymbolData>();
1117 if (!results)
1118 return;
1119
1120 uint32_t matches = 0;
1121 size_t old_size = variables.GetSize();
1122 while (auto result = results->getNext()) {
1123 auto pdb_data = llvm::dyn_cast<PDBSymbolData>(result.get());
1124 if (max_matches > 0 && matches >= max_matches)
1125 break;
1126
1127 SymbolContext sc;
1128 sc.module_sp = m_objfile_sp->GetModule();
1129 lldbassert(sc.module_sp.get());
1130
1131 if (name.GetStringRef() !=
1132 MSVCUndecoratedNameParser::DropScope(pdb_data->getName()))
1133 continue;
1134
1135 sc.comp_unit = ParseCompileUnitForUID(GetCompilandId(*pdb_data)).get();
1136 // FIXME: We are not able to determine the compile unit.
1137 if (sc.comp_unit == nullptr)
1138 continue;
1139
1140 if (parent_decl_ctx.IsValid() &&
1141 GetDeclContextContainingUID(result->getSymIndexId()) != parent_decl_ctx)
1142 continue;
1143
1144 ParseVariables(sc, *pdb_data, &variables);
1145 matches = variables.GetSize() - old_size;
1146 }
1147}
1148
1150 const lldb_private::RegularExpression &regex, uint32_t max_matches,
1151 lldb_private::VariableList &variables) {
1152 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1153 if (!regex.IsValid())
1154 return;
1155 auto results = m_global_scope_up->findAllChildren<PDBSymbolData>();
1156 if (!results)
1157 return;
1158
1159 uint32_t matches = 0;
1160 size_t old_size = variables.GetSize();
1161 while (auto pdb_data = results->getNext()) {
1162 if (max_matches > 0 && matches >= max_matches)
1163 break;
1164
1165 auto var_name = pdb_data->getName();
1166 if (var_name.empty())
1167 continue;
1168 if (!regex.Execute(var_name))
1169 continue;
1170 SymbolContext sc;
1171 sc.module_sp = m_objfile_sp->GetModule();
1172 lldbassert(sc.module_sp.get());
1173
1174 sc.comp_unit = ParseCompileUnitForUID(GetCompilandId(*pdb_data)).get();
1175 // FIXME: We are not able to determine the compile unit.
1176 if (sc.comp_unit == nullptr)
1177 continue;
1178
1179 ParseVariables(sc, *pdb_data, &variables);
1180 matches = variables.GetSize() - old_size;
1181 }
1182}
1183
1184bool SymbolFilePDB::ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func,
1185 bool include_inlines,
1188 sc.comp_unit = ParseCompileUnitForUID(pdb_func.getCompilandId()).get();
1189 if (!sc.comp_unit)
1190 return false;
1191 sc.module_sp = sc.comp_unit->GetModule();
1193 if (!sc.function)
1194 return false;
1195
1196 sc_list.Append(sc);
1197 return true;
1198}
1199
1200bool SymbolFilePDB::ResolveFunction(uint32_t uid, bool include_inlines,
1202 auto pdb_func_up = m_session_up->getConcreteSymbolById<PDBSymbolFunc>(uid);
1203 if (!pdb_func_up && !(include_inlines && pdb_func_up->hasInlineAttribute()))
1204 return false;
1205 return ResolveFunction(*pdb_func_up, include_inlines, sc_list);
1206}
1207
1210 return;
1211
1212 std::map<uint64_t, uint32_t> addr_ids;
1213
1214 if (auto results_up = m_global_scope_up->findAllChildren<PDBSymbolFunc>()) {
1215 while (auto pdb_func_up = results_up->getNext()) {
1216 if (pdb_func_up->isCompilerGenerated())
1217 continue;
1218
1219 auto name = pdb_func_up->getName();
1220 auto demangled_name = pdb_func_up->getUndecoratedName();
1221 if (name.empty() && demangled_name.empty())
1222 continue;
1223
1224 auto uid = pdb_func_up->getSymIndexId();
1225 if (!demangled_name.empty() && pdb_func_up->getVirtualAddress())
1226 addr_ids.insert(std::make_pair(pdb_func_up->getVirtualAddress(), uid));
1227
1228 if (auto parent = pdb_func_up->getClassParent()) {
1229
1230 // PDB have symbols for class/struct methods or static methods in Enum
1231 // Class. We won't bother to check if the parent is UDT or Enum here.
1233
1234 // To search a method name, like NS::Class:MemberFunc, LLDB searches
1235 // its base name, i.e. MemberFunc by default. Since PDBSymbolFunc does
1236 // not have information of this, we extract base names and cache them
1237 // by our own effort.
1238 llvm::StringRef basename = MSVCUndecoratedNameParser::DropScope(name);
1239 if (!basename.empty())
1240 m_func_base_names.Append(ConstString(basename), uid);
1241 else {
1243 }
1244
1245 if (!demangled_name.empty())
1246 m_func_full_names.Append(ConstString(demangled_name), uid);
1247
1248 } else {
1249 // Handle not-method symbols.
1250
1251 // The function name might contain namespace, or its lexical scope.
1252 llvm::StringRef basename = MSVCUndecoratedNameParser::DropScope(name);
1253 if (!basename.empty())
1254 m_func_base_names.Append(ConstString(basename), uid);
1255 else
1257
1258 if (name == "main") {
1260
1261 if (!demangled_name.empty() && name != demangled_name) {
1262 m_func_full_names.Append(ConstString(demangled_name), uid);
1263 m_func_base_names.Append(ConstString(demangled_name), uid);
1264 }
1265 } else if (!demangled_name.empty()) {
1266 m_func_full_names.Append(ConstString(demangled_name), uid);
1267 } else {
1269 }
1270 }
1271 }
1272 }
1273
1274 if (auto results_up =
1275 m_global_scope_up->findAllChildren<PDBSymbolPublicSymbol>()) {
1276 while (auto pub_sym_up = results_up->getNext()) {
1277 if (!pub_sym_up->isFunction())
1278 continue;
1279 auto name = pub_sym_up->getName();
1280 if (name.empty())
1281 continue;
1282
1283 if (CPlusPlusLanguage::IsCPPMangledName(name.c_str())) {
1284 // PDB public symbol has mangled name for its associated function.
1285 if (auto vm_addr = pub_sym_up->getVirtualAddress()) {
1286 if (auto it = addr_ids.find(vm_addr); it != addr_ids.end())
1287 // Cache mangled name.
1288 m_func_full_names.Append(ConstString(name), it->second);
1289 }
1290 }
1291 }
1292 }
1293 // Sort them before value searching is working properly
1300}
1301
1303 const lldb_private::Module::LookupInfo &lookup_info,
1304 const lldb_private::CompilerDeclContext &parent_decl_ctx,
1305 bool include_inlines,
1307 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1308 ConstString name = lookup_info.GetLookupName();
1309 FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();
1310 lldbassert((name_type_mask & eFunctionNameTypeAuto) == 0);
1311
1312 if (name_type_mask & eFunctionNameTypeFull)
1313 name = lookup_info.GetName();
1314
1315 if (name_type_mask == eFunctionNameTypeNone)
1316 return;
1317 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
1318 return;
1319 if (name.IsEmpty())
1320 return;
1321
1322 if (name_type_mask & eFunctionNameTypeFull ||
1323 name_type_mask & eFunctionNameTypeBase ||
1324 name_type_mask & eFunctionNameTypeMethod) {
1326
1327 std::set<uint32_t> resolved_ids;
1328 auto ResolveFn = [this, &name, parent_decl_ctx, include_inlines, &sc_list,
1329 &resolved_ids](UniqueCStringMap<uint32_t> &Names) {
1330 std::vector<uint32_t> ids;
1331 if (!Names.GetValues(name, ids))
1332 return;
1333
1334 for (uint32_t id : ids) {
1335 if (resolved_ids.find(id) != resolved_ids.end())
1336 continue;
1337
1338 if (parent_decl_ctx.IsValid() &&
1339 GetDeclContextContainingUID(id) != parent_decl_ctx)
1340 continue;
1341
1342 if (ResolveFunction(id, include_inlines, sc_list))
1343 resolved_ids.insert(id);
1344 }
1345 };
1346 if (name_type_mask & eFunctionNameTypeFull) {
1347 ResolveFn(m_func_full_names);
1348 ResolveFn(m_func_base_names);
1349 ResolveFn(m_func_method_names);
1350 }
1351 if (name_type_mask & eFunctionNameTypeBase)
1352 ResolveFn(m_func_base_names);
1353 if (name_type_mask & eFunctionNameTypeMethod)
1354 ResolveFn(m_func_method_names);
1355 }
1356}
1357
1359 bool include_inlines,
1361 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1362 if (!regex.IsValid())
1363 return;
1364
1366
1367 std::set<uint32_t> resolved_ids;
1368 auto ResolveFn = [&regex, include_inlines, &sc_list, &resolved_ids,
1369 this](UniqueCStringMap<uint32_t> &Names) {
1370 std::vector<uint32_t> ids;
1371 if (Names.GetValues(regex, ids)) {
1372 for (auto id : ids) {
1373 if (resolved_ids.find(id) == resolved_ids.end())
1374 if (ResolveFunction(id, include_inlines, sc_list))
1375 resolved_ids.insert(id);
1376 }
1377 }
1378 };
1379 ResolveFn(m_func_full_names);
1380 ResolveFn(m_func_base_names);
1381}
1382
1384 const std::string &scope_qualified_name,
1385 std::vector<lldb_private::ConstString> &mangled_names) {}
1386
1388 std::set<lldb::addr_t> sym_addresses;
1389 for (size_t i = 0; i < symtab.GetNumSymbols(); i++)
1390 sym_addresses.insert(symtab.SymbolAtIndex(i)->GetFileAddress());
1391
1392 auto results = m_global_scope_up->findAllChildren<PDBSymbolPublicSymbol>();
1393 if (!results)
1394 return;
1395
1396 auto section_list = m_objfile_sp->GetSectionList();
1397 if (!section_list)
1398 return;
1399
1400 while (auto pub_symbol = results->getNext()) {
1401 auto section_id = pub_symbol->getAddressSection();
1402
1403 auto section = section_list->FindSectionByID(section_id);
1404 if (!section)
1405 continue;
1406
1407 auto offset = pub_symbol->getAddressOffset();
1408
1409 auto file_addr = section->GetFileAddress() + offset;
1410 if (sym_addresses.find(file_addr) != sym_addresses.end())
1411 continue;
1412 sym_addresses.insert(file_addr);
1413
1414 auto size = pub_symbol->getLength();
1415 symtab.AddSymbol(
1416 Symbol(pub_symbol->getSymIndexId(), // symID
1417 pub_symbol->getName().c_str(), // name
1418 pub_symbol->isCode() ? eSymbolTypeCode : eSymbolTypeData, // type
1419 true, // external
1420 false, // is_debug
1421 false, // is_trampoline
1422 false, // is_artificial
1423 section, // section_sp
1424 offset, // value
1425 size, // size
1426 size != 0, // size_is_valid
1427 false, // contains_linker_annotations
1428 0 // flags
1429 ));
1430 }
1431
1432 symtab.Finalize();
1433}
1434
1436 auto type_system_or_err =
1438 if (auto err = type_system_or_err.takeError()) {
1439 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1440 "Unable to dump ClangAST: {0}");
1441 return;
1442 }
1443
1444 auto ts = *type_system_or_err;
1445 TypeSystemClang *clang_type_system =
1446 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
1447 if (!clang_type_system)
1448 return;
1449 clang_type_system->Dump(s.AsRawOstream());
1450}
1451
1453 const lldb_private::RegularExpression &regex, uint32_t max_matches,
1454 lldb_private::TypeMap &types) {
1455 // When searching by regex, we need to go out of our way to limit the search
1456 // space as much as possible since this searches EVERYTHING in the PDB,
1457 // manually doing regex comparisons. PDB library isn't optimized for regex
1458 // searches or searches across multiple symbol types at the same time, so the
1459 // best we can do is to search enums, then typedefs, then classes one by one,
1460 // and do a regex comparison against each of them.
1461 PDB_SymType tags_to_search[] = {PDB_SymType::Enum, PDB_SymType::Typedef,
1462 PDB_SymType::UDT};
1463 std::unique_ptr<IPDBEnumSymbols> results;
1464
1465 uint32_t matches = 0;
1466
1467 for (auto tag : tags_to_search) {
1468 results = m_global_scope_up->findAllChildren(tag);
1469 if (!results)
1470 continue;
1471
1472 while (auto result = results->getNext()) {
1473 if (max_matches > 0 && matches >= max_matches)
1474 break;
1475
1476 std::string type_name;
1477 if (auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(result.get()))
1478 type_name = enum_type->getName();
1479 else if (auto typedef_type =
1480 llvm::dyn_cast<PDBSymbolTypeTypedef>(result.get()))
1481 type_name = typedef_type->getName();
1482 else if (auto class_type = llvm::dyn_cast<PDBSymbolTypeUDT>(result.get()))
1483 type_name = class_type->getName();
1484 else {
1485 // We're looking only for types that have names. Skip symbols, as well
1486 // as unnamed types such as arrays, pointers, etc.
1487 continue;
1488 }
1489
1490 if (!regex.Execute(type_name))
1491 continue;
1492
1493 // This should cause the type to get cached and stored in the `m_types`
1494 // lookup.
1495 if (!ResolveTypeUID(result->getSymIndexId()))
1496 continue;
1497
1498 auto iter = m_types.find(result->getSymIndexId());
1499 if (iter == m_types.end())
1500 continue;
1501 types.Insert(iter->second);
1502 ++matches;
1503 }
1504 }
1505}
1506
1508 lldb_private::TypeResults &type_results) {
1509
1510 // Make sure we haven't already searched this SymbolFile before.
1511 if (type_results.AlreadySearched(this))
1512 return;
1513
1514 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1515
1516 std::unique_ptr<IPDBEnumSymbols> results;
1517 llvm::StringRef basename = query.GetTypeBasename().GetStringRef();
1518 if (basename.empty())
1519 return;
1520 results = m_global_scope_up->findAllChildren(PDB_SymType::None);
1521 if (!results)
1522 return;
1523
1524 while (auto result = results->getNext()) {
1525
1526 switch (result->getSymTag()) {
1527 case PDB_SymType::Enum:
1528 case PDB_SymType::UDT:
1529 case PDB_SymType::Typedef:
1530 break;
1531 default:
1532 // We're looking only for types that have names. Skip symbols, as well
1533 // as unnamed types such as arrays, pointers, etc.
1534 continue;
1535 }
1536
1538 result->getRawSymbol().getName()) != basename)
1539 continue;
1540
1541 // This should cause the type to get cached and stored in the `m_types`
1542 // lookup.
1543 if (!ResolveTypeUID(result->getSymIndexId()))
1544 continue;
1545
1546 auto iter = m_types.find(result->getSymIndexId());
1547 if (iter == m_types.end())
1548 continue;
1549 // We resolved a type. Get the fully qualified name to ensure it matches.
1550 ConstString name = iter->second->GetQualifiedName();
1551 TypeQuery type_match(name.GetStringRef(), TypeQueryOptions::e_exact_match);
1552 if (query.ContextMatches(type_match.GetContextRef())) {
1553 type_results.InsertUnique(iter->second);
1554 if (type_results.Done(query))
1555 return;
1556 }
1557 }
1558}
1559
1560void SymbolFilePDB::GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol,
1561 uint32_t type_mask,
1562 TypeCollection &type_collection) {
1563 bool can_parse = false;
1564 switch (pdb_symbol.getSymTag()) {
1565 case PDB_SymType::ArrayType:
1566 can_parse = ((type_mask & eTypeClassArray) != 0);
1567 break;
1568 case PDB_SymType::BuiltinType:
1569 can_parse = ((type_mask & eTypeClassBuiltin) != 0);
1570 break;
1571 case PDB_SymType::Enum:
1572 can_parse = ((type_mask & eTypeClassEnumeration) != 0);
1573 break;
1574 case PDB_SymType::Function:
1575 case PDB_SymType::FunctionSig:
1576 can_parse = ((type_mask & eTypeClassFunction) != 0);
1577 break;
1578 case PDB_SymType::PointerType:
1579 can_parse = ((type_mask & (eTypeClassPointer | eTypeClassBlockPointer |
1580 eTypeClassMemberPointer)) != 0);
1581 break;
1582 case PDB_SymType::Typedef:
1583 can_parse = ((type_mask & eTypeClassTypedef) != 0);
1584 break;
1585 case PDB_SymType::UDT: {
1586 auto *udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&pdb_symbol);
1587 assert(udt);
1588 can_parse = (udt->getUdtKind() != PDB_UdtType::Interface &&
1589 ((type_mask & (eTypeClassClass | eTypeClassStruct |
1590 eTypeClassUnion)) != 0));
1591 } break;
1592 default:
1593 break;
1594 }
1595
1596 if (can_parse) {
1597 if (auto *type = ResolveTypeUID(pdb_symbol.getSymIndexId())) {
1598 if (!llvm::is_contained(type_collection, type))
1599 type_collection.push_back(type);
1600 }
1601 }
1602
1603 auto results_up = pdb_symbol.findAllChildren();
1604 while (auto symbol_up = results_up->getNext())
1605 GetTypesForPDBSymbol(*symbol_up, type_mask, type_collection);
1606}
1607
1609 TypeClass type_mask,
1610 lldb_private::TypeList &type_list) {
1611 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1612 TypeCollection type_collection;
1613 CompileUnit *cu =
1614 sc_scope ? sc_scope->CalculateSymbolContextCompileUnit() : nullptr;
1615 if (cu) {
1616 auto compiland_up = GetPDBCompilandByUID(cu->GetID());
1617 if (!compiland_up)
1618 return;
1619 GetTypesForPDBSymbol(*compiland_up, type_mask, type_collection);
1620 } else {
1621 for (uint32_t cu_idx = 0; cu_idx < GetNumCompileUnits(); ++cu_idx) {
1622 auto cu_sp = ParseCompileUnitAtIndex(cu_idx);
1623 if (cu_sp) {
1624 if (auto compiland_up = GetPDBCompilandByUID(cu_sp->GetID()))
1625 GetTypesForPDBSymbol(*compiland_up, type_mask, type_collection);
1626 }
1627 }
1628 }
1629
1630 for (auto type : type_collection) {
1631 type->GetForwardCompilerType();
1632 type_list.Insert(type->shared_from_this());
1633 }
1634}
1635
1636llvm::Expected<lldb::TypeSystemSP>
1638 auto type_system_or_err =
1639 m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
1640 if (type_system_or_err) {
1641 if (auto ts = *type_system_or_err)
1642 ts->SetSymbolFile(this);
1643 }
1644 return type_system_or_err;
1645}
1646
1648 auto type_system_or_err =
1650 if (auto err = type_system_or_err.takeError()) {
1651 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1652 "Unable to get PDB AST parser: {0}");
1653 return nullptr;
1654 }
1655
1656 auto ts = *type_system_or_err;
1657 auto *clang_type_system =
1658 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
1659 if (!clang_type_system)
1660 return nullptr;
1661
1662 return clang_type_system->GetPDBParser();
1663}
1664
1667 const CompilerDeclContext &parent_decl_ctx, bool) {
1668 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1669 auto type_system_or_err =
1671 if (auto err = type_system_or_err.takeError()) {
1672 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
1673 "Unable to find namespace {1}: {0}", name.AsCString());
1674 return CompilerDeclContext();
1675 }
1676 auto ts = *type_system_or_err;
1677 auto *clang_type_system =
1678 llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
1679 if (!clang_type_system)
1680 return CompilerDeclContext();
1681
1682 PDBASTParser *pdb = clang_type_system->GetPDBParser();
1683 if (!pdb)
1684 return CompilerDeclContext();
1685
1686 clang::DeclContext *decl_context = nullptr;
1687 if (parent_decl_ctx)
1688 decl_context = static_cast<clang::DeclContext *>(
1689 parent_decl_ctx.GetOpaqueDeclContext());
1690
1691 auto namespace_decl =
1692 pdb->FindNamespaceDecl(decl_context, name.GetStringRef());
1693 if (!namespace_decl)
1694 return CompilerDeclContext();
1695
1696 return clang_type_system->CreateDeclContext(namespace_decl);
1697}
1698
1700
1701const IPDBSession &SymbolFilePDB::GetPDBSession() const {
1702 return *m_session_up;
1703}
1704
1706 uint32_t index) {
1707 auto found_cu = m_comp_units.find(id);
1708 if (found_cu != m_comp_units.end())
1709 return found_cu->second;
1710
1711 auto compiland_up = GetPDBCompilandByUID(id);
1712 if (!compiland_up)
1713 return CompUnitSP();
1714
1715 lldb::LanguageType lang;
1716 auto details = compiland_up->findOneChild<PDBSymbolCompilandDetails>();
1717 if (!details)
1719 else
1720 lang = TranslateLanguage(details->getLanguage());
1721
1723 return CompUnitSP();
1724
1725 std::string path = compiland_up->getSourceFileFullPath();
1726 if (path.empty())
1727 return CompUnitSP();
1728
1729 // Don't support optimized code for now, DebugInfoPDB does not return this
1730 // information.
1731 LazyBool optimized = eLazyBoolNo;
1732 auto cu_sp = std::make_shared<CompileUnit>(m_objfile_sp->GetModule(), nullptr,
1733 path.c_str(), id, lang, optimized);
1734
1735 if (!cu_sp)
1736 return CompUnitSP();
1737
1738 m_comp_units.insert(std::make_pair(id, cu_sp));
1739 if (index == UINT32_MAX)
1740 GetCompileUnitIndex(*compiland_up, index);
1741 lldbassert(index != UINT32_MAX);
1742 SetCompileUnitAtIndex(index, cu_sp);
1743 return cu_sp;
1744}
1745
1747 uint32_t match_line) {
1748 auto compiland_up = GetPDBCompilandByUID(comp_unit.GetID());
1749 if (!compiland_up)
1750 return false;
1751
1752 // LineEntry needs the *index* of the file into the list of support files
1753 // returned by ParseCompileUnitSupportFiles. But the underlying SDK gives us
1754 // a globally unique idenfitifier in the namespace of the PDB. So, we have
1755 // to do a mapping so that we can hand out indices.
1756 llvm::DenseMap<uint32_t, uint32_t> index_map;
1757 BuildSupportFileIdToSupportFileIndexMap(*compiland_up, index_map);
1758 auto line_table = std::make_unique<LineTable>(&comp_unit);
1759
1760 // Find contributions to `compiland` from all source and header files.
1761 auto files = m_session_up->getSourceFilesForCompiland(*compiland_up);
1762 if (!files)
1763 return false;
1764
1765 // For each source and header file, create a LineSequence for contributions
1766 // to the compiland from that file, and add the sequence.
1767 while (auto file = files->getNext()) {
1768 std::unique_ptr<LineSequence> sequence(
1769 line_table->CreateLineSequenceContainer());
1770 auto lines = m_session_up->findLineNumbers(*compiland_up, *file);
1771 if (!lines)
1772 continue;
1773 int entry_count = lines->getChildCount();
1774
1775 uint64_t prev_addr;
1776 uint32_t prev_length;
1777 uint32_t prev_line;
1778 uint32_t prev_source_idx;
1779
1780 for (int i = 0; i < entry_count; ++i) {
1781 auto line = lines->getChildAtIndex(i);
1782
1783 uint64_t lno = line->getLineNumber();
1784 uint64_t addr = line->getVirtualAddress();
1785 uint32_t length = line->getLength();
1786 uint32_t source_id = line->getSourceFileId();
1787 uint32_t col = line->getColumnNumber();
1788 uint32_t source_idx = index_map[source_id];
1789
1790 // There was a gap between the current entry and the previous entry if
1791 // the addresses don't perfectly line up.
1792 bool is_gap = (i > 0) && (prev_addr + prev_length < addr);
1793
1794 // Before inserting the current entry, insert a terminal entry at the end
1795 // of the previous entry's address range if the current entry resulted in
1796 // a gap from the previous entry.
1797 if (is_gap && ShouldAddLine(match_line, prev_line, prev_length)) {
1798 line_table->AppendLineEntryToSequence(
1799 sequence.get(), prev_addr + prev_length, prev_line, 0,
1800 prev_source_idx, false, false, false, false, true);
1801
1802 line_table->InsertSequence(sequence.get());
1803 sequence = line_table->CreateLineSequenceContainer();
1804 }
1805
1806 if (ShouldAddLine(match_line, lno, length)) {
1807 bool is_statement = line->isStatement();
1808 bool is_prologue = false;
1809 bool is_epilogue = false;
1810 auto func =
1811 m_session_up->findSymbolByAddress(addr, PDB_SymType::Function);
1812 if (func) {
1813 auto prologue = func->findOneChild<PDBSymbolFuncDebugStart>();
1814 if (prologue)
1815 is_prologue = (addr == prologue->getVirtualAddress());
1816
1817 auto epilogue = func->findOneChild<PDBSymbolFuncDebugEnd>();
1818 if (epilogue)
1819 is_epilogue = (addr == epilogue->getVirtualAddress());
1820 }
1821
1822 line_table->AppendLineEntryToSequence(sequence.get(), addr, lno, col,
1823 source_idx, is_statement, false,
1824 is_prologue, is_epilogue, false);
1825 }
1826
1827 prev_addr = addr;
1828 prev_length = length;
1829 prev_line = lno;
1830 prev_source_idx = source_idx;
1831 }
1832
1833 if (entry_count > 0 && ShouldAddLine(match_line, prev_line, prev_length)) {
1834 // The end is always a terminal entry, so insert it regardless.
1835 line_table->AppendLineEntryToSequence(
1836 sequence.get(), prev_addr + prev_length, prev_line, 0,
1837 prev_source_idx, false, false, false, false, true);
1838 }
1839
1840 line_table->InsertSequence(sequence.get());
1841 }
1842
1843 if (line_table->GetSize()) {
1844 comp_unit.SetLineTable(line_table.release());
1845 return true;
1846 }
1847 return false;
1848}
1849
1851 const PDBSymbolCompiland &compiland,
1852 llvm::DenseMap<uint32_t, uint32_t> &index_map) const {
1853 // This is a hack, but we need to convert the source id into an index into
1854 // the support files array. We don't want to do path comparisons to avoid
1855 // basename / full path issues that may or may not even be a problem, so we
1856 // use the globally unique source file identifiers. Ideally we could use the
1857 // global identifiers everywhere, but LineEntry currently assumes indices.
1858 auto source_files = m_session_up->getSourceFilesForCompiland(compiland);
1859 if (!source_files)
1860 return;
1861
1862 int index = 0;
1863 while (auto file = source_files->getNext()) {
1864 uint32_t source_id = file->getUniqueId();
1865 index_map[source_id] = index++;
1866 }
1867}
1868
1870 const lldb_private::Address &so_addr) {
1871 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1872 if (file_vm_addr == LLDB_INVALID_ADDRESS || file_vm_addr == 0)
1873 return nullptr;
1874
1875 // If it is a PDB function's vm addr, this is the first sure bet.
1876 if (auto lines =
1877 m_session_up->findLineNumbersByAddress(file_vm_addr, /*Length=*/1)) {
1878 if (auto first_line = lines->getNext())
1879 return ParseCompileUnitForUID(first_line->getCompilandId());
1880 }
1881
1882 // Otherwise we resort to section contributions.
1883 if (auto sec_contribs = m_session_up->getSectionContribs()) {
1884 while (auto section = sec_contribs->getNext()) {
1885 auto va = section->getVirtualAddress();
1886 if (file_vm_addr >= va && file_vm_addr < va + section->getLength())
1887 return ParseCompileUnitForUID(section->getCompilandId());
1888 }
1889 }
1890 return nullptr;
1891}
1892
1893Mangled
1894SymbolFilePDB::GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func) {
1895 Mangled mangled;
1896 auto func_name = pdb_func.getName();
1897 auto func_undecorated_name = pdb_func.getUndecoratedName();
1898 std::string func_decorated_name;
1899
1900 // Seek from public symbols for non-static function's decorated name if any.
1901 // For static functions, they don't have undecorated names and aren't exposed
1902 // in Public Symbols either.
1903 if (!func_undecorated_name.empty()) {
1904 auto result_up = m_global_scope_up->findChildren(
1905 PDB_SymType::PublicSymbol, func_undecorated_name,
1906 PDB_NameSearchFlags::NS_UndecoratedName);
1907 if (result_up) {
1908 while (auto symbol_up = result_up->getNext()) {
1909 // For a public symbol, it is unique.
1910 lldbassert(result_up->getChildCount() == 1);
1911 if (auto *pdb_public_sym =
1912 llvm::dyn_cast_or_null<PDBSymbolPublicSymbol>(
1913 symbol_up.get())) {
1914 if (pdb_public_sym->isFunction()) {
1915 func_decorated_name = pdb_public_sym->getName();
1916 break;
1917 }
1918 }
1919 }
1920 }
1921 }
1922 if (!func_decorated_name.empty()) {
1923 mangled.SetMangledName(ConstString(func_decorated_name));
1924
1925 // For MSVC, format of C function's decorated name depends on calling
1926 // convention. Unfortunately none of the format is recognized by current
1927 // LLDB. For example, `_purecall` is a __cdecl C function. From PDB,
1928 // `__purecall` is retrieved as both its decorated and undecorated name
1929 // (using PDBSymbolFunc::getUndecoratedName method). However `__purecall`
1930 // string is not treated as mangled in LLDB (neither `?` nor `_Z` prefix).
1931 // Mangled::GetDemangledName method will fail internally and caches an
1932 // empty string as its undecorated name. So we will face a contradiction
1933 // here for the same symbol:
1934 // non-empty undecorated name from PDB
1935 // empty undecorated name from LLDB
1936 if (!func_undecorated_name.empty() && mangled.GetDemangledName().IsEmpty())
1937 mangled.SetDemangledName(ConstString(func_undecorated_name));
1938
1939 // LLDB uses several flags to control how a C++ decorated name is
1940 // undecorated for MSVC. See `safeUndecorateName` in Class Mangled. So the
1941 // yielded name could be different from what we retrieve from
1942 // PDB source unless we also apply same flags in getting undecorated
1943 // name through PDBSymbolFunc::getUndecoratedNameEx method.
1944 if (!func_undecorated_name.empty() &&
1945 mangled.GetDemangledName() != ConstString(func_undecorated_name))
1946 mangled.SetDemangledName(ConstString(func_undecorated_name));
1947 } else if (!func_undecorated_name.empty()) {
1948 mangled.SetDemangledName(ConstString(func_undecorated_name));
1949 } else if (!func_name.empty())
1950 mangled.SetValue(ConstString(func_name));
1951
1952 return mangled;
1953}
1954
1956 const lldb_private::CompilerDeclContext &decl_ctx) {
1957 if (!decl_ctx.IsValid())
1958 return true;
1959
1960 TypeSystem *decl_ctx_type_system = decl_ctx.GetTypeSystem();
1961 if (!decl_ctx_type_system)
1962 return false;
1963 auto type_system_or_err = GetTypeSystemForLanguage(
1964 decl_ctx_type_system->GetMinimumLanguage(nullptr));
1965 if (auto err = type_system_or_err.takeError()) {
1967 GetLog(LLDBLog::Symbols), std::move(err),
1968 "Unable to determine if DeclContext matches this symbol file: {0}");
1969 return false;
1970 }
1971
1972 if (decl_ctx_type_system == type_system_or_err->get())
1973 return true; // The type systems match, return true
1974
1975 return false;
1976}
1977
1978uint32_t SymbolFilePDB::GetCompilandId(const llvm::pdb::PDBSymbolData &data) {
1979 static const auto pred_upper = [](uint32_t lhs, SecContribInfo rhs) {
1980 return lhs < rhs.Offset;
1981 };
1982
1983 // Cache section contributions
1984 if (m_sec_contribs.empty()) {
1985 if (auto SecContribs = m_session_up->getSectionContribs()) {
1986 while (auto SectionContrib = SecContribs->getNext()) {
1987 auto comp_id = SectionContrib->getCompilandId();
1988 if (!comp_id)
1989 continue;
1990
1991 auto sec = SectionContrib->getAddressSection();
1992 auto &sec_cs = m_sec_contribs[sec];
1993
1994 auto offset = SectionContrib->getAddressOffset();
1995 auto it = llvm::upper_bound(sec_cs, offset, pred_upper);
1996
1997 auto size = SectionContrib->getLength();
1998 sec_cs.insert(it, {offset, size, comp_id});
1999 }
2000 }
2001 }
2002
2003 // Check by line number
2004 if (auto Lines = data.getLineNumbers()) {
2005 if (auto FirstLine = Lines->getNext())
2006 return FirstLine->getCompilandId();
2007 }
2008
2009 // Retrieve section + offset
2010 uint32_t DataSection = data.getAddressSection();
2011 uint32_t DataOffset = data.getAddressOffset();
2012 if (DataSection == 0) {
2013 if (auto RVA = data.getRelativeVirtualAddress())
2014 m_session_up->addressForRVA(RVA, DataSection, DataOffset);
2015 }
2016
2017 if (DataSection) {
2018 // Search by section contributions
2019 auto &sec_cs = m_sec_contribs[DataSection];
2020 auto it = llvm::upper_bound(sec_cs, DataOffset, pred_upper);
2021 if (it != sec_cs.begin()) {
2022 --it;
2023 if (DataOffset < it->Offset + it->Size)
2024 return it->CompilandId;
2025 }
2026 } else {
2027 // Search in lexical tree
2028 auto LexParentId = data.getLexicalParentId();
2029 while (auto LexParent = m_session_up->getSymbolById(LexParentId)) {
2030 if (LexParent->getSymTag() == PDB_SymType::Exe)
2031 break;
2032 if (LexParent->getSymTag() == PDB_SymType::Compiland)
2033 return LexParentId;
2034 LexParentId = LexParent->getRawSymbol().getLexicalParentId();
2035 }
2036 }
2037
2038 return 0;
2039}
static llvm::raw_ostream & error(Stream &strm)
#define lldbassert(x)
Definition: LLDBAssert.h:15
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:392
DWARFExpression ConvertPDBLocationToDWARFExpression(ModuleSP module, const PDBSymbolData &symbol, const Variable::RangeList &ranges, bool &is_constant)
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:32
static lldb::LanguageType TranslateLanguage(PDB_Lang lang)
static size_t ParseFunctionBlocksForPDBSymbol(uint64_t func_file_vm_addr, const llvm::pdb::PDBSymbol *pdb_symbol, lldb_private::Block *parent_block, bool is_top_parent)
static bool ShouldUseNativeReader()
static llvm::StringRef DropScope(llvm::StringRef name)
clang::NamespaceDecl * FindNamespaceDecl(const clang::DeclContext *parent, llvm::StringRef name)
lldb::TypeSP CreateLLDBTypeFromPDBType(const llvm::pdb::PDBSymbol &type)
clang::DeclContext * GetDeclContextForSymbol(const llvm::pdb::PDBSymbol &symbol)
void ParseDeclsForDeclContext(const clang::DeclContext *decl_context)
bool CompleteTypeFromPDB(lldb_private::CompilerType &compiler_type)
clang::Decl * GetDeclForSymbol(const llvm::pdb::PDBSymbol &symbol)
clang::DeclContext * GetDeclContextContainingSymbol(const llvm::pdb::PDBSymbol &symbol)
lldb_private::CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override
std::unique_ptr< llvm::pdb::PDBSymbolCompiland > GetPDBCompilandByUID(uint32_t uid)
static lldb_private::SymbolFile * CreateInstance(lldb::ObjectFileSP objfile_sp)
std::unique_ptr< llvm::pdb::IPDBSession > m_session_up
lldb::CompUnitSP GetCompileUnitContainsAddress(const lldb_private::Address &so_addr)
void GetMangledNamesForFunction(const std::string &scope_qualified_name, std::vector< lldb_private::ConstString > &mangled_names) override
void GetTypes(lldb_private::SymbolContextScope *sc_scope, lldb::TypeClass type_mask, lldb_private::TypeList &type_list) override
void FindFunctions(const lldb_private::Module::LookupInfo &lookup_info, const lldb_private::CompilerDeclContext &parent_decl_ctx, bool include_inlines, lldb_private::SymbolContextList &sc_list) override
lldb_private::CompilerDeclContext FindNamespace(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, bool only_root_namespaces) override
Finds a namespace of name name and whose parent context is parent_decl_ctx.
std::unique_ptr< llvm::pdb::PDBSymbolExe > m_global_scope_up
llvm::DenseMap< uint32_t, lldb::CompUnitSP > m_comp_units
std::optional< ArrayInfo > GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) override
If type_uid points to an array type, return its characteristics.
size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override
static llvm::StringRef GetPluginNameStatic()
Definition: SymbolFilePDB.h:45
bool ParseCompileUnitLineTable(lldb_private::CompileUnit &comp_unit, uint32_t match_line)
void BuildSupportFileIdToSupportFileIndexMap(const llvm::pdb::PDBSymbolCompiland &pdb_compiland, llvm::DenseMap< uint32_t, uint32_t > &index_map) const
lldb_private::Function * ParseCompileUnitFunctionForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func, lldb_private::CompileUnit &comp_unit)
lldb_private::UniqueCStringMap< uint32_t > m_func_base_names
bool ParseImportedModules(const lldb_private::SymbolContext &sc, std::vector< lldb_private::SourceModule > &imported_modules) override
void FindGlobalVariables(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, lldb_private::VariableList &variables) override
size_t ParseVariablesForContext(const lldb_private::SymbolContext &sc) override
static void Initialize()
bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override
void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland &pdb_compiland, uint32_t &index)
llvm::DenseMap< uint32_t, lldb::TypeSP > m_types
void AddSymbols(lldb_private::Symtab &symtab) override
size_t ParseBlocksRecursive(lldb_private::Function &func) override
void CacheFunctionNames()
llvm::DenseMap< uint64_t, std::string > m_public_names
size_t ParseVariables(const lldb_private::SymbolContext &sc, const llvm::pdb::PDBSymbol &pdb_data, lldb_private::VariableList *variable_list=nullptr)
lldb::LanguageType ParseLanguage(lldb_private::CompileUnit &comp_unit) override
bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override
void InitializeObject() override
Initialize the SymbolFile object.
uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, lldb::SymbolContextItem resolve_scope, lldb_private::SymbolContext &sc) override
PDBASTParser * GetPDBAstParser()
uint32_t CalculateNumCompileUnits() override
SymbolFilePDB(lldb::ObjectFileSP objfile_sp)
~SymbolFilePDB() override
uint32_t GetCompilandId(const llvm::pdb::PDBSymbolData &data)
llvm::pdb::IPDBSession & GetPDBSession()
bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, lldb_private::SupportFileList &support_files) override
static char ID
LLVM RTTI support.
Definition: SymbolFilePDB.h:27
void FindTypesByRegex(const lldb_private::RegularExpression &regex, uint32_t max_matches, lldb_private::TypeMap &types)
size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override
lldb::CompUnitSP ParseCompileUnitForUID(uint32_t id, uint32_t index=UINT32_MAX)
lldb_private::Mangled GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func)
std::vector< lldb_private::Type * > TypeCollection
void ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override
void DumpClangAST(lldb_private::Stream &s) override
void GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol, uint32_t type_mask, TypeCollection &type_collection)
bool CompleteType(lldb_private::CompilerType &compiler_type) override
static void DebuggerInitialize(lldb_private::Debugger &debugger)
static llvm::StringRef GetPluginDescriptionStatic()
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
std::string GetMangledForPDBData(const llvm::pdb::PDBSymbolData &pdb_data)
lldb_private::Type * ResolveTypeUID(lldb::user_id_t type_uid) override
lldb_private::UniqueCStringMap< uint32_t > m_func_full_names
static void Terminate()
lldb_private::UniqueCStringMap< uint32_t > m_func_method_names
bool DeclContextMatchesThisSymbolFile(const lldb_private::CompilerDeclContext &decl_ctx)
lldb_private::CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
void FindTypes(const lldb_private::TypeQuery &match, lldb_private::TypeResults &results) override
Find types using a type-matching object that contains all search parameters.
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
SecContribsMap m_sec_contribs
lldb::VariableSP ParseVariableForPDBData(const lldb_private::SymbolContext &sc, const llvm::pdb::PDBSymbolData &pdb_data)
bool ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func, bool include_inlines, lldb_private::SymbolContextList &sc_list)
uint32_t CalculateAbilities() override
llvm::DenseMap< uint32_t, lldb::VariableSP > m_variables
lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override
A section + offset based address range class.
Definition: AddressRange.h:25
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:211
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
Definition: AddressRange.h:223
A section + offset based address class.
Definition: Address.h:62
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:293
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:355
A class that describes a single lexical block.
Definition: Block.h:41
lldb::VariableListSP GetBlockVariableList(bool can_create)
Get the variable list for this block only.
Definition: Block.cpp:407
bool GetRangeAtIndex(uint32_t range_idx, AddressRange &range)
Definition: Block.cpp:297
lldb::BlockSP CreateChild(lldb::user_id_t uid)
Creates a block with the specified UID uid.
Definition: Block.cpp:395
Block * FindBlockByID(lldb::user_id_t block_id)
Definition: Block.cpp:114
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
Definition: Block.h:317
size_t GetNumRanges() const
Definition: Block.h:329
void SetDidParseVariables(bool b, bool set_children)
Definition: Block.cpp:504
void AddRange(const Range &range)
Add a new offset range to this block.
Definition: Block.cpp:345
void FinalizeRanges()
Definition: Block.cpp:340
static bool IsCPPMangledName(llvm::StringRef name)
A class that describes a compilation unit.
Definition: CompileUnit.h:43
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
lldb::VariableListSP GetVariableList(bool can_create)
Get the variable list for a compile unit.
void SetLineTable(LineTable *line_table)
Set the line table for the compile unit.
void AddFunction(lldb::FunctionSP &function_sp)
Add a function to this compile unit.
lldb::FunctionSP FindFunctionByUID(lldb::user_id_t uid)
Finds a function by user ID.
LineTable * GetLineTable()
Get the line table for the compile unit.
Represents a generic declaration context in a program.
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:304
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:197
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
A class to manage flag bits.
Definition: Debugger.h:80
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
void SetLine(uint32_t line)
Set accessor for the declaration line number.
Definition: Declaration.h:172
void SetColumn(uint16_t column)
Set accessor for the declaration column number.
Definition: Declaration.h:179
void SetFile(const FileSpec &file_spec)
Set accessor for the declaration file specification.
Definition: Declaration.h:165
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file utility class.
Definition: FileSpec.h:56
const ConstString & GetDirectory() const
Directory string const get accessor.
Definition: FileSpec.h:223
static int Compare(const FileSpec &lhs, const FileSpec &rhs, bool full)
Compare two FileSpec objects.
Definition: FileSpec.cpp:273
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:367
A class that describes a function.
Definition: Function.h:399
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition: Function.cpp:396
A class that handles mangled names.
Definition: Mangled.h:33
void SetDemangledName(ConstString name)
Definition: Mangled.h:137
ConstString GetDemangledName() const
Demangled name get accessor.
Definition: Mangled.cpp:270
void SetMangledName(ConstString name)
Definition: Mangled.h:139
void SetValue(ConstString name)
Set the string value in this object.
Definition: Mangled.cpp:120
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:24
A class that encapsulates name lookup information.
Definition: Module.h:907
lldb::FunctionNameType GetNameTypeMask() const
Definition: Module.h:922
ConstString GetLookupName() const
Definition: Module.h:918
ConstString GetName() const
Definition: Module.h:914
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
void Append(const Entry &entry)
Definition: RangeMap.h:179
bool IsValid() const
Test if this object contains a valid regular expression.
bool Execute(llvm::StringRef string, llvm::SmallVectorImpl< llvm::StringRef > *matches=nullptr) const
Execute a regular expression match using the compiled regular expression that is already in this obje...
"lldb/Core/SourceLocationSpec.h" A source location specifier class.
std::optional< uint32_t > GetLine() const
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition: Stream.h:401
A list of support files for a CompileUnit.
Definition: FileSpecList.h:23
bool AppendIfUnique(const FileSpec &file)
Defines a list of symbol context objects.
uint32_t GetSize() const
Get accessor for a symbol context list size.
void Append(const SymbolContext &sc)
Append a new symbol context to the list.
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
virtual CompileUnit * CalculateSymbolContextCompileUnit()
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
Function * function
The Function for a given query.
Block * block
The Block for a given query.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
LineEntry line_entry
The LineEntry for a given query.
Containing protected virtual methods for child classes to override.
Definition: SymbolFile.h:507
ObjectFile * GetObjectFile() override
Definition: SymbolFile.h:536
lldb::ObjectFileSP m_objfile_sp
Definition: SymbolFile.h:612
void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp)
Definition: SymbolFile.cpp:203
uint32_t GetNumCompileUnits() override
Definition: SymbolFile.cpp:182
Provides public interface for all SymbolFiles.
Definition: SymbolFile.h:50
virtual std::recursive_mutex & GetModuleMutex() const
Symbols file subclasses should override this to return the Module that owns the TypeSystem that this ...
Definition: SymbolFile.cpp:36
lldb::addr_t GetFileAddress() const
Definition: Symbol.cpp:534
Symbol * SymbolAtIndex(size_t idx)
Definition: Symtab.cpp:228
uint32_t AddSymbol(const Symbol &symbol)
Definition: Symtab.cpp:64
size_t GetNumSymbols() const
Definition: Symtab.cpp:77
void Insert(const lldb::TypeSP &type)
Definition: TypeList.cpp:27
void Insert(const lldb::TypeSP &type)
Definition: TypeMap.cpp:27
A class that contains all state required for type lookups.
Definition: Type.h:104
std::vector< lldb_private::CompilerContext > & GetContextRef()
Access the internal compiler context array.
Definition: Type.h:322
ConstString GetTypeBasename() const
Get the type basename to use when searching the type indexes in each SymbolFile object.
Definition: Type.cpp:112
bool ContextMatches(llvm::ArrayRef< lldb_private::CompilerContext > context) const
Check of a CompilerContext array from matching type from a symbol file matches the m_context.
Definition: Type.cpp:128
This class tracks the state and results of a TypeQuery.
Definition: Type.h:344
bool InsertUnique(const lldb::TypeSP &type_sp)
When types that match a TypeQuery are found, this API is used to insert the matching types.
Definition: Type.cpp:193
bool Done(const TypeQuery &query) const
Check if the type matching has found all of the matches that it needs.
Definition: Type.cpp:199
bool AlreadySearched(lldb_private::SymbolFile *sym_file)
Check if a SymbolFile object has already been searched by this type match object.
Definition: Type.cpp:189
A TypeSystem implementation based on Clang.
CompilerDecl GetCompilerDecl(clang::Decl *decl)
Creates a CompilerDecl from the given Decl with the current TypeSystemClang instance as its typesyste...
void Dump(llvm::raw_ostream &output) override
CompilerDeclContext CreateDeclContext(clang::DeclContext *ctx)
Creates a CompilerDeclContext from the given DeclContext with the current TypeSystemClang instance as...
PDBASTParser * GetPDBParser() override
Interface for representing a type system.
Definition: TypeSystem.h:70
virtual lldb::LanguageType GetMinimumLanguage(lldb::opaque_compiler_type_t type)=0
void Append(ConstString unique_cstr, const T &value)
bool AddVariableIfUnique(const lldb::VariableSP &var_sp)
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
#define UINT32_MAX
Definition: lldb-defines.h:19
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:332
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Function > FunctionSP
Definition: lldb-forward.h:355
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
Definition: lldb-forward.h:375
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eLanguageTypeRust
Rust.
@ eLanguageTypeObjC_plus_plus
Objective-C++.
@ eLanguageTypeSwift
Swift.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eLanguageTypeObjC
Objective-C.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
std::shared_ptr< lldb_private::Type > TypeSP
Definition: lldb-forward.h:461
std::shared_ptr< lldb_private::VariableList > VariableListSP
Definition: lldb-forward.h:487
std::shared_ptr< lldb_private::SymbolFileType > SymbolFileTypeSP
Definition: lldb-forward.h:441
std::shared_ptr< lldb_private::Variable > VariableSP
Definition: lldb-forward.h:486
uint64_t user_id_t
Definition: lldb-types.h:82
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
Definition: lldb-forward.h:335
@ eValueTypeInvalid
@ eValueTypeVariableGlobal
globals variable
@ eValueTypeConstResult
constant result variables
@ eValueTypeVariableLocal
function local variables
@ eValueTypeVariableArgument
function argument variables
@ eValueTypeVariableStatic
static variable
@ eValueTypeVariableThreadLocal
thread local storage variable
AddressRange range
The section offset address range for this line entry.
Definition: LineEntry.h:137
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47