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