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