LLDB mainline
SymbolFileNativePDB.cpp
Go to the documentation of this file.
1//===-- SymbolFileNativePDB.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
10
15#include "lldb/Core/Module.h"
25#include "lldb/Utility/Log.h"
26
27#include "llvm/DebugInfo/CodeView/CVRecord.h"
28#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
29#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
30#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
31#include "llvm/DebugInfo/CodeView/RecordName.h"
32#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
33#include "llvm/DebugInfo/CodeView/SymbolRecordHelpers.h"
34#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
35#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
36#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
37#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
38#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
39#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
40#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
41#include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
42#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
43#include "llvm/DebugInfo/PDB/PDB.h"
44#include "llvm/DebugInfo/PDB/PDBTypes.h"
45#include "llvm/Demangle/MicrosoftDemangle.h"
46#include "llvm/Object/COFF.h"
47#include "llvm/Support/Allocator.h"
48#include "llvm/Support/BinaryStreamReader.h"
49#include "llvm/Support/Error.h"
50#include "llvm/Support/ErrorOr.h"
51#include "llvm/Support/MemoryBuffer.h"
52
54#include "PdbSymUid.h"
55#include "PdbUtil.h"
56#include "UdtRecordCompleter.h"
57#include <optional>
58#include <string_view>
59
60using namespace lldb;
61using namespace lldb_private;
62using namespace npdb;
63using namespace llvm::codeview;
64using namespace llvm::pdb;
65
67
69 switch (lang) {
70 case PDB_Lang::Cpp:
72 case PDB_Lang::C:
74 case PDB_Lang::Swift:
76 case PDB_Lang::Rust:
78 case PDB_Lang::ObjC:
80 case PDB_Lang::ObjCpp:
82 default:
84 }
85}
86
87static std::unique_ptr<PDBFile>
88loadMatchingPDBFile(std::string exe_path, llvm::BumpPtrAllocator &allocator) {
89 // Try to find a matching PDB for an EXE.
90 using namespace llvm::object;
91 auto expected_binary = createBinary(exe_path);
92
93 // If the file isn't a PE/COFF executable, fail.
94 if (!expected_binary) {
95 llvm::consumeError(expected_binary.takeError());
96 return nullptr;
97 }
98 OwningBinary<Binary> binary = std::move(*expected_binary);
99
100 // TODO: Avoid opening the PE/COFF binary twice by reading this information
101 // directly from the lldb_private::ObjectFile.
102 auto *obj = llvm::dyn_cast<llvm::object::COFFObjectFile>(binary.getBinary());
103 if (!obj)
104 return nullptr;
105 const llvm::codeview::DebugInfo *pdb_info = nullptr;
106
107 // If it doesn't have a debug directory, fail.
108 llvm::StringRef pdb_file;
109 if (llvm::Error e = obj->getDebugPDBInfo(pdb_info, pdb_file)) {
110 consumeError(std::move(e));
111 return nullptr;
112 }
113
114 // If the file doesn't exist, perhaps the path specified at build time
115 // doesn't match the PDB's current location, so check the location of the
116 // executable.
117 if (!FileSystem::Instance().Exists(pdb_file)) {
118 const auto exe_dir = FileSpec(exe_path).CopyByRemovingLastPathComponent();
119 const auto pdb_name = FileSpec(pdb_file).GetFilename().GetCString();
120 pdb_file = exe_dir.CopyByAppendingPathComponent(pdb_name).GetPathAsConstString().GetStringRef();
121 }
122
123 // If the file is not a PDB or if it doesn't have a matching GUID, fail.
124 auto pdb = ObjectFilePDB::loadPDBFile(std::string(pdb_file), allocator);
125 if (!pdb)
126 return nullptr;
127
128 auto expected_info = pdb->getPDBInfoStream();
129 if (!expected_info) {
130 llvm::consumeError(expected_info.takeError());
131 return nullptr;
132 }
133 llvm::codeview::GUID guid;
134 memcpy(&guid, pdb_info->PDB70.Signature, 16);
135
136 if (expected_info->getGuid() != guid)
137 return nullptr;
138 return pdb;
139}
140
142 lldb::addr_t addr) {
143 // FIXME: Implement this.
144 return false;
145}
146
148 lldb::addr_t addr) {
149 // FIXME: Implement this.
150 return false;
151}
152
153static llvm::StringRef GetSimpleTypeName(SimpleTypeKind kind) {
154 switch (kind) {
155 case SimpleTypeKind::Boolean128:
156 case SimpleTypeKind::Boolean16:
157 case SimpleTypeKind::Boolean32:
158 case SimpleTypeKind::Boolean64:
159 case SimpleTypeKind::Boolean8:
160 return "bool";
161 case SimpleTypeKind::Byte:
162 case SimpleTypeKind::UnsignedCharacter:
163 return "unsigned char";
164 case SimpleTypeKind::NarrowCharacter:
165 return "char";
166 case SimpleTypeKind::SignedCharacter:
167 case SimpleTypeKind::SByte:
168 return "signed char";
169 case SimpleTypeKind::Character16:
170 return "char16_t";
171 case SimpleTypeKind::Character32:
172 return "char32_t";
173 case SimpleTypeKind::Character8:
174 return "char8_t";
175 case SimpleTypeKind::Complex80:
176 case SimpleTypeKind::Complex64:
177 case SimpleTypeKind::Complex32:
178 return "complex";
179 case SimpleTypeKind::Float128:
180 case SimpleTypeKind::Float80:
181 return "long double";
182 case SimpleTypeKind::Float64:
183 return "double";
184 case SimpleTypeKind::Float32:
185 return "float";
186 case SimpleTypeKind::Float16:
187 return "single";
188 case SimpleTypeKind::Int128:
189 return "__int128";
190 case SimpleTypeKind::Int64:
191 case SimpleTypeKind::Int64Quad:
192 return "int64_t";
193 case SimpleTypeKind::Int32:
194 return "int";
195 case SimpleTypeKind::Int16:
196 return "short";
197 case SimpleTypeKind::UInt128:
198 return "unsigned __int128";
199 case SimpleTypeKind::UInt64:
200 case SimpleTypeKind::UInt64Quad:
201 return "uint64_t";
202 case SimpleTypeKind::HResult:
203 return "HRESULT";
204 case SimpleTypeKind::UInt32:
205 return "unsigned";
206 case SimpleTypeKind::UInt16:
207 case SimpleTypeKind::UInt16Short:
208 return "unsigned short";
209 case SimpleTypeKind::Int32Long:
210 return "long";
211 case SimpleTypeKind::UInt32Long:
212 return "unsigned long";
213 case SimpleTypeKind::Void:
214 return "void";
215 case SimpleTypeKind::WideCharacter:
216 return "wchar_t";
217 default:
218 return "";
219 }
220}
221
222static bool IsClassRecord(TypeLeafKind kind) {
223 switch (kind) {
224 case LF_STRUCTURE:
225 case LF_CLASS:
226 case LF_INTERFACE:
227 return true;
228 default:
229 return false;
230 }
231}
232
233static std::optional<CVTagRecord>
234GetNestedTagDefinition(const NestedTypeRecord &Record,
235 const CVTagRecord &parent, TpiStream &tpi) {
236 // An LF_NESTTYPE is essentially a nested typedef / using declaration, but it
237 // is also used to indicate the primary definition of a nested class. That is
238 // to say, if you have:
239 // struct A {
240 // struct B {};
241 // using C = B;
242 // };
243 // Then in the debug info, this will appear as:
244 // LF_STRUCTURE `A::B` [type index = N]
245 // LF_STRUCTURE `A`
246 // LF_NESTTYPE [name = `B`, index = N]
247 // LF_NESTTYPE [name = `C`, index = N]
248 // In order to accurately reconstruct the decl context hierarchy, we need to
249 // know which ones are actual definitions and which ones are just aliases.
250
251 // If it's a simple type, then this is something like `using foo = int`.
252 if (Record.Type.isSimple())
253 return std::nullopt;
254
255 CVType cvt = tpi.getType(Record.Type);
256
257 if (!IsTagRecord(cvt))
258 return std::nullopt;
259
260 // If it's an inner definition, then treat whatever name we have here as a
261 // single component of a mangled name. So we can inject it into the parent's
262 // mangled name to see if it matches.
263 CVTagRecord child = CVTagRecord::create(cvt);
264 std::string qname = std::string(parent.asTag().getUniqueName());
265 if (qname.size() < 4 || child.asTag().getUniqueName().size() < 4)
266 return std::nullopt;
267
268 // qname[3] is the tag type identifier (struct, class, union, etc). Since the
269 // inner tag type is not necessarily the same as the outer tag type, re-write
270 // it to match the inner tag type.
271 qname[3] = child.asTag().getUniqueName()[3];
272 std::string piece;
273 if (qname[3] == 'W')
274 piece = "4";
275 piece += Record.Name;
276 piece.push_back('@');
277 qname.insert(4, std::move(piece));
278 if (qname != child.asTag().UniqueName)
279 return std::nullopt;
280
281 return std::move(child);
282}
283
288}
289
292}
293
295
297 return "Microsoft PDB debug symbol cross-platform file reader.";
298}
299
301 return new SymbolFileNativePDB(std::move(objfile_sp));
302}
303
305 : SymbolFileCommon(std::move(objfile_sp)) {}
306
308
310 uint32_t abilities = 0;
311 if (!m_objfile_sp)
312 return 0;
313
314 if (!m_index) {
315 // Lazily load and match the PDB file, but only do this once.
316 PDBFile *pdb_file;
317 if (auto *pdb = llvm::dyn_cast<ObjectFilePDB>(m_objfile_sp.get())) {
318 pdb_file = &pdb->GetPDBFile();
319 } else {
320 m_file_up = loadMatchingPDBFile(m_objfile_sp->GetFileSpec().GetPath(),
322 pdb_file = m_file_up.get();
323 }
324
325 if (!pdb_file)
326 return 0;
327
328 auto expected_index = PdbIndex::create(pdb_file);
329 if (!expected_index) {
330 llvm::consumeError(expected_index.takeError());
331 return 0;
332 }
333 m_index = std::move(*expected_index);
334 }
335 if (!m_index)
336 return 0;
337
338 // We don't especially have to be precise here. We only distinguish between
339 // stripped and not stripped.
340 abilities = kAllAbilities;
341
342 if (m_index->dbi().isStripped())
343 abilities &= ~(Blocks | LocalVariables);
344 return abilities;
345}
346
348 m_obj_load_address = m_objfile_sp->GetModule()
349 ->GetObjectFile()
350 ->GetBaseAddress()
351 .GetFileAddress();
352 m_index->SetLoadAddress(m_obj_load_address);
353 m_index->ParseSectionContribs();
354
355 auto ts_or_err = m_objfile_sp->GetModule()->GetTypeSystemForLanguage(
357 if (auto err = ts_or_err.takeError()) {
358 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
359 "Failed to initialize: {0}");
360 } else {
361 if (auto ts = *ts_or_err)
362 ts->SetSymbolFile(this);
364 }
365}
366
368 const DbiModuleList &modules = m_index->dbi().modules();
369 uint32_t count = modules.getModuleCount();
370 if (count == 0)
371 return count;
372
373 // The linker can inject an additional "dummy" compilation unit into the
374 // PDB. Ignore this special compile unit for our purposes, if it is there.
375 // It is always the last one.
376 DbiModuleDescriptor last = modules.getModuleDescriptor(count - 1);
377 if (last.getModuleName() == "* Linker *")
378 --count;
379 return count;
380}
381
383 CompilandIndexItem *cii = m_index->compilands().GetCompiland(block_id.modi);
384 CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(block_id.offset);
385 CompUnitSP comp_unit = GetOrCreateCompileUnit(*cii);
386 lldb::user_id_t opaque_block_uid = toOpaqueUid(block_id);
387 auto ts_or_err = GetTypeSystemForLanguage(comp_unit->GetLanguage());
388 if (auto err = ts_or_err.takeError())
389 return nullptr;
390 auto ts = *ts_or_err;
391 if (!ts)
392 return nullptr;
393 PdbAstBuilder* ast_builder = ts->GetNativePDBParser();
394
395 switch (sym.kind()) {
396 case S_GPROC32:
397 case S_LPROC32:
398 // This is a function. It must be global. Creating the Function entry
399 // for it automatically creates a block for it.
400 if (FunctionSP func = GetOrCreateFunction(block_id, *comp_unit))
401 return &func->GetBlock(false);
402 break;
403 case S_BLOCK32: {
404 // This is a block. Its parent is either a function or another block. In
405 // either case, its parent can be viewed as a block (e.g. a function
406 // contains 1 big block. So just get the parent block and add this block
407 // to it.
408 BlockSym block(static_cast<SymbolRecordKind>(sym.kind()));
409 cantFail(SymbolDeserializer::deserializeAs<BlockSym>(sym, block));
410 lldbassert(block.Parent != 0);
411 PdbCompilandSymId parent_id(block_id.modi, block.Parent);
412 Block *parent_block = GetOrCreateBlock(parent_id);
413 if (!parent_block)
414 return nullptr;
415 Function *func = parent_block->CalculateSymbolContextFunction();
416 lldbassert(func);
417 lldb::addr_t block_base =
418 m_index->MakeVirtualAddress(block.Segment, block.CodeOffset);
419 lldb::addr_t func_base =
421 BlockSP child_block = parent_block->CreateChild(opaque_block_uid);
422 if (block_base >= func_base)
423 child_block->AddRange(Block::Range(block_base - func_base, block.CodeSize));
424 else {
425 GetObjectFile()->GetModule()->ReportError(
426 "S_BLOCK32 at modi: {0:d} offset: {1:d}: adding range "
427 "[{2:x16}-{3:x16}) which has a base that is less than the "
428 "function's "
429 "low PC 0x%" PRIx64 ". Please file a bug and attach the file at the "
430 "start of this error message",
431 block_id.modi, block_id.offset, block_base,
432 block_base + block.CodeSize, func_base);
433 }
434 ast_builder->GetOrCreateBlockDecl(block_id);
435 m_blocks.insert({opaque_block_uid, child_block});
436 break;
437 }
438 case S_INLINESITE: {
439 // This ensures line table is parsed first so we have inline sites info.
440 comp_unit->GetLineTable();
441
442 std::shared_ptr<InlineSite> inline_site = m_inline_sites[opaque_block_uid];
443 Block *parent_block = GetOrCreateBlock(inline_site->parent_id);
444 if (!parent_block)
445 return nullptr;
446 BlockSP child_block = parent_block->CreateChild(opaque_block_uid);
447 ast_builder->GetOrCreateInlinedFunctionDecl(block_id);
448 // Copy ranges from InlineSite to Block.
449 for (size_t i = 0; i < inline_site->ranges.GetSize(); ++i) {
450 auto *entry = inline_site->ranges.GetEntryAtIndex(i);
451 child_block->AddRange(
452 Block::Range(entry->GetRangeBase(), entry->GetByteSize()));
453 }
454 child_block->FinalizeRanges();
455
456 // Get the inlined function callsite info.
457 Declaration &decl = inline_site->inline_function_info->GetDeclaration();
458 Declaration &callsite = inline_site->inline_function_info->GetCallSite();
459 child_block->SetInlinedFunctionInfo(
460 inline_site->inline_function_info->GetName().GetCString(), nullptr,
461 &decl, &callsite);
462 m_blocks.insert({opaque_block_uid, child_block});
463 break;
464 }
465 default:
466 lldbassert(false && "Symbol is not a block!");
467 }
468
469 return nullptr;
470}
471
473 CompileUnit &comp_unit) {
474 const CompilandIndexItem *cci =
475 m_index->compilands().GetCompiland(func_id.modi);
476 lldbassert(cci);
477 CVSymbol sym_record = cci->m_debug_stream.readSymbolAtOffset(func_id.offset);
478
479 lldbassert(sym_record.kind() == S_LPROC32 || sym_record.kind() == S_GPROC32);
481
482 auto file_vm_addr =
483 m_index->MakeVirtualAddress(sol.so.segment, sol.so.offset);
484 if (file_vm_addr == LLDB_INVALID_ADDRESS || file_vm_addr == 0)
485 return nullptr;
486
487 AddressRange func_range(file_vm_addr, sol.length,
488 comp_unit.GetModule()->GetSectionList());
489 if (!func_range.GetBaseAddress().IsValid())
490 return nullptr;
491
492 ProcSym proc(static_cast<SymbolRecordKind>(sym_record.kind()));
493 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc));
494 if (proc.FunctionType == TypeIndex::None())
495 return nullptr;
496 TypeSP func_type = GetOrCreateType(proc.FunctionType);
497 if (!func_type)
498 return nullptr;
499
500 PdbTypeSymId sig_id(proc.FunctionType, false);
501 Mangled mangled(proc.Name);
502 FunctionSP func_sp = std::make_shared<Function>(
503 &comp_unit, toOpaqueUid(func_id), toOpaqueUid(sig_id), mangled,
504 func_type.get(), AddressRanges{func_range});
505
506 comp_unit.AddFunction(func_sp);
507
508 auto ts_or_err = GetTypeSystemForLanguage(comp_unit.GetLanguage());
509 if (auto err = ts_or_err.takeError())
510 return func_sp;
511 auto ts = *ts_or_err;
512 if (!ts)
513 return func_sp;
514 ts->GetNativePDBParser()->GetOrCreateFunctionDecl(func_id);
515
516 return func_sp;
517}
518
521 lldb::LanguageType lang =
522 cci.m_compile_opts ? TranslateLanguage(cci.m_compile_opts->getLanguage())
524
525 LazyBool optimized = eLazyBoolNo;
526 if (cci.m_compile_opts && cci.m_compile_opts->hasOptimizations())
527 optimized = eLazyBoolYes;
528
529 llvm::SmallString<64> source_file_name =
530 m_index->compilands().GetMainSourceFile(cci);
531 FileSpec fs(llvm::sys::path::convert_to_slash(
532 source_file_name, llvm::sys::path::Style::windows_backslash));
533
534 CompUnitSP cu_sp = std::make_shared<CompileUnit>(
535 m_objfile_sp->GetModule(), nullptr, std::make_shared<SupportFile>(fs),
536 toOpaqueUid(cci.m_id), lang, optimized);
537
538 SetCompileUnitAtIndex(cci.m_id.modi, cu_sp);
539 return cu_sp;
540}
541
543 const ModifierRecord &mr,
544 CompilerType ct) {
545 TpiStream &stream = m_index->tpi();
546
547 std::string name;
548 if (mr.ModifiedType.isSimple())
549 name = std::string(GetSimpleTypeName(mr.ModifiedType.getSimpleKind()));
550 else
551 name = computeTypeName(stream.typeCollection(), mr.ModifiedType);
552 Declaration decl;
553 lldb::TypeSP modified_type = GetOrCreateType(mr.ModifiedType);
554
555 return MakeType(toOpaqueUid(type_id), ConstString(name),
556 modified_type->GetByteSize(nullptr), nullptr,
559}
560
563 const llvm::codeview::PointerRecord &pr,
564 CompilerType ct) {
565 TypeSP pointee = GetOrCreateType(pr.ReferentType);
566 if (!pointee)
567 return nullptr;
568
569 if (pr.isPointerToMember()) {
570 MemberPointerInfo mpi = pr.getMemberInfo();
571 GetOrCreateType(mpi.ContainingType);
572 }
573
574 Declaration decl;
575 return MakeType(toOpaqueUid(type_id), ConstString(), pr.getSize(), nullptr,
578}
579
581 CompilerType ct) {
582 uint64_t uid = toOpaqueUid(PdbTypeSymId(ti, false));
583 if (ti == TypeIndex::NullptrT()) {
584 Declaration decl;
585 return MakeType(uid, ConstString("std::nullptr_t"), 0, nullptr,
588 }
589
590 if (ti.getSimpleMode() != SimpleTypeMode::Direct) {
591 TypeSP direct_sp = GetOrCreateType(ti.makeDirect());
592 uint32_t pointer_size = 0;
593 switch (ti.getSimpleMode()) {
594 case SimpleTypeMode::FarPointer32:
595 case SimpleTypeMode::NearPointer32:
596 pointer_size = 4;
597 break;
598 case SimpleTypeMode::NearPointer64:
599 pointer_size = 8;
600 break;
601 default:
602 // 128-bit and 16-bit pointers unsupported.
603 return nullptr;
604 }
605 Declaration decl;
606 return MakeType(uid, ConstString(), pointer_size, nullptr, LLDB_INVALID_UID,
608 }
609
610 if (ti.getSimpleKind() == SimpleTypeKind::NotTranslated)
611 return nullptr;
612
613 size_t size = GetTypeSizeForSimpleKind(ti.getSimpleKind());
614 llvm::StringRef type_name = GetSimpleTypeName(ti.getSimpleKind());
615
616 Declaration decl;
617 return MakeType(uid, ConstString(type_name), size, nullptr, LLDB_INVALID_UID,
619}
620
621static std::string GetUnqualifiedTypeName(const TagRecord &record) {
622 if (!record.hasUniqueName()) {
623 MSVCUndecoratedNameParser parser(record.Name);
624 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs = parser.GetSpecifiers();
625
626 return std::string(specs.back().GetBaseName());
627 }
628
629 llvm::ms_demangle::Demangler demangler;
630 std::string_view sv(record.UniqueName.begin(), record.UniqueName.size());
631 llvm::ms_demangle::TagTypeNode *ttn = demangler.parseTagUniqueName(sv);
632 if (demangler.Error)
633 return std::string(record.Name);
634
635 llvm::ms_demangle::IdentifierNode *idn =
636 ttn->QualifiedName->getUnqualifiedIdentifier();
637 return idn->toString();
638}
639
642 const TagRecord &record,
643 size_t size, CompilerType ct) {
644
645 std::string uname = GetUnqualifiedTypeName(record);
646
647 // FIXME: Search IPI stream for LF_UDT_MOD_SRC_LINE.
648 Declaration decl;
649 return MakeType(toOpaqueUid(type_id), ConstString(uname), size, nullptr,
652}
653
655 const ClassRecord &cr,
656 CompilerType ct) {
657 return CreateClassStructUnion(type_id, cr, cr.getSize(), ct);
658}
659
661 const UnionRecord &ur,
662 CompilerType ct) {
663 return CreateClassStructUnion(type_id, ur, ur.getSize(), ct);
664}
665
667 const EnumRecord &er,
668 CompilerType ct) {
669 std::string uname = GetUnqualifiedTypeName(er);
670
671 Declaration decl;
672 TypeSP underlying_type = GetOrCreateType(er.UnderlyingType);
673
674 return MakeType(toOpaqueUid(type_id), ConstString(uname),
675 underlying_type->GetByteSize(nullptr), nullptr,
678}
679
681 const ArrayRecord &ar,
682 CompilerType ct) {
683 TypeSP element_type = GetOrCreateType(ar.ElementType);
684
685 Declaration decl;
686 TypeSP array_sp =
687 MakeType(toOpaqueUid(type_id), ConstString(), ar.Size, nullptr,
690 array_sp->SetEncodingType(element_type.get());
691 return array_sp;
692}
693
695 const MemberFunctionRecord &mfr,
696 CompilerType ct) {
697 Declaration decl;
698 return MakeType(toOpaqueUid(type_id), ConstString(), 0, nullptr,
701}
702
704 const ProcedureRecord &pr,
705 CompilerType ct) {
706 Declaration decl;
707 return MakeType(toOpaqueUid(type_id), ConstString(), 0, nullptr,
710}
711
713 if (type_id.index.isSimple())
714 return CreateSimpleType(type_id.index, ct);
715
716 TpiStream &stream = type_id.is_ipi ? m_index->ipi() : m_index->tpi();
717 CVType cvt = stream.getType(type_id.index);
718
719 if (cvt.kind() == LF_MODIFIER) {
720 ModifierRecord modifier;
721 llvm::cantFail(
722 TypeDeserializer::deserializeAs<ModifierRecord>(cvt, modifier));
723 return CreateModifierType(type_id, modifier, ct);
724 }
725
726 if (cvt.kind() == LF_POINTER) {
727 PointerRecord pointer;
728 llvm::cantFail(
729 TypeDeserializer::deserializeAs<PointerRecord>(cvt, pointer));
730 return CreatePointerType(type_id, pointer, ct);
731 }
732
733 if (IsClassRecord(cvt.kind())) {
734 ClassRecord cr;
735 llvm::cantFail(TypeDeserializer::deserializeAs<ClassRecord>(cvt, cr));
736 return CreateTagType(type_id, cr, ct);
737 }
738
739 if (cvt.kind() == LF_ENUM) {
740 EnumRecord er;
741 llvm::cantFail(TypeDeserializer::deserializeAs<EnumRecord>(cvt, er));
742 return CreateTagType(type_id, er, ct);
743 }
744
745 if (cvt.kind() == LF_UNION) {
746 UnionRecord ur;
747 llvm::cantFail(TypeDeserializer::deserializeAs<UnionRecord>(cvt, ur));
748 return CreateTagType(type_id, ur, ct);
749 }
750
751 if (cvt.kind() == LF_ARRAY) {
752 ArrayRecord ar;
753 llvm::cantFail(TypeDeserializer::deserializeAs<ArrayRecord>(cvt, ar));
754 return CreateArrayType(type_id, ar, ct);
755 }
756
757 if (cvt.kind() == LF_PROCEDURE) {
758 ProcedureRecord pr;
759 llvm::cantFail(TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr));
760 return CreateProcedureType(type_id, pr, ct);
761 }
762 if (cvt.kind() == LF_MFUNCTION) {
763 MemberFunctionRecord mfr;
764 llvm::cantFail(TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr));
765 return CreateFunctionType(type_id, mfr, ct);
766 }
767
768 return nullptr;
769}
770
772 // If they search for a UDT which is a forward ref, try and resolve the full
773 // decl and just map the forward ref uid to the full decl record.
774 std::optional<PdbTypeSymId> full_decl_uid;
775 if (IsForwardRefUdt(type_id, m_index->tpi())) {
776 auto expected_full_ti =
777 m_index->tpi().findFullDeclForForwardRef(type_id.index);
778 if (!expected_full_ti)
779 llvm::consumeError(expected_full_ti.takeError());
780 else if (*expected_full_ti != type_id.index) {
781 full_decl_uid = PdbTypeSymId(*expected_full_ti, false);
782
783 // It's possible that a lookup would occur for the full decl causing it
784 // to be cached, then a second lookup would occur for the forward decl.
785 // We don't want to create a second full decl, so make sure the full
786 // decl hasn't already been cached.
787 auto full_iter = m_types.find(toOpaqueUid(*full_decl_uid));
788 if (full_iter != m_types.end()) {
789 TypeSP result = full_iter->second;
790 // Map the forward decl to the TypeSP for the full decl so we can take
791 // the fast path next time.
792 m_types[toOpaqueUid(type_id)] = result;
793 return result;
794 }
795 }
796 }
797
798 PdbTypeSymId best_decl_id = full_decl_uid ? *full_decl_uid : type_id;
800 if (auto err = ts_or_err.takeError())
801 return nullptr;
802 auto ts = *ts_or_err;
803 if (!ts)
804 return nullptr;
805
806 PdbAstBuilder* ast_builder = ts->GetNativePDBParser();
807 clang::QualType qt = ast_builder->GetOrCreateType(best_decl_id);
808 if (qt.isNull())
809 return nullptr;
810
811 TypeSP result = CreateType(best_decl_id, ast_builder->ToCompilerType(qt));
812 if (!result)
813 return nullptr;
814
815 uint64_t best_uid = toOpaqueUid(best_decl_id);
816 m_types[best_uid] = result;
817 // If we had both a forward decl and a full decl, make both point to the new
818 // type.
819 if (full_decl_uid)
820 m_types[toOpaqueUid(type_id)] = result;
821
822 return result;
823}
824
826 // We can't use try_emplace / overwrite here because the process of creating
827 // a type could create nested types, which could invalidate iterators. So
828 // we have to do a 2-phase lookup / insert.
829 auto iter = m_types.find(toOpaqueUid(type_id));
830 if (iter != m_types.end())
831 return iter->second;
832
833 TypeSP type = CreateAndCacheType(type_id);
834 if (type)
835 GetTypeList().Insert(type);
836 return type;
837}
838
840 CVSymbol sym = m_index->symrecords().readRecord(var_id.offset);
841 if (sym.kind() == S_CONSTANT)
842 return CreateConstantSymbol(var_id, sym);
843
845 TypeIndex ti;
846 llvm::StringRef name;
847 lldb::addr_t addr = 0;
848 uint16_t section = 0;
849 uint32_t offset = 0;
850 bool is_external = false;
851 switch (sym.kind()) {
852 case S_GDATA32:
853 is_external = true;
854 [[fallthrough]];
855 case S_LDATA32: {
856 DataSym ds(sym.kind());
857 llvm::cantFail(SymbolDeserializer::deserializeAs<DataSym>(sym, ds));
858 ti = ds.Type;
859 scope = (sym.kind() == S_GDATA32) ? eValueTypeVariableGlobal
861 name = ds.Name;
862 section = ds.Segment;
863 offset = ds.DataOffset;
864 addr = m_index->MakeVirtualAddress(ds.Segment, ds.DataOffset);
865 break;
866 }
867 case S_GTHREAD32:
868 is_external = true;
869 [[fallthrough]];
870 case S_LTHREAD32: {
871 ThreadLocalDataSym tlds(sym.kind());
872 llvm::cantFail(
873 SymbolDeserializer::deserializeAs<ThreadLocalDataSym>(sym, tlds));
874 ti = tlds.Type;
875 name = tlds.Name;
876 section = tlds.Segment;
877 offset = tlds.DataOffset;
878 addr = m_index->MakeVirtualAddress(tlds.Segment, tlds.DataOffset);
880 break;
881 }
882 default:
883 llvm_unreachable("unreachable!");
884 }
885
886 CompUnitSP comp_unit;
887 std::optional<uint16_t> modi = m_index->GetModuleIndexForVa(addr);
888 // Some globals has modi points to the linker module, ignore them.
889 if (!modi || modi >= GetNumCompileUnits())
890 return nullptr;
891
892 CompilandIndexItem &cci = m_index->compilands().GetOrCreateCompiland(*modi);
893 comp_unit = GetOrCreateCompileUnit(cci);
894
895 Declaration decl;
896 PdbTypeSymId tid(ti, false);
897 SymbolFileTypeSP type_sp =
898 std::make_shared<SymbolFileType>(*this, toOpaqueUid(tid));
899 Variable::RangeList ranges;
900 auto ts_or_err = GetTypeSystemForLanguage(comp_unit->GetLanguage());
901 if (auto err = ts_or_err.takeError())
902 return nullptr;
903 auto ts = *ts_or_err;
904 if (!ts)
905 return nullptr;
906
907 ts->GetNativePDBParser()->GetOrCreateVariableDecl(var_id);
908
909 ModuleSP module_sp = GetObjectFile()->GetModule();
910 DWARFExpressionList location(
911 module_sp, MakeGlobalLocationExpression(section, offset, module_sp),
912 nullptr);
913
914 std::string global_name("::");
915 global_name += name;
916 bool artificial = false;
917 bool location_is_constant_data = false;
918 bool static_member = false;
919 VariableSP var_sp = std::make_shared<Variable>(
920 toOpaqueUid(var_id), name.str().c_str(), global_name.c_str(), type_sp,
921 scope, comp_unit.get(), ranges, &decl, location, is_external, artificial,
922 location_is_constant_data, static_member);
923
924 return var_sp;
925}
926
929 const CVSymbol &cvs) {
930 TpiStream &tpi = m_index->tpi();
931 ConstantSym constant(cvs.kind());
932
933 llvm::cantFail(SymbolDeserializer::deserializeAs<ConstantSym>(cvs, constant));
934 std::string global_name("::");
935 global_name += constant.Name;
936 PdbTypeSymId tid(constant.Type, false);
937 SymbolFileTypeSP type_sp =
938 std::make_shared<SymbolFileType>(*this, toOpaqueUid(tid));
939
940 Declaration decl;
941 Variable::RangeList ranges;
942 ModuleSP module = GetObjectFile()->GetModule();
943 DWARFExpressionList location(module,
945 constant.Type, tpi, constant.Value, module),
946 nullptr);
947
948 bool external = false;
949 bool artificial = false;
950 bool location_is_constant_data = true;
951 bool static_member = false;
952 VariableSP var_sp = std::make_shared<Variable>(
953 toOpaqueUid(var_id), constant.Name.str().c_str(), global_name.c_str(),
954 type_sp, eValueTypeVariableGlobal, module.get(), ranges, &decl, location,
955 external, artificial, location_is_constant_data, static_member);
956 return var_sp;
957}
958
961 auto emplace_result = m_global_vars.try_emplace(toOpaqueUid(var_id), nullptr);
962 if (emplace_result.second) {
963 if (VariableSP var_sp = CreateGlobalVariable(var_id))
964 emplace_result.first->second = var_sp;
965 else
966 return nullptr;
967 }
968
969 return emplace_result.first->second;
970}
971
973 return GetOrCreateType(PdbTypeSymId(ti, false));
974}
975
977 CompileUnit &comp_unit) {
978 auto emplace_result = m_functions.try_emplace(toOpaqueUid(func_id), nullptr);
979 if (emplace_result.second)
980 emplace_result.first->second = CreateFunction(func_id, comp_unit);
981
982 return emplace_result.first->second;
983}
984
987
988 auto emplace_result =
989 m_compilands.try_emplace(toOpaqueUid(cci.m_id), nullptr);
990 if (emplace_result.second)
991 emplace_result.first->second = CreateCompileUnit(cci);
992
993 lldbassert(emplace_result.first->second);
994 return emplace_result.first->second;
995}
996
998 auto iter = m_blocks.find(toOpaqueUid(block_id));
999 if (iter != m_blocks.end())
1000 return iter->second.get();
1001
1002 return CreateBlock(block_id);
1003}
1004
1007 TypeSystem* ts_or_err = decl_ctx.GetTypeSystem();
1008 if (!ts_or_err)
1009 return;
1010 PdbAstBuilder* ast_builder = ts_or_err->GetNativePDBParser();
1011 clang::DeclContext *context = ast_builder->FromCompilerDeclContext(decl_ctx);
1012 if (!context)
1013 return;
1014 ast_builder->ParseDeclsForContext(*context);
1015}
1016
1018 if (index >= GetNumCompileUnits())
1019 return CompUnitSP();
1020 lldbassert(index < UINT16_MAX);
1021 if (index >= UINT16_MAX)
1022 return nullptr;
1023
1024 CompilandIndexItem &item = m_index->compilands().GetOrCreateCompiland(index);
1025
1026 return GetOrCreateCompileUnit(item);
1027}
1028
1030 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1031 PdbSymUid uid(comp_unit.GetID());
1033
1034 CompilandIndexItem *item =
1035 m_index->compilands().GetCompiland(uid.asCompiland().modi);
1036 lldbassert(item);
1037 if (!item->m_compile_opts)
1039
1040 return TranslateLanguage(item->m_compile_opts->getLanguage());
1041}
1042
1044
1046 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1047 PdbSymUid uid{comp_unit.GetID()};
1048 lldbassert(uid.kind() == PdbSymUidKind::Compiland);
1049 uint16_t modi = uid.asCompiland().modi;
1050 CompilandIndexItem &cii = m_index->compilands().GetOrCreateCompiland(modi);
1051
1052 size_t count = comp_unit.GetNumFunctions();
1053 const CVSymbolArray &syms = cii.m_debug_stream.getSymbolArray();
1054 for (auto iter = syms.begin(); iter != syms.end(); ++iter) {
1055 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32)
1056 continue;
1057
1058 PdbCompilandSymId sym_id{modi, iter.offset()};
1059
1060 FunctionSP func = GetOrCreateFunction(sym_id, comp_unit);
1061 }
1062
1063 size_t new_count = comp_unit.GetNumFunctions();
1064 lldbassert(new_count >= count);
1065 return new_count - count;
1066}
1067
1068static bool NeedsResolvedCompileUnit(uint32_t resolve_scope) {
1069 // If any of these flags are set, we need to resolve the compile unit.
1070 uint32_t flags = eSymbolContextCompUnit;
1071 flags |= eSymbolContextVariable;
1072 flags |= eSymbolContextFunction;
1073 flags |= eSymbolContextBlock;
1074 flags |= eSymbolContextLineEntry;
1075 return (resolve_scope & flags) != 0;
1076}
1077
1079 const Address &addr, SymbolContextItem resolve_scope, SymbolContext &sc) {
1080 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1081 uint32_t resolved_flags = 0;
1082 lldb::addr_t file_addr = addr.GetFileAddress();
1083
1084 if (NeedsResolvedCompileUnit(resolve_scope)) {
1085 std::optional<uint16_t> modi = m_index->GetModuleIndexForVa(file_addr);
1086 if (!modi)
1087 return 0;
1088 CompUnitSP cu_sp = GetCompileUnitAtIndex(*modi);
1089 if (!cu_sp)
1090 return 0;
1091
1092 sc.comp_unit = cu_sp.get();
1093 resolved_flags |= eSymbolContextCompUnit;
1094 }
1095
1096 if (resolve_scope & eSymbolContextFunction ||
1097 resolve_scope & eSymbolContextBlock) {
1099 std::vector<SymbolAndUid> matches = m_index->FindSymbolsByVa(file_addr);
1100 // Search the matches in reverse. This way if there are multiple matches
1101 // (for example we are 3 levels deep in a nested scope) it will find the
1102 // innermost one first.
1103 for (const auto &match : llvm::reverse(matches)) {
1104 if (match.uid.kind() != PdbSymUidKind::CompilandSym)
1105 continue;
1106
1107 PdbCompilandSymId csid = match.uid.asCompilandSym();
1108 CVSymbol cvs = m_index->ReadSymbolRecord(csid);
1109 PDB_SymType type = CVSymToPDBSym(cvs.kind());
1110 if (type != PDB_SymType::Function && type != PDB_SymType::Block)
1111 continue;
1112 if (type == PDB_SymType::Function) {
1113 sc.function = GetOrCreateFunction(csid, *sc.comp_unit).get();
1114 if (sc.function) {
1115 Block &block = sc.function->GetBlock(true);
1116 addr_t func_base =
1118 addr_t offset = file_addr - func_base;
1119 sc.block = block.FindInnermostBlockByOffset(offset);
1120 }
1121 }
1122
1123 if (type == PDB_SymType::Block) {
1124 Block *block = GetOrCreateBlock(csid);
1125 if (!block)
1126 continue;
1128 if (sc.function) {
1129 sc.function->GetBlock(true);
1130 addr_t func_base =
1132 addr_t offset = file_addr - func_base;
1133 sc.block = block->FindInnermostBlockByOffset(offset);
1134 }
1135 }
1136 if (sc.function)
1137 resolved_flags |= eSymbolContextFunction;
1138 if (sc.block)
1139 resolved_flags |= eSymbolContextBlock;
1140 break;
1141 }
1142 }
1143
1144 if (resolve_scope & eSymbolContextLineEntry) {
1146 if (auto *line_table = sc.comp_unit->GetLineTable()) {
1147 if (line_table->FindLineEntryByAddress(addr, sc.line_entry))
1148 resolved_flags |= eSymbolContextLineEntry;
1149 }
1150 }
1151
1152 return resolved_flags;
1153}
1154
1156 const SourceLocationSpec &src_location_spec,
1157 lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
1158 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1159 const uint32_t prev_size = sc_list.GetSize();
1160 if (resolve_scope & eSymbolContextCompUnit) {
1161 for (uint32_t cu_idx = 0, num_cus = GetNumCompileUnits(); cu_idx < num_cus;
1162 ++cu_idx) {
1163 CompileUnit *cu = ParseCompileUnitAtIndex(cu_idx).get();
1164 if (!cu)
1165 continue;
1166
1167 bool file_spec_matches_cu_file_spec = FileSpec::Match(
1168 src_location_spec.GetFileSpec(), cu->GetPrimaryFile());
1169 if (file_spec_matches_cu_file_spec) {
1170 cu->ResolveSymbolContext(src_location_spec, resolve_scope, sc_list);
1171 break;
1172 }
1173 }
1174 }
1175 return sc_list.GetSize() - prev_size;
1176}
1177
1179 // Unfortunately LLDB is set up to parse the entire compile unit line table
1180 // all at once, even if all it really needs is line info for a specific
1181 // function. In the future it would be nice if it could set the sc.m_function
1182 // member, and we could only get the line info for the function in question.
1183 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1184 PdbSymUid cu_id(comp_unit.GetID());
1186 uint16_t modi = cu_id.asCompiland().modi;
1187 CompilandIndexItem *cii = m_index->compilands().GetCompiland(modi);
1188 lldbassert(cii);
1189
1190 // Parse DEBUG_S_LINES subsections first, then parse all S_INLINESITE records
1191 // in this CU. Add line entries into the set first so that if there are line
1192 // entries with same addres, the later is always more accurate than the
1193 // former.
1194 std::set<LineTable::Entry, LineTableEntryComparator> line_set;
1195
1196 // This is basically a copy of the .debug$S subsections from all original COFF
1197 // object files merged together with address relocations applied. We are
1198 // looking for all DEBUG_S_LINES subsections.
1199 for (const DebugSubsectionRecord &dssr :
1200 cii->m_debug_stream.getSubsectionsArray()) {
1201 if (dssr.kind() != DebugSubsectionKind::Lines)
1202 continue;
1203
1204 DebugLinesSubsectionRef lines;
1205 llvm::BinaryStreamReader reader(dssr.getRecordData());
1206 if (auto EC = lines.initialize(reader)) {
1207 llvm::consumeError(std::move(EC));
1208 return false;
1209 }
1210
1211 const LineFragmentHeader *lfh = lines.header();
1212 uint64_t virtual_addr =
1213 m_index->MakeVirtualAddress(lfh->RelocSegment, lfh->RelocOffset);
1214 if (virtual_addr == LLDB_INVALID_ADDRESS)
1215 continue;
1216
1217 for (const LineColumnEntry &group : lines) {
1218 llvm::Expected<uint32_t> file_index_or_err =
1219 GetFileIndex(*cii, group.NameIndex);
1220 if (!file_index_or_err)
1221 continue;
1222 uint32_t file_index = file_index_or_err.get();
1223 lldbassert(!group.LineNumbers.empty());
1226 for (const LineNumberEntry &entry : group.LineNumbers) {
1227 LineInfo cur_info(entry.Flags);
1228
1229 if (cur_info.isAlwaysStepInto() || cur_info.isNeverStepInto())
1230 continue;
1231
1232 uint64_t addr = virtual_addr + entry.Offset;
1233
1234 bool is_statement = cur_info.isStatement();
1235 bool is_prologue = IsFunctionPrologue(*cii, addr);
1236 bool is_epilogue = IsFunctionEpilogue(*cii, addr);
1237
1238 uint32_t lno = cur_info.getStartLine();
1239
1240 LineTable::Entry new_entry(addr, lno, 0, file_index, is_statement, false,
1241 is_prologue, is_epilogue, false);
1242 // Terminal entry has lower precedence than new entry.
1243 auto iter = line_set.find(new_entry);
1244 if (iter != line_set.end() && iter->is_terminal_entry)
1245 line_set.erase(iter);
1246 line_set.insert(new_entry);
1247
1248 if (line_entry.GetRangeBase() != LLDB_INVALID_ADDRESS) {
1249 line_entry.SetRangeEnd(addr);
1250 cii->m_global_line_table.Append(line_entry);
1251 }
1252 line_entry.SetRangeBase(addr);
1253 line_entry.data = {file_index, lno};
1254 }
1255 LineInfo last_line(group.LineNumbers.back().Flags);
1256 line_set.emplace(virtual_addr + lfh->CodeSize, last_line.getEndLine(), 0,
1257 file_index, false, false, false, false, true);
1258
1259 if (line_entry.GetRangeBase() != LLDB_INVALID_ADDRESS) {
1260 line_entry.SetRangeEnd(virtual_addr + lfh->CodeSize);
1261 cii->m_global_line_table.Append(line_entry);
1262 }
1263 }
1264 }
1265
1267
1268 // Parse all S_INLINESITE in this CU.
1269 const CVSymbolArray &syms = cii->m_debug_stream.getSymbolArray();
1270 for (auto iter = syms.begin(); iter != syms.end();) {
1271 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32) {
1272 ++iter;
1273 continue;
1274 }
1275
1276 uint32_t record_offset = iter.offset();
1277 CVSymbol func_record =
1278 cii->m_debug_stream.readSymbolAtOffset(record_offset);
1280 addr_t file_vm_addr =
1281 m_index->MakeVirtualAddress(sol.so.segment, sol.so.offset);
1282 if (file_vm_addr == LLDB_INVALID_ADDRESS)
1283 continue;
1284
1285 AddressRange func_range(file_vm_addr, sol.length,
1286 comp_unit.GetModule()->GetSectionList());
1287 Address func_base = func_range.GetBaseAddress();
1288 PdbCompilandSymId func_id{modi, record_offset};
1289
1290 // Iterate all S_INLINESITEs in the function.
1291 auto parse_inline_sites = [&](SymbolKind kind, PdbCompilandSymId id) {
1292 if (kind != S_INLINESITE)
1293 return false;
1294
1295 ParseInlineSite(id, func_base);
1296
1297 for (const auto &line_entry :
1298 m_inline_sites[toOpaqueUid(id)]->line_entries) {
1299 // If line_entry is not terminal entry, remove previous line entry at
1300 // the same address and insert new one. Terminal entry inside an inline
1301 // site might not be terminal entry for its parent.
1302 if (!line_entry.is_terminal_entry)
1303 line_set.erase(line_entry);
1304 line_set.insert(line_entry);
1305 }
1306 // No longer useful after adding to line_set.
1307 m_inline_sites[toOpaqueUid(id)]->line_entries.clear();
1308 return true;
1309 };
1310 ParseSymbolArrayInScope(func_id, parse_inline_sites);
1311 // Jump to the end of the function record.
1312 iter = syms.at(getScopeEndOffset(func_record));
1313 }
1314
1316
1317 // Add line entries in line_set to line_table.
1318 auto line_table = std::make_unique<LineTable>(&comp_unit);
1319 std::unique_ptr<LineSequence> sequence(
1320 line_table->CreateLineSequenceContainer());
1321 for (const auto &line_entry : line_set) {
1322 line_table->AppendLineEntryToSequence(
1323 sequence.get(), line_entry.file_addr, line_entry.line,
1324 line_entry.column, line_entry.file_idx,
1325 line_entry.is_start_of_statement, line_entry.is_start_of_basic_block,
1326 line_entry.is_prologue_end, line_entry.is_epilogue_begin,
1327 line_entry.is_terminal_entry);
1328 }
1329 line_table->InsertSequence(sequence.get());
1330
1331 if (line_table->GetSize() == 0)
1332 return false;
1333
1334 comp_unit.SetLineTable(line_table.release());
1335 return true;
1336}
1337
1339 // PDB doesn't contain information about macros
1340 return false;
1341}
1342
1343llvm::Expected<uint32_t>
1345 uint32_t file_id) {
1346 if (!cii.m_strings.hasChecksums() || !cii.m_strings.hasStrings())
1347 return llvm::make_error<RawError>(raw_error_code::no_entry);
1348
1349 const auto &checksums = cii.m_strings.checksums().getArray();
1350 const auto &strings = cii.m_strings.strings();
1351 // Indices in this structure are actually offsets of records in the
1352 // DEBUG_S_FILECHECKSUMS subsection. Those entries then have an index
1353 // into the global PDB string table.
1354 auto iter = checksums.at(file_id);
1355 if (iter == checksums.end())
1356 return llvm::make_error<RawError>(raw_error_code::no_entry);
1357
1358 llvm::Expected<llvm::StringRef> efn = strings.getString(iter->FileNameOffset);
1359 if (!efn) {
1360 return efn.takeError();
1361 }
1362
1363 // LLDB wants the index of the file in the list of support files.
1364 auto fn_iter = llvm::find(cii.m_file_list, *efn);
1365 if (fn_iter != cii.m_file_list.end())
1366 return std::distance(cii.m_file_list.begin(), fn_iter);
1367 return llvm::make_error<RawError>(raw_error_code::no_entry);
1368}
1369
1371 SupportFileList &support_files) {
1372 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1373 PdbSymUid cu_id(comp_unit.GetID());
1375 CompilandIndexItem *cci =
1376 m_index->compilands().GetCompiland(cu_id.asCompiland().modi);
1377 lldbassert(cci);
1378
1379 for (llvm::StringRef f : cci->m_file_list) {
1380 FileSpec::Style style =
1381 f.starts_with("/") ? FileSpec::Style::posix : FileSpec::Style::windows;
1382 FileSpec spec(f, style);
1383 support_files.Append(spec);
1384 }
1385 return true;
1386}
1387
1389 const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
1390 // PDB does not yet support module debug info
1391 return false;
1392}
1393
1395 Address func_addr) {
1396 lldb::user_id_t opaque_uid = toOpaqueUid(id);
1397 if (m_inline_sites.contains(opaque_uid))
1398 return;
1399
1400 addr_t func_base = func_addr.GetFileAddress();
1401 CompilandIndexItem *cii = m_index->compilands().GetCompiland(id.modi);
1402 CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(id.offset);
1403 CompUnitSP comp_unit = GetOrCreateCompileUnit(*cii);
1404
1405 InlineSiteSym inline_site(static_cast<SymbolRecordKind>(sym.kind()));
1406 cantFail(SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site));
1407 PdbCompilandSymId parent_id(id.modi, inline_site.Parent);
1408
1409 std::shared_ptr<InlineSite> inline_site_sp =
1410 std::make_shared<InlineSite>(parent_id);
1411
1412 // Get the inlined function declaration info.
1413 auto iter = cii->m_inline_map.find(inline_site.Inlinee);
1414 if (iter == cii->m_inline_map.end())
1415 return;
1416 InlineeSourceLine inlinee_line = iter->second;
1417
1418 const SupportFileList &files = comp_unit->GetSupportFiles();
1419 FileSpec decl_file;
1420 llvm::Expected<uint32_t> file_index_or_err =
1421 GetFileIndex(*cii, inlinee_line.Header->FileID);
1422 if (!file_index_or_err)
1423 return;
1424 uint32_t file_offset = file_index_or_err.get();
1425 decl_file = files.GetFileSpecAtIndex(file_offset);
1426 uint32_t decl_line = inlinee_line.Header->SourceLineNum;
1427 std::unique_ptr<Declaration> decl_up =
1428 std::make_unique<Declaration>(decl_file, decl_line);
1429
1430 // Parse range and line info.
1431 uint32_t code_offset = 0;
1432 int32_t line_offset = 0;
1433 std::optional<uint32_t> code_offset_base;
1434 std::optional<uint32_t> code_offset_end;
1435 std::optional<int32_t> cur_line_offset;
1436 std::optional<int32_t> next_line_offset;
1437 std::optional<uint32_t> next_file_offset;
1438
1439 bool is_terminal_entry = false;
1440 bool is_start_of_statement = true;
1441 // The first instruction is the prologue end.
1442 bool is_prologue_end = true;
1443
1444 auto update_code_offset = [&](uint32_t code_delta) {
1445 if (!code_offset_base)
1446 code_offset_base = code_offset;
1447 else if (!code_offset_end)
1448 code_offset_end = *code_offset_base + code_delta;
1449 };
1450 auto update_line_offset = [&](int32_t line_delta) {
1451 line_offset += line_delta;
1452 if (!code_offset_base || !cur_line_offset)
1453 cur_line_offset = line_offset;
1454 else
1455 next_line_offset = line_offset;
1456 ;
1457 };
1458 auto update_file_offset = [&](uint32_t offset) {
1459 if (!code_offset_base)
1460 file_offset = offset;
1461 else
1462 next_file_offset = offset;
1463 };
1464
1465 for (auto &annot : inline_site.annotations()) {
1466 switch (annot.OpCode) {
1467 case BinaryAnnotationsOpCode::CodeOffset:
1468 case BinaryAnnotationsOpCode::ChangeCodeOffset:
1469 case BinaryAnnotationsOpCode::ChangeCodeOffsetBase:
1470 code_offset += annot.U1;
1471 update_code_offset(annot.U1);
1472 break;
1473 case BinaryAnnotationsOpCode::ChangeLineOffset:
1474 update_line_offset(annot.S1);
1475 break;
1476 case BinaryAnnotationsOpCode::ChangeCodeLength:
1477 update_code_offset(annot.U1);
1478 code_offset += annot.U1;
1479 is_terminal_entry = true;
1480 break;
1481 case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset:
1482 code_offset += annot.U1;
1483 update_code_offset(annot.U1);
1484 update_line_offset(annot.S1);
1485 break;
1486 case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset:
1487 code_offset += annot.U2;
1488 update_code_offset(annot.U2);
1489 update_code_offset(annot.U1);
1490 code_offset += annot.U1;
1491 is_terminal_entry = true;
1492 break;
1493 case BinaryAnnotationsOpCode::ChangeFile:
1494 update_file_offset(annot.U1);
1495 break;
1496 default:
1497 break;
1498 }
1499
1500 // Add range if current range is finished.
1501 if (code_offset_base && code_offset_end && cur_line_offset) {
1502 inline_site_sp->ranges.Append(RangeSourceLineVector::Entry(
1503 *code_offset_base, *code_offset_end - *code_offset_base,
1504 decl_line + *cur_line_offset));
1505 // Set base, end, file offset and line offset for next range.
1506 if (next_file_offset)
1507 file_offset = *next_file_offset;
1508 if (next_line_offset) {
1509 cur_line_offset = next_line_offset;
1510 next_line_offset = std::nullopt;
1511 }
1512 code_offset_base = is_terminal_entry ? std::nullopt : code_offset_end;
1513 code_offset_end = next_file_offset = std::nullopt;
1514 }
1515 if (code_offset_base && cur_line_offset) {
1516 if (is_terminal_entry) {
1517 LineTable::Entry line_entry(
1518 func_base + *code_offset_base, decl_line + *cur_line_offset, 0,
1519 file_offset, false, false, false, false, true);
1520 inline_site_sp->line_entries.push_back(line_entry);
1521 } else {
1522 LineTable::Entry line_entry(func_base + *code_offset_base,
1523 decl_line + *cur_line_offset, 0,
1524 file_offset, is_start_of_statement, false,
1525 is_prologue_end, false, false);
1526 inline_site_sp->line_entries.push_back(line_entry);
1527 is_prologue_end = false;
1528 is_start_of_statement = false;
1529 }
1530 }
1531 if (is_terminal_entry)
1532 is_start_of_statement = true;
1533 is_terminal_entry = false;
1534 }
1535
1536 inline_site_sp->ranges.Sort();
1537
1538 // Get the inlined function callsite info.
1539 std::unique_ptr<Declaration> callsite_up;
1540 if (!inline_site_sp->ranges.IsEmpty()) {
1541 auto *entry = inline_site_sp->ranges.GetEntryAtIndex(0);
1542 addr_t base_offset = entry->GetRangeBase();
1543 if (cii->m_debug_stream.readSymbolAtOffset(parent_id.offset).kind() ==
1544 S_INLINESITE) {
1545 // Its parent is another inline site, lookup parent site's range vector
1546 // for callsite line.
1547 ParseInlineSite(parent_id, func_base);
1548 std::shared_ptr<InlineSite> parent_site =
1549 m_inline_sites[toOpaqueUid(parent_id)];
1550 FileSpec &parent_decl_file =
1551 parent_site->inline_function_info->GetDeclaration().GetFile();
1552 if (auto *parent_entry =
1553 parent_site->ranges.FindEntryThatContains(base_offset)) {
1554 callsite_up =
1555 std::make_unique<Declaration>(parent_decl_file, parent_entry->data);
1556 }
1557 } else {
1558 // Its parent is a function, lookup global line table for callsite.
1559 if (auto *entry = cii->m_global_line_table.FindEntryThatContains(
1560 func_base + base_offset)) {
1561 const FileSpec &callsite_file =
1562 files.GetFileSpecAtIndex(entry->data.first);
1563 callsite_up =
1564 std::make_unique<Declaration>(callsite_file, entry->data.second);
1565 }
1566 }
1567 }
1568
1569 // Get the inlined function name.
1570 CVType inlinee_cvt = m_index->ipi().getType(inline_site.Inlinee);
1571 std::string inlinee_name;
1572 if (inlinee_cvt.kind() == LF_MFUNC_ID) {
1573 MemberFuncIdRecord mfr;
1574 cantFail(
1575 TypeDeserializer::deserializeAs<MemberFuncIdRecord>(inlinee_cvt, mfr));
1576 LazyRandomTypeCollection &types = m_index->tpi().typeCollection();
1577 inlinee_name.append(std::string(types.getTypeName(mfr.ClassType)));
1578 inlinee_name.append("::");
1579 inlinee_name.append(mfr.getName().str());
1580 } else if (inlinee_cvt.kind() == LF_FUNC_ID) {
1581 FuncIdRecord fir;
1582 cantFail(TypeDeserializer::deserializeAs<FuncIdRecord>(inlinee_cvt, fir));
1583 TypeIndex parent_idx = fir.getParentScope();
1584 if (!parent_idx.isNoneType()) {
1585 LazyRandomTypeCollection &ids = m_index->ipi().typeCollection();
1586 inlinee_name.append(std::string(ids.getTypeName(parent_idx)));
1587 inlinee_name.append("::");
1588 }
1589 inlinee_name.append(fir.getName().str());
1590 }
1591 inline_site_sp->inline_function_info = std::make_shared<InlineFunctionInfo>(
1592 inlinee_name.c_str(), llvm::StringRef(), decl_up.get(),
1593 callsite_up.get());
1594
1595 m_inline_sites[opaque_uid] = inline_site_sp;
1596}
1597
1599 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1600 PdbCompilandSymId func_id = PdbSymUid(func.GetID()).asCompilandSym();
1601 // After we iterate through inline sites inside the function, we already get
1602 // all the info needed, removing from the map to save memory.
1603 std::set<uint64_t> remove_uids;
1604 auto parse_blocks = [&](SymbolKind kind, PdbCompilandSymId id) {
1605 if (kind == S_GPROC32 || kind == S_LPROC32 || kind == S_BLOCK32 ||
1606 kind == S_INLINESITE) {
1607 GetOrCreateBlock(id);
1608 if (kind == S_INLINESITE)
1609 remove_uids.insert(toOpaqueUid(id));
1610 return true;
1611 }
1612 return false;
1613 };
1614 size_t count = ParseSymbolArrayInScope(func_id, parse_blocks);
1615 for (uint64_t uid : remove_uids) {
1616 m_inline_sites.erase(uid);
1617 }
1618 return count;
1619}
1620
1622 PdbCompilandSymId parent_id,
1623 llvm::function_ref<bool(SymbolKind, PdbCompilandSymId)> fn) {
1624 CompilandIndexItem *cii = m_index->compilands().GetCompiland(parent_id.modi);
1625 CVSymbolArray syms =
1626 cii->m_debug_stream.getSymbolArrayForScope(parent_id.offset);
1627
1628 size_t count = 1;
1629 for (auto iter = syms.begin(); iter != syms.end(); ++iter) {
1630 PdbCompilandSymId child_id(parent_id.modi, iter.offset());
1631 if (fn(iter->kind(), child_id))
1632 ++count;
1633 }
1634
1635 return count;
1636}
1637
1640 if (!ts_or_err)
1641 return;
1642 auto ts = *ts_or_err;
1643 TypeSystemClang *clang = llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
1644 if (!clang)
1645 return;
1646 clang->GetNativePDBParser()->Dump(s);
1647}
1648
1650 ConstString name, const CompilerDeclContext &parent_decl_ctx,
1651 uint32_t max_matches, VariableList &variables) {
1652 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1653 using SymbolAndOffset = std::pair<uint32_t, llvm::codeview::CVSymbol>;
1654
1655 std::vector<SymbolAndOffset> results = m_index->globals().findRecordsByName(
1656 name.GetStringRef(), m_index->symrecords());
1657 for (const SymbolAndOffset &result : results) {
1658 switch (result.second.kind()) {
1659 case SymbolKind::S_GDATA32:
1660 case SymbolKind::S_LDATA32:
1661 case SymbolKind::S_GTHREAD32:
1662 case SymbolKind::S_LTHREAD32:
1663 case SymbolKind::S_CONSTANT: {
1664 PdbGlobalSymId global(result.first, false);
1665 if (VariableSP var = GetOrCreateGlobalVariable(global))
1666 variables.AddVariable(var);
1667 break;
1668 }
1669 default:
1670 continue;
1671 }
1672 }
1673}
1674
1676 const Module::LookupInfo &lookup_info,
1677 const CompilerDeclContext &parent_decl_ctx, bool include_inlines,
1678 SymbolContextList &sc_list) {
1679 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1680 ConstString name = lookup_info.GetLookupName();
1681 FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();
1682 if (name_type_mask & eFunctionNameTypeFull)
1683 name = lookup_info.GetName();
1684
1685 // For now we only support lookup by method name or full name.
1686 if (!(name_type_mask & eFunctionNameTypeFull ||
1687 name_type_mask & eFunctionNameTypeMethod))
1688 return;
1689
1690 using SymbolAndOffset = std::pair<uint32_t, llvm::codeview::CVSymbol>;
1691
1692 std::vector<SymbolAndOffset> matches = m_index->globals().findRecordsByName(
1693 name.GetStringRef(), m_index->symrecords());
1694 for (const SymbolAndOffset &match : matches) {
1695 if (match.second.kind() != S_PROCREF && match.second.kind() != S_LPROCREF)
1696 continue;
1697 ProcRefSym proc(match.second.kind());
1698 cantFail(SymbolDeserializer::deserializeAs<ProcRefSym>(match.second, proc));
1699
1700 if (!IsValidRecord(proc))
1701 continue;
1702
1703 CompilandIndexItem &cci =
1704 m_index->compilands().GetOrCreateCompiland(proc.modi());
1705 SymbolContext sc;
1706
1707 sc.comp_unit = GetOrCreateCompileUnit(cci).get();
1708 PdbCompilandSymId func_id(proc.modi(), proc.SymOffset);
1709 sc.function = GetOrCreateFunction(func_id, *sc.comp_unit).get();
1710
1711 sc_list.Append(sc);
1712 }
1713}
1714
1716 bool include_inlines,
1717 SymbolContextList &sc_list) {}
1718
1720 lldb_private::TypeResults &results) {
1721
1722 // Make sure we haven't already searched this SymbolFile before.
1723 if (results.AlreadySearched(this))
1724 return;
1725
1726 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1727
1728 std::vector<TypeIndex> matches =
1729 m_index->tpi().findRecordsByName(query.GetTypeBasename().GetStringRef());
1730
1731 for (TypeIndex type_idx : matches) {
1732 TypeSP type_sp = GetOrCreateType(type_idx);
1733 if (!type_sp)
1734 continue;
1735
1736 // We resolved a type. Get the fully qualified name to ensure it matches.
1737 ConstString name = type_sp->GetQualifiedName();
1738 TypeQuery type_match(name.GetStringRef(), TypeQueryOptions::e_exact_match);
1739 if (query.ContextMatches(type_match.GetContextRef())) {
1740 results.InsertUnique(type_sp);
1741 if (results.Done(query))
1742 return;
1743 }
1744 }
1745}
1746
1748 uint32_t max_matches,
1749 TypeMap &types) {
1750
1751 std::vector<TypeIndex> matches = m_index->tpi().findRecordsByName(name);
1752 if (max_matches > 0 && max_matches < matches.size())
1753 matches.resize(max_matches);
1754
1755 for (TypeIndex ti : matches) {
1756 TypeSP type = GetOrCreateType(ti);
1757 if (!type)
1758 continue;
1759
1760 types.Insert(type);
1761 }
1762}
1763
1765 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1766 // Only do the full type scan the first time.
1768 return 0;
1769
1770 const size_t old_count = GetTypeList().GetSize();
1771 LazyRandomTypeCollection &types = m_index->tpi().typeCollection();
1772
1773 // First process the entire TPI stream.
1774 for (auto ti = types.getFirst(); ti; ti = types.getNext(*ti)) {
1775 TypeSP type = GetOrCreateType(*ti);
1776 if (type)
1777 (void)type->GetFullCompilerType();
1778 }
1779
1780 // Next look for S_UDT records in the globals stream.
1781 for (const uint32_t gid : m_index->globals().getGlobalsTable()) {
1782 PdbGlobalSymId global{gid, false};
1783 CVSymbol sym = m_index->ReadSymbolRecord(global);
1784 if (sym.kind() != S_UDT)
1785 continue;
1786
1787 UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs<UDTSym>(sym));
1788 bool is_typedef = true;
1789 if (IsTagRecord(PdbTypeSymId{udt.Type, false}, m_index->tpi())) {
1790 CVType cvt = m_index->tpi().getType(udt.Type);
1791 llvm::StringRef name = CVTagRecord::create(cvt).name();
1792 if (name == udt.Name)
1793 is_typedef = false;
1794 }
1795
1796 if (is_typedef)
1797 GetOrCreateTypedef(global);
1798 }
1799
1800 const size_t new_count = GetTypeList().GetSize();
1801
1802 m_done_full_type_scan = true;
1803
1804 return new_count - old_count;
1805}
1806
1807size_t
1809 VariableList &variables) {
1810 PdbSymUid sym_uid(comp_unit.GetID());
1812 for (const uint32_t gid : m_index->globals().getGlobalsTable()) {
1813 PdbGlobalSymId global{gid, false};
1814 CVSymbol sym = m_index->ReadSymbolRecord(global);
1815 // TODO: S_CONSTANT is not handled here to prevent a possible crash in
1816 // lldb_private::npdb::MakeConstantLocationExpression when it's a record
1817 // type (e.g. std::strong_ordering::equal). That function needs to be
1818 // updated to handle this case when we add S_CONSTANT case here.
1819 switch (sym.kind()) {
1820 case SymbolKind::S_GDATA32:
1821 case SymbolKind::S_LDATA32:
1822 case SymbolKind::S_GTHREAD32:
1823 case SymbolKind::S_LTHREAD32: {
1824 if (VariableSP var = GetOrCreateGlobalVariable(global))
1825 variables.AddVariable(var);
1826 break;
1827 }
1828 default:
1829 break;
1830 }
1831 }
1832 return variables.GetSize();
1833}
1834
1836 PdbCompilandSymId var_id,
1837 bool is_param) {
1838 ModuleSP module = GetObjectFile()->GetModule();
1839 Block *block = GetOrCreateBlock(scope_id);
1840 if (!block)
1841 return nullptr;
1842
1843 // Get function block.
1844 Block *func_block = block;
1845 while (func_block->GetParent()) {
1846 func_block = func_block->GetParent();
1847 }
1848
1849 Address addr;
1850 func_block->GetStartAddress(addr);
1851 VariableInfo var_info =
1852 GetVariableLocationInfo(*m_index, var_id, *func_block, module);
1853 Function *func = func_block->CalculateSymbolContextFunction();
1854 if (!func)
1855 return nullptr;
1856 // Use empty dwarf expr if optimized away so that it won't be filtered out
1857 // when lookuping local variables in this scope.
1858 if (!var_info.location.IsValid())
1859 var_info.location = DWARFExpressionList(module, DWARFExpression(), nullptr);
1862 CompilandIndexItem *cii = m_index->compilands().GetCompiland(var_id.modi);
1863 CompUnitSP comp_unit_sp = GetOrCreateCompileUnit(*cii);
1864 TypeSP type_sp = GetOrCreateType(var_info.type);
1865 if (!type_sp)
1866 return nullptr;
1867 std::string name = var_info.name.str();
1868 Declaration decl;
1869 SymbolFileTypeSP sftype =
1870 std::make_shared<SymbolFileType>(*this, type_sp->GetID());
1871
1872 is_param |= var_info.is_param;
1873 ValueType var_scope =
1875 bool external = false;
1876 bool artificial = false;
1877 bool location_is_constant_data = false;
1878 bool static_member = false;
1879 Variable::RangeList scope_ranges;
1880 VariableSP var_sp = std::make_shared<Variable>(
1881 toOpaqueUid(var_id), name.c_str(), name.c_str(), sftype, var_scope, block,
1882 scope_ranges, &decl, var_info.location, external, artificial,
1883 location_is_constant_data, static_member);
1884 if (!is_param) {
1885 auto ts_or_err = GetTypeSystemForLanguage(comp_unit_sp->GetLanguage());
1886 if (auto err = ts_or_err.takeError())
1887 return nullptr;
1888 auto ts = *ts_or_err;
1889 if (!ts)
1890 return nullptr;
1891
1892 ts->GetNativePDBParser()->GetOrCreateVariableDecl(scope_id, var_id);
1893 }
1894 m_local_variables[toOpaqueUid(var_id)] = var_sp;
1895 return var_sp;
1896}
1897
1899 PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param) {
1900 auto iter = m_local_variables.find(toOpaqueUid(var_id));
1901 if (iter != m_local_variables.end())
1902 return iter->second;
1903
1904 return CreateLocalVariable(scope_id, var_id, is_param);
1905}
1906
1908 CVSymbol sym = m_index->ReadSymbolRecord(id);
1909 lldbassert(sym.kind() == SymbolKind::S_UDT);
1910
1911 UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs<UDTSym>(sym));
1912
1913 TypeSP target_type = GetOrCreateType(udt.Type);
1914
1916 if (auto err = ts_or_err.takeError())
1917 return nullptr;
1918 auto ts = *ts_or_err;
1919 if (!ts)
1920 return nullptr;
1921
1922 ts->GetNativePDBParser()->GetOrCreateTypedefDecl(id);
1923
1924 Declaration decl;
1925 return MakeType(
1926 toOpaqueUid(id), ConstString(udt.Name), target_type->GetByteSize(nullptr),
1927 nullptr, target_type->GetID(), lldb_private::Type::eEncodingIsTypedefUID,
1928 decl, target_type->GetForwardCompilerType(),
1930}
1931
1933 auto iter = m_types.find(toOpaqueUid(id));
1934 if (iter != m_types.end())
1935 return iter->second;
1936
1937 return CreateTypedef(id);
1938}
1939
1941 Block *block = GetOrCreateBlock(block_id);
1942 if (!block)
1943 return 0;
1944
1945 size_t count = 0;
1946
1947 CompilandIndexItem *cii = m_index->compilands().GetCompiland(block_id.modi);
1948 CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(block_id.offset);
1949 uint32_t params_remaining = 0;
1950 switch (sym.kind()) {
1951 case S_GPROC32:
1952 case S_LPROC32: {
1953 ProcSym proc(static_cast<SymbolRecordKind>(sym.kind()));
1954 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym, proc));
1955 CVType signature = m_index->tpi().getType(proc.FunctionType);
1956 if (signature.kind() == LF_PROCEDURE) {
1957 ProcedureRecord sig;
1958 if (llvm::Error e = TypeDeserializer::deserializeAs<ProcedureRecord>(
1959 signature, sig)) {
1960 llvm::consumeError(std::move(e));
1961 return 0;
1962 }
1963 params_remaining = sig.getParameterCount();
1964 } else if (signature.kind() == LF_MFUNCTION) {
1965 MemberFunctionRecord sig;
1966 if (llvm::Error e = TypeDeserializer::deserializeAs<MemberFunctionRecord>(
1967 signature, sig)) {
1968 llvm::consumeError(std::move(e));
1969 return 0;
1970 }
1971 params_remaining = sig.getParameterCount();
1972 } else
1973 return 0;
1974 break;
1975 }
1976 case S_BLOCK32:
1977 break;
1978 case S_INLINESITE:
1979 break;
1980 default:
1981 lldbassert(false && "Symbol is not a block!");
1982 return 0;
1983 }
1984
1985 VariableListSP variables = block->GetBlockVariableList(false);
1986 if (!variables) {
1987 variables = std::make_shared<VariableList>();
1988 block->SetVariableList(variables);
1989 }
1990
1991 CVSymbolArray syms = limitSymbolArrayToScope(
1992 cii->m_debug_stream.getSymbolArray(), block_id.offset);
1993
1994 // Skip the first record since it's a PROC32 or BLOCK32, and there's
1995 // no point examining it since we know it's not a local variable.
1996 syms.drop_front();
1997 auto iter = syms.begin();
1998 auto end = syms.end();
1999
2000 while (iter != end) {
2001 uint32_t record_offset = iter.offset();
2002 CVSymbol variable_cvs = *iter;
2003 PdbCompilandSymId child_sym_id(block_id.modi, record_offset);
2004 ++iter;
2005
2006 // If this is a block or inline site, recurse into its children and then
2007 // skip it.
2008 if (variable_cvs.kind() == S_BLOCK32 ||
2009 variable_cvs.kind() == S_INLINESITE) {
2010 uint32_t block_end = getScopeEndOffset(variable_cvs);
2011 count += ParseVariablesForBlock(child_sym_id);
2012 iter = syms.at(block_end);
2013 continue;
2014 }
2015
2016 bool is_param = params_remaining > 0;
2017 VariableSP variable;
2018 switch (variable_cvs.kind()) {
2019 case S_REGREL32:
2020 case S_REGISTER:
2021 case S_LOCAL:
2022 variable = GetOrCreateLocalVariable(block_id, child_sym_id, is_param);
2023 if (is_param)
2024 --params_remaining;
2025 if (variable)
2026 variables->AddVariableIfUnique(variable);
2027 break;
2028 default:
2029 break;
2030 }
2031 }
2032
2033 // Pass false for set_children, since we call this recursively so that the
2034 // children will call this for themselves.
2035 block->SetDidParseVariables(true, false);
2036
2037 return count;
2038}
2039
2041 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2042 lldbassert(sc.function || sc.comp_unit);
2043
2044 VariableListSP variables;
2045 if (sc.block) {
2046 PdbSymUid block_id(sc.block->GetID());
2047
2048 size_t count = ParseVariablesForBlock(block_id.asCompilandSym());
2049 return count;
2050 }
2051
2052 if (sc.function) {
2053 PdbSymUid block_id(sc.function->GetID());
2054
2055 size_t count = ParseVariablesForBlock(block_id.asCompilandSym());
2056 return count;
2057 }
2058
2059 if (sc.comp_unit) {
2060 variables = sc.comp_unit->GetVariableList(false);
2061 if (!variables) {
2062 variables = std::make_shared<VariableList>();
2063 sc.comp_unit->SetVariableList(variables);
2064 }
2065 return ParseVariablesForCompileUnit(*sc.comp_unit, *variables);
2066 }
2067
2068 llvm_unreachable("Unreachable!");
2069}
2070
2073 if (auto err = ts_or_err.takeError())
2074 return CompilerDecl();
2075 auto ts = *ts_or_err;
2076 if (!ts)
2077 return {};
2078
2079 if (auto decl = ts->GetNativePDBParser()->GetOrCreateDeclForUid(uid))
2080 return *decl;
2081 return CompilerDecl();
2082}
2083
2087 if (auto err = ts_or_err.takeError())
2088 return {};
2089 auto ts = *ts_or_err;
2090 if (!ts)
2091 return {};
2092
2093 PdbAstBuilder *ast_builder = ts->GetNativePDBParser();
2094 clang::DeclContext *context =
2095 ast_builder->GetOrCreateDeclContextForUid(PdbSymUid(uid));
2096 if (!context)
2097 return {};
2098
2099 return ast_builder->ToCompilerDeclContext(*context);
2100}
2101
2105 if (auto err = ts_or_err.takeError())
2106 return CompilerDeclContext();
2107 auto ts = *ts_or_err;
2108 if (!ts)
2109 return {};
2110
2111 PdbAstBuilder *ast_builder = ts->GetNativePDBParser();
2112 clang::DeclContext *context = ast_builder->GetParentDeclContext(PdbSymUid(uid));
2113 if (!context)
2114 return CompilerDeclContext();
2115 return ast_builder->ToCompilerDeclContext(*context);
2116}
2117
2119 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2120 auto iter = m_types.find(type_uid);
2121 // lldb should not be passing us non-sensical type uids. the only way it
2122 // could have a type uid in the first place is if we handed it out, in which
2123 // case we should know about the type. However, that doesn't mean we've
2124 // instantiated it yet. We can vend out a UID for a future type. So if the
2125 // type doesn't exist, let's instantiate it now.
2126 if (iter != m_types.end())
2127 return &*iter->second;
2128
2129 PdbSymUid uid(type_uid);
2131 PdbTypeSymId type_id = uid.asTypeSym();
2132 if (type_id.index.isNoneType())
2133 return nullptr;
2134
2135 TypeSP type_sp = CreateAndCacheType(type_id);
2136 if (!type_sp)
2137 return nullptr;
2138 return &*type_sp;
2139}
2140
2141std::optional<SymbolFile::ArrayInfo>
2143 lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) {
2144 return std::nullopt;
2145}
2146
2148 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2149 auto ts = compiler_type.GetTypeSystem();
2150 auto clang_type_system = ts.dyn_cast_or_null<TypeSystemClang>();
2151 if (!clang_type_system)
2152 return false;
2153
2154 PdbAstBuilder *ast_builder =
2155 static_cast<PdbAstBuilder *>(clang_type_system->GetNativePDBParser());
2156 if (ast_builder &&
2157 ast_builder->GetClangASTImporter().CanImport(compiler_type))
2158 return ast_builder->GetClangASTImporter().CompleteType(compiler_type);
2159 clang::QualType qt =
2160 clang::QualType::getFromOpaquePtr(compiler_type.GetOpaqueQualType());
2161
2162 return ast_builder->CompleteType(qt);
2163}
2164
2166 TypeClass type_mask,
2167 lldb_private::TypeList &type_list) {}
2168
2170 ConstString name, const CompilerDeclContext &parent_decl_ctx, bool) {
2171 return {};
2172}
2173
2174llvm::Expected<lldb::TypeSystemSP>
2176 auto type_system_or_err =
2177 m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
2178 if (type_system_or_err)
2179 if (auto ts = *type_system_or_err)
2180 ts->SetSymbolFile(this);
2181 return type_system_or_err;
2182}
2183
2184uint64_t SymbolFileNativePDB::GetDebugInfoSize(bool load_all_debug_info) {
2185 // PDB files are a separate file that contains all debug info.
2186 return m_index->pdb().getFileSize();
2187}
2188
2190 LazyRandomTypeCollection &types = m_index->tpi().typeCollection();
2191
2192 llvm::DenseMap<TypeIndex, TypeIndex> forward_to_full;
2193 llvm::DenseMap<TypeIndex, TypeIndex> full_to_forward;
2194
2195 struct RecordIndices {
2196 TypeIndex forward;
2197 TypeIndex full;
2198 };
2199
2200 llvm::StringMap<RecordIndices> record_indices;
2201
2202 for (auto ti = types.getFirst(); ti; ti = types.getNext(*ti)) {
2203 CVType type = types.getType(*ti);
2204 if (!IsTagRecord(type))
2205 continue;
2206
2207 CVTagRecord tag = CVTagRecord::create(type);
2208
2209 RecordIndices &indices = record_indices[tag.asTag().getUniqueName()];
2210 if (tag.asTag().isForwardRef())
2211 indices.forward = *ti;
2212 else
2213 indices.full = *ti;
2214
2215 if (indices.full != TypeIndex::None() &&
2216 indices.forward != TypeIndex::None()) {
2217 forward_to_full[indices.forward] = indices.full;
2218 full_to_forward[indices.full] = indices.forward;
2219 }
2220
2221 // We're looking for LF_NESTTYPE records in the field list, so ignore
2222 // forward references (no field list), and anything without a nested class
2223 // (since there won't be any LF_NESTTYPE records).
2224 if (tag.asTag().isForwardRef() || !tag.asTag().containsNestedClass())
2225 continue;
2226
2227 struct ProcessTpiStream : public TypeVisitorCallbacks {
2228 ProcessTpiStream(PdbIndex &index, TypeIndex parent,
2229 const CVTagRecord &parent_cvt,
2230 llvm::DenseMap<TypeIndex, TypeIndex> &parents)
2231 : index(index), parents(parents), parent(parent),
2232 parent_cvt(parent_cvt) {}
2233
2234 PdbIndex &index;
2235 llvm::DenseMap<TypeIndex, TypeIndex> &parents;
2236
2237 unsigned unnamed_type_index = 1;
2238 TypeIndex parent;
2239 const CVTagRecord &parent_cvt;
2240
2241 llvm::Error visitKnownMember(CVMemberRecord &CVR,
2242 NestedTypeRecord &Record) override {
2243 std::string unnamed_type_name;
2244 if (Record.Name.empty()) {
2245 unnamed_type_name =
2246 llvm::formatv("<unnamed-type-$S{0}>", unnamed_type_index).str();
2247 Record.Name = unnamed_type_name;
2248 ++unnamed_type_index;
2249 }
2250 std::optional<CVTagRecord> tag =
2251 GetNestedTagDefinition(Record, parent_cvt, index.tpi());
2252 if (!tag)
2253 return llvm::ErrorSuccess();
2254
2255 parents[Record.Type] = parent;
2256 return llvm::ErrorSuccess();
2257 }
2258 };
2259
2260 CVType field_list_cvt = m_index->tpi().getType(tag.asTag().FieldList);
2261 ProcessTpiStream process(*m_index, *ti, tag, m_parent_types);
2262 FieldListRecord field_list;
2263 if (llvm::Error error = TypeDeserializer::deserializeAs<FieldListRecord>(
2264 field_list_cvt, field_list))
2265 llvm::consumeError(std::move(error));
2266 if (llvm::Error error = visitMemberRecordStream(field_list.Data, process))
2267 llvm::consumeError(std::move(error));
2268 }
2269
2270 // Now that we know the forward -> full mapping of all type indices, we can
2271 // re-write all the indices. At the end of this process, we want a mapping
2272 // consisting of fwd -> full and full -> full for all child -> parent indices.
2273 // We can re-write the values in place, but for the keys, we must save them
2274 // off so that we don't modify the map in place while also iterating it.
2275 std::vector<TypeIndex> full_keys;
2276 std::vector<TypeIndex> fwd_keys;
2277 for (auto &entry : m_parent_types) {
2278 TypeIndex key = entry.first;
2279 TypeIndex value = entry.second;
2280
2281 auto iter = forward_to_full.find(value);
2282 if (iter != forward_to_full.end())
2283 entry.second = iter->second;
2284
2285 iter = forward_to_full.find(key);
2286 if (iter != forward_to_full.end())
2287 fwd_keys.push_back(key);
2288 else
2289 full_keys.push_back(key);
2290 }
2291 for (TypeIndex fwd : fwd_keys) {
2292 TypeIndex full = forward_to_full[fwd];
2293 TypeIndex parent_idx = m_parent_types[fwd];
2294 m_parent_types[full] = parent_idx;
2295 }
2296 for (TypeIndex full : full_keys) {
2297 TypeIndex fwd = full_to_forward[full];
2298 m_parent_types[fwd] = m_parent_types[full];
2299 }
2300}
2301
2302std::optional<PdbCompilandSymId>
2304 CVSymbol sym = m_index->ReadSymbolRecord(id);
2305 if (symbolOpensScope(sym.kind())) {
2306 // If this exact symbol opens a scope, we can just directly access its
2307 // parent.
2308 id.offset = getScopeParentOffset(sym);
2309 // Global symbols have parent offset of 0. Return std::nullopt to indicate
2310 // this.
2311 if (id.offset == 0)
2312 return std::nullopt;
2313 return id;
2314 }
2315
2316 // Otherwise we need to start at the beginning and iterate forward until we
2317 // reach (or pass) this particular symbol
2318 CompilandIndexItem &cii = m_index->compilands().GetOrCreateCompiland(id.modi);
2319 const CVSymbolArray &syms = cii.m_debug_stream.getSymbolArray();
2320
2321 auto begin = syms.begin();
2322 auto end = syms.at(id.offset);
2323 std::vector<PdbCompilandSymId> scope_stack;
2324
2325 while (begin != end) {
2326 if (begin.offset() > id.offset) {
2327 // We passed it. We couldn't even find this symbol record.
2328 lldbassert(false && "Invalid compiland symbol id!");
2329 return std::nullopt;
2330 }
2331
2332 // We haven't found the symbol yet. Check if we need to open or close the
2333 // scope stack.
2334 if (symbolOpensScope(begin->kind())) {
2335 // We can use the end offset of the scope to determine whether or not
2336 // we can just outright skip this entire scope.
2337 uint32_t scope_end = getScopeEndOffset(*begin);
2338 if (scope_end < id.offset) {
2339 begin = syms.at(scope_end);
2340 } else {
2341 // The symbol we're looking for is somewhere in this scope.
2342 scope_stack.emplace_back(id.modi, begin.offset());
2343 }
2344 } else if (symbolEndsScope(begin->kind())) {
2345 scope_stack.pop_back();
2346 }
2347 ++begin;
2348 }
2349 if (scope_stack.empty())
2350 return std::nullopt;
2351 // We have a match! Return the top of the stack
2352 return scope_stack.back();
2353}
2354
2355std::optional<llvm::codeview::TypeIndex>
2356SymbolFileNativePDB::GetParentType(llvm::codeview::TypeIndex ti) {
2357 auto parent_iter = m_parent_types.find(ti);
2358 if (parent_iter == m_parent_types.end())
2359 return std::nullopt;
2360 return parent_iter->second;
2361}
static llvm::raw_ostream & error(Stream &strm)
#define lldbassert(x)
Definition: LLDBAssert.h:15
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:392
static std::unique_ptr< PDBFile > loadMatchingPDBFile(std::string exe_path, llvm::BumpPtrAllocator &allocator)
static std::optional< CVTagRecord > GetNestedTagDefinition(const NestedTypeRecord &Record, const CVTagRecord &parent, TpiStream &tpi)
static lldb::LanguageType TranslateLanguage(PDB_Lang lang)
static std::string GetUnqualifiedTypeName(const TagRecord &record)
static llvm::StringRef GetSimpleTypeName(SimpleTypeKind kind)
static bool IsClassRecord(TypeLeafKind kind)
static bool IsFunctionEpilogue(const CompilandIndexItem &cci, lldb::addr_t addr)
static bool NeedsResolvedCompileUnit(uint32_t resolve_scope)
static bool IsFunctionPrologue(const CompilandIndexItem &cci, lldb::addr_t addr)
llvm::ArrayRef< MSVCUndecoratedNameSpecifier > GetSpecifiers() const
A section + offset based address range class.
Definition: AddressRange.h:25
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:211
A section + offset based address class.
Definition: Address.h:62
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:293
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:355
A class that describes a single lexical block.
Definition: Block.h:41
lldb::VariableListSP GetBlockVariableList(bool can_create)
Get the variable list for this block only.
Definition: Block.cpp:407
Block * FindInnermostBlockByOffset(const lldb::addr_t offset)
Definition: Block.cpp:128
lldb::BlockSP CreateChild(lldb::user_id_t uid)
Creates a block with the specified UID uid.
Definition: Block.cpp:395
Function * CalculateSymbolContextFunction() override
Definition: Block.cpp:151
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
Definition: Block.h:317
Block * GetParent() const
Get the parent block.
Definition: Block.cpp:197
bool GetStartAddress(Address &addr)
Definition: Block.cpp:327
void SetDidParseVariables(bool b, bool set_children)
Definition: Block.cpp:504
bool CanImport(const CompilerType &type)
Returns true iff the given type was copied from another TypeSystemClang and the original type in this...
bool CompleteType(const CompilerType &compiler_type)
A class that describes a compilation unit.
Definition: CompileUnit.h:43
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
lldb::VariableListSP GetVariableList(bool can_create)
Get the variable list for a compile unit.
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
Definition: CompileUnit.h:232
void ResolveSymbolContext(const SourceLocationSpec &src_location_spec, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list, RealpathPrefixes *realpath_prefixes=nullptr)
Resolve symbol contexts by file and line.
void SetLineTable(LineTable *line_table)
Set the line table for the compile unit.
void AddFunction(lldb::FunctionSP &function_sp)
Add a function to this compile unit.
size_t GetNumFunctions() const
Returns the number of functions in this compile unit.
Definition: CompileUnit.h:418
lldb::LanguageType GetLanguage()
LineTable * GetLineTable()
Get the line table for the compile unit.
Represents a generic declaration context in a program.
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
std::shared_ptr< TypeSystemType > dyn_cast_or_null()
Return a shared_ptr<TypeSystemType> if dyn_cast succeeds.
Definition: CompilerType.h:65
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
Definition: CompilerType.h:289
A uniqued constant string class.
Definition: ConstString.h:40
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:197
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
bool IsValid() const
Return true if the location expression contains data.
void SetFuncFileAddress(lldb::addr_t func_file_addr)
"lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location expression and interprets it.
A class to manage flag bits.
Definition: Debugger.h:80
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file utility class.
Definition: FileSpec.h:56
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
Definition: FileSpec.cpp:301
const ConstString & GetFilename() const
Filename string const get accessor.
Definition: FileSpec.h:240
FileSpec CopyByRemovingLastPathComponent() const
Definition: FileSpec.cpp:424
llvm::sys::path::Style Style
Definition: FileSpec.h:58
static FileSystem & Instance()
A class that describes a function.
Definition: Function.h:399
const AddressRange & GetAddressRange()
DEPRECATED: Use GetAddressRanges instead.
Definition: Function.h:448
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition: Function.cpp:396
A class that handles mangled names.
Definition: Mangled.h:33
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:24
A class that encapsulates name lookup information.
Definition: Module.h:907
lldb::FunctionNameType GetNameTypeMask() const
Definition: Module.h:922
ConstString GetLookupName() const
Definition: Module.h:918
ConstString GetName() const
Definition: Module.h:914
static std::unique_ptr< llvm::pdb::PDBFile > loadPDBFile(std::string PdbPath, llvm::BumpPtrAllocator &Allocator)
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
void Append(const Entry &entry)
Definition: RangeMap.h:451
Entry * FindEntryThatContains(B addr)
Definition: RangeMap.h:569
"lldb/Core/SourceLocationSpec.h" A source location specifier class.
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
A list of support files for a CompileUnit.
Definition: FileSpecList.h:23
const FileSpec & GetFileSpecAtIndex(size_t idx) const
void Append(const FileSpec &file)
Definition: FileSpecList.h:34
Defines a list of symbol context objects.
uint32_t GetSize() const
Get accessor for a symbol context list size.
void Append(const SymbolContext &sc)
Append a new symbol context to the list.
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
Function * function
The Function for a given query.
Block * block
The Block for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
LineEntry line_entry
The LineEntry for a given query.
Containing protected virtual methods for child classes to override.
Definition: SymbolFile.h:507
lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) override
Definition: SymbolFile.cpp:192
ObjectFile * GetObjectFile() override
Definition: SymbolFile.h:536
virtual TypeList & GetTypeList()
Definition: SymbolFile.h:609
lldb::ObjectFileSP m_objfile_sp
Definition: SymbolFile.h:612
void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp)
Definition: SymbolFile.cpp:203
uint32_t GetNumCompileUnits() override
Definition: SymbolFile.cpp:182
lldb::TypeSP MakeType(lldb::user_id_t uid, ConstString name, std::optional< uint64_t > byte_size, SymbolContextScope *context, lldb::user_id_t encoding_uid, Type::EncodingDataType encoding_uid_type, const Declaration &decl, const CompilerType &compiler_qual_type, Type::ResolveState compiler_type_resolve_state, uint32_t opaque_payload=0) override
This function is used to create types that belong to a SymbolFile.
Definition: SymbolFile.h:580
Provides public interface for all SymbolFiles.
Definition: SymbolFile.h:50
virtual std::recursive_mutex & GetModuleMutex() const
Symbols file subclasses should override this to return the Module that owns the TypeSystem that this ...
Definition: SymbolFile.cpp:36
uint32_t GetSize() const
Definition: TypeList.cpp:60
void Insert(const lldb::TypeSP &type)
Definition: TypeList.cpp:27
void Insert(const lldb::TypeSP &type)
Definition: TypeMap.cpp:27
A class that contains all state required for type lookups.
Definition: Type.h:104
std::vector< lldb_private::CompilerContext > & GetContextRef()
Access the internal compiler context array.
Definition: Type.h:322
ConstString GetTypeBasename() const
Get the type basename to use when searching the type indexes in each SymbolFile object.
Definition: Type.cpp:112
bool ContextMatches(llvm::ArrayRef< lldb_private::CompilerContext > context) const
Check of a CompilerContext array from matching type from a symbol file matches the m_context.
Definition: Type.cpp:128
This class tracks the state and results of a TypeQuery.
Definition: Type.h:344
bool InsertUnique(const lldb::TypeSP &type_sp)
When types that match a TypeQuery are found, this API is used to insert the matching types.
Definition: Type.cpp:193
bool Done(const TypeQuery &query) const
Check if the type matching has found all of the matches that it needs.
Definition: Type.cpp:199
bool AlreadySearched(lldb_private::SymbolFile *sym_file)
Check if a SymbolFile object has already been searched by this type match object.
Definition: Type.cpp:189
A TypeSystem implementation based on Clang.
Interface for representing a type system.
Definition: TypeSystem.h:70
virtual npdb::PdbAstBuilder * GetNativePDBParser()
Definition: TypeSystem.h:92
@ eEncodingIsTypedefUID
This type is alias to a type whose UID is m_encoding_uid.
Definition: Type.h:434
@ eEncodingIsUID
This type is the type whose UID is m_encoding_uid.
Definition: Type.h:423
void AddVariable(const lldb::VariableSP &var_sp)
ClangASTImporter & GetClangASTImporter()
Definition: PdbAstBuilder.h:88
clang::DeclContext * GetParentDeclContext(PdbSymUid uid)
CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context)
clang::DeclContext * FromCompilerDeclContext(CompilerDeclContext context)
CompilerType ToCompilerType(clang::QualType qt)
bool CompleteType(clang::QualType qt)
clang::DeclContext * GetOrCreateDeclContextForUid(PdbSymUid uid)
void ParseDeclsForContext(clang::DeclContext &context)
clang::BlockDecl * GetOrCreateBlockDecl(PdbCompilandSymId block_id)
clang::QualType GetOrCreateType(PdbTypeSymId type)
clang::FunctionDecl * GetOrCreateInlinedFunctionDecl(PdbCompilandSymId inlinesite_id)
PdbIndex - Lazy access to the important parts of a PDB file.
Definition: PdbIndex.h:47
static llvm::Expected< std::unique_ptr< PdbIndex > > create(llvm::pdb::PDBFile *)
Definition: PdbIndex.cpp:43
llvm::pdb::TpiStream & tpi()
Definition: PdbIndex.h:124
PdbCompilandId asCompiland() const
Definition: PdbSymUid.cpp:117
PdbCompilandSymId asCompilandSym() const
Definition: PdbSymUid.cpp:125
PdbTypeSymId asTypeSym() const
Definition: PdbSymUid.cpp:144
PdbSymUidKind kind() const
Definition: PdbSymUid.cpp:112
lldb::VariableSP GetOrCreateGlobalVariable(PdbGlobalSymId var_id)
bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override
lldb::TypeSP CreateArrayType(PdbTypeSymId type_id, const llvm::codeview::ArrayRecord &ar, CompilerType ct)
std::optional< ArrayInfo > GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) override
If type_uid points to an array type, return its characteristics.
lldb::VariableSP CreateGlobalVariable(PdbGlobalSymId var_id)
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
void InitializeObject() override
Initialize the SymbolFile object.
static SymbolFile * CreateInstance(lldb::ObjectFileSP objfile_sp)
llvm::DenseMap< lldb::user_id_t, lldb::TypeSP > m_types
bool CompleteType(CompilerType &compiler_type) override
lldb::LanguageType ParseLanguage(lldb_private::CompileUnit &comp_unit) override
CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
lldb::VariableSP GetOrCreateLocalVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param)
size_t ParseVariablesForContext(const SymbolContext &sc) override
size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override
lldb::TypeSP CreatePointerType(PdbTypeSymId type_id, const llvm::codeview::PointerRecord &pr, CompilerType ct)
lldb::FunctionSP CreateFunction(PdbCompilandSymId func_id, CompileUnit &comp_unit)
llvm::DenseMap< lldb::user_id_t, lldb::BlockSP > m_blocks
bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, SupportFileList &support_files) override
CompilerDecl GetDeclForUID(lldb::user_id_t uid) override
SymbolFileNativePDB(lldb::ObjectFileSP objfile_sp)
lldb::TypeSP GetOrCreateTypedef(PdbGlobalSymId id)
void FindTypesByName(llvm::StringRef name, uint32_t max_matches, TypeMap &types)
lldb::TypeSP CreateTagType(PdbTypeSymId type_id, const llvm::codeview::ClassRecord &cr, CompilerType ct)
lldb::TypeSP GetOrCreateType(PdbTypeSymId type_id)
void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, TypeList &type_list) override
llvm::DenseMap< lldb::user_id_t, lldb::VariableSP > m_local_variables
lldb::VariableSP CreateConstantSymbol(PdbGlobalSymId var_id, const llvm::codeview::CVSymbol &cvs)
lldb::TypeSP CreateType(PdbTypeSymId type_id, CompilerType ct)
std::optional< llvm::codeview::TypeIndex > GetParentType(llvm::codeview::TypeIndex ti)
void FindFunctions(const Module::LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, bool include_inlines, SymbolContextList &sc_list) override
static llvm::StringRef GetPluginDescriptionStatic()
std::unique_ptr< llvm::pdb::PDBFile > m_file_up
lldb::VariableSP CreateLocalVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param)
lldb::TypeSP CreateProcedureType(PdbTypeSymId type_id, const llvm::codeview::ProcedureRecord &pr, CompilerType ct)
lldb::TypeSP CreateModifierType(PdbTypeSymId type_id, const llvm::codeview::ModifierRecord &mr, CompilerType ct)
uint64_t GetDebugInfoSize(bool load_all_debug_info=false) override
Metrics gathering functions.
size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override
Block * GetOrCreateBlock(PdbCompilandSymId block_id)
size_t ParseBlocksRecursive(Function &func) override
lldb::CompUnitSP CreateCompileUnit(const CompilandIndexItem &cci)
std::optional< PdbCompilandSymId > FindSymbolScope(PdbCompilandSymId id)
size_t ParseSymbolArrayInScope(PdbCompilandSymId parent, llvm::function_ref< bool(llvm::codeview::SymbolKind, PdbCompilandSymId)> fn)
size_t ParseVariablesForCompileUnit(CompileUnit &comp_unit, VariableList &variables)
llvm::DenseMap< lldb::user_id_t, lldb::CompUnitSP > m_compilands
Block * CreateBlock(PdbCompilandSymId block_id)
llvm::Expected< uint32_t > GetFileIndex(const CompilandIndexItem &cii, uint32_t file_id)
lldb::CompUnitSP GetOrCreateCompileUnit(const CompilandIndexItem &cci)
Type * ResolveTypeUID(lldb::user_id_t type_uid) override
llvm::DenseMap< lldb::user_id_t, lldb::FunctionSP > m_functions
bool ParseImportedModules(const SymbolContext &sc, std::vector< lldb_private::SourceModule > &imported_modules) override
static void DebuggerInitialize(Debugger &debugger)
llvm::DenseMap< lldb::user_id_t, std::shared_ptr< InlineSite > > m_inline_sites
void ParseInlineSite(PdbCompilandSymId inline_site_id, Address func_addr)
lldb::TypeSP CreateClassStructUnion(PdbTypeSymId type_id, const llvm::codeview::TagRecord &record, size_t size, CompilerType ct)
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, VariableList &variables) override
static llvm::StringRef GetPluginNameStatic()
size_t ParseVariablesForBlock(PdbCompilandSymId block_id)
void ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override
lldb::FunctionSP GetOrCreateFunction(PdbCompilandSymId func_id, CompileUnit &comp_unit)
llvm::DenseMap< llvm::codeview::TypeIndex, llvm::codeview::TypeIndex > m_parent_types
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
lldb::TypeSP CreateFunctionType(PdbTypeSymId type_id, const llvm::codeview::MemberFunctionRecord &pr, CompilerType ct)
lldb::TypeSP CreateAndCacheType(PdbTypeSymId type_id)
CompilerDeclContext FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx, bool only_root_namespaces) override
Finds a namespace of name name and whose parent context is parent_decl_ctx.
CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override
bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override
lldb::TypeSP CreateTypedef(PdbGlobalSymId id)
void FindTypes(const lldb_private::TypeQuery &match, lldb_private::TypeResults &results) override
Find types using a type-matching object that contains all search parameters.
uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc) override
llvm::DenseMap< lldb::user_id_t, lldb::VariableSP > m_global_vars
lldb::TypeSP CreateSimpleType(llvm::codeview::TypeIndex ti, CompilerType ct)
#define LLDB_INVALID_UID
Definition: lldb-defines.h:88
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
uint64_t toOpaqueUid(const T &cid)
Definition: PdbSymUid.h:114
size_t GetTypeSizeForSimpleKind(llvm::codeview::SimpleTypeKind kind)
SegmentOffsetLength GetSegmentOffsetAndLength(const llvm::codeview::CVSymbol &sym)
bool IsTagRecord(llvm::codeview::CVType cvt)
Definition: PdbUtil.cpp:517
bool IsValidRecord(const RecordT &sym)
Definition: PdbUtil.h:119
DWARFExpression MakeGlobalLocationExpression(uint16_t section, uint32_t offset, lldb::ModuleSP module)
VariableInfo GetVariableLocationInfo(PdbIndex &index, PdbCompilandSymId var_id, Block &func_block, lldb::ModuleSP module)
Definition: PdbUtil.cpp:734
bool IsForwardRefUdt(llvm::codeview::CVType cvt)
llvm::pdb::PDB_SymType CVSymToPDBSym(llvm::codeview::SymbolKind kind)
DWARFExpression MakeConstantLocationExpression(llvm::codeview::TypeIndex underlying_ti, llvm::pdb::TpiStream &tpi, const llvm::APSInt &constant, lldb::ModuleSP module)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:332
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Function > FunctionSP
Definition: lldb-forward.h:355
std::shared_ptr< lldb_private::Block > BlockSP
Definition: lldb-forward.h:320
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
Definition: lldb-forward.h:375
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eLanguageTypeRust
Rust.
@ eLanguageTypeObjC_plus_plus
Objective-C++.
@ eLanguageTypeSwift
Swift.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eLanguageTypeObjC
Objective-C.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
std::shared_ptr< lldb_private::Type > TypeSP
Definition: lldb-forward.h:461
std::shared_ptr< lldb_private::VariableList > VariableListSP
Definition: lldb-forward.h:487
std::shared_ptr< lldb_private::SymbolFileType > SymbolFileTypeSP
Definition: lldb-forward.h:441
std::shared_ptr< lldb_private::Variable > VariableSP
Definition: lldb-forward.h:486
uint64_t user_id_t
Definition: lldb-types.h:82
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
Definition: lldb-forward.h:335
@ eValueTypeInvalid
@ eValueTypeVariableGlobal
globals variable
@ eValueTypeVariableLocal
function local variables
@ eValueTypeVariableArgument
function argument variables
@ eValueTypeVariableStatic
static variable
@ eValueTypeVariableThreadLocal
thread local storage variable
BaseType GetRangeBase() const
Definition: RangeMap.h:45
void SetRangeEnd(BaseType end)
Definition: RangeMap.h:80
void SetRangeBase(BaseType b)
Set the start value for the range, and keep the same size.
Definition: RangeMap.h:48
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47
static CVTagRecord create(llvm::codeview::CVType type)
Definition: PdbUtil.cpp:198
const llvm::codeview::TagRecord & asTag() const
Definition: PdbUtil.h:44
llvm::StringRef name() const
Definition: PdbUtil.h:67
Represents a single compile unit.
std::map< llvm::codeview::TypeIndex, llvm::codeview::InlineeSourceLine > m_inline_map
std::optional< llvm::codeview::Compile3Sym > m_compile_opts
llvm::pdb::ModuleDebugStreamRef m_debug_stream
llvm::codeview::StringsAndChecksumsRef m_strings
std::vector< llvm::StringRef > m_file_list
llvm::codeview::TypeIndex index
Definition: PdbSymUid.h:76
DWARFExpressionList location
Definition: PdbUtil.h:105
llvm::codeview::TypeIndex type
Definition: PdbUtil.h:104