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