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 BlockSP child_block = std::make_shared<Block>(opaque_block_uid);
388 auto ts_or_err = GetTypeSystemForLanguage(comp_unit->GetLanguage());
389 if (auto err = ts_or_err.takeError())
390 return *child_block;
391 auto ts = *ts_or_err;
392 if (!ts)
393 return *child_block;
394 PdbAstBuilder* ast_builder = ts->GetNativePDBParser();
395
396 switch (sym.kind()) {
397 case S_GPROC32:
398 case S_LPROC32: {
399 // This is a function. It must be global. Creating the Function entry
400 // for it automatically creates a block for it.
401 FunctionSP func = GetOrCreateFunction(block_id, *comp_unit);
402 if (func) {
403 Block &block = func->GetBlock(false);
404 if (block.GetNumRanges() == 0)
405 block.AddRange(Block::Range(0, func->GetAddressRange().GetByteSize()));
406 return block;
407 }
408 break;
409 }
410 case S_BLOCK32: {
411 // This is a block. Its parent is either a function or another block. In
412 // either case, its parent can be viewed as a block (e.g. a function
413 // contains 1 big block. So just get the parent block and add this block
414 // to it.
415 BlockSym block(static_cast<SymbolRecordKind>(sym.kind()));
416 cantFail(SymbolDeserializer::deserializeAs<BlockSym>(sym, block));
417 lldbassert(block.Parent != 0);
418 PdbCompilandSymId parent_id(block_id.modi, block.Parent);
419 Block &parent_block = GetOrCreateBlock(parent_id);
420 Function *func = parent_block.CalculateSymbolContextFunction();
421 lldbassert(func);
422 lldb::addr_t block_base =
423 m_index->MakeVirtualAddress(block.Segment, block.CodeOffset);
424 lldb::addr_t func_base =
426 if (block_base >= func_base)
427 child_block->AddRange(Block::Range(block_base - func_base, block.CodeSize));
428 else {
429 GetObjectFile()->GetModule()->ReportError(
430 "S_BLOCK32 at modi: {0:d} offset: {1:d}: adding range "
431 "[{2:x16}-{3:x16}) which has a base that is less than the "
432 "function's "
433 "low PC 0x%" PRIx64 ". Please file a bug and attach the file at the "
434 "start of this error message",
435 block_id.modi, block_id.offset, block_base,
436 block_base + block.CodeSize, func_base);
437 }
438 parent_block.AddChild(child_block);
439 ast_builder->GetOrCreateBlockDecl(block_id);
440 m_blocks.insert({opaque_block_uid, child_block});
441 break;
442 }
443 case S_INLINESITE: {
444 // This ensures line table is parsed first so we have inline sites info.
445 comp_unit->GetLineTable();
446
447 std::shared_ptr<InlineSite> inline_site = m_inline_sites[opaque_block_uid];
448 Block &parent_block = GetOrCreateBlock(inline_site->parent_id);
449 parent_block.AddChild(child_block);
450 ast_builder->GetOrCreateInlinedFunctionDecl(block_id);
451 // Copy ranges from InlineSite to Block.
452 for (size_t i = 0; i < inline_site->ranges.GetSize(); ++i) {
453 auto *entry = inline_site->ranges.GetEntryAtIndex(i);
454 child_block->AddRange(
455 Block::Range(entry->GetRangeBase(), entry->GetByteSize()));
456 }
457 child_block->FinalizeRanges();
458
459 // Get the inlined function callsite info.
460 Declaration &decl = inline_site->inline_function_info->GetDeclaration();
461 Declaration &callsite = inline_site->inline_function_info->GetCallSite();
462 child_block->SetInlinedFunctionInfo(
463 inline_site->inline_function_info->GetName().GetCString(), nullptr,
464 &decl, &callsite);
465 m_blocks.insert({opaque_block_uid, child_block});
466 break;
467 }
468 default:
469 lldbassert(false && "Symbol is not a block!");
470 }
471
472 return *child_block;
473}
474
476 CompileUnit &comp_unit) {
477 const CompilandIndexItem *cci =
478 m_index->compilands().GetCompiland(func_id.modi);
479 lldbassert(cci);
480 CVSymbol sym_record = cci->m_debug_stream.readSymbolAtOffset(func_id.offset);
481
482 lldbassert(sym_record.kind() == S_LPROC32 || sym_record.kind() == S_GPROC32);
484
485 auto file_vm_addr =
486 m_index->MakeVirtualAddress(sol.so.segment, sol.so.offset);
487 if (file_vm_addr == LLDB_INVALID_ADDRESS || file_vm_addr == 0)
488 return nullptr;
489
490 AddressRange func_range(file_vm_addr, sol.length,
491 comp_unit.GetModule()->GetSectionList());
492 if (!func_range.GetBaseAddress().IsValid())
493 return nullptr;
494
495 ProcSym proc(static_cast<SymbolRecordKind>(sym_record.kind()));
496 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc));
497 if (proc.FunctionType == TypeIndex::None())
498 return nullptr;
499 TypeSP func_type = GetOrCreateType(proc.FunctionType);
500 if (!func_type)
501 return nullptr;
502
503 PdbTypeSymId sig_id(proc.FunctionType, false);
504 Mangled mangled(proc.Name);
505 FunctionSP func_sp = std::make_shared<Function>(
506 &comp_unit, toOpaqueUid(func_id), toOpaqueUid(sig_id), mangled,
507 func_type.get(), func_range);
508
509 comp_unit.AddFunction(func_sp);
510
511 auto ts_or_err = GetTypeSystemForLanguage(comp_unit.GetLanguage());
512 if (auto err = ts_or_err.takeError())
513 return func_sp;
514 auto ts = *ts_or_err;
515 if (!ts)
516 return func_sp;
517 ts->GetNativePDBParser()->GetOrCreateFunctionDecl(func_id);
518
519 return func_sp;
520}
521
524 lldb::LanguageType lang =
525 cci.m_compile_opts ? TranslateLanguage(cci.m_compile_opts->getLanguage())
527
528 LazyBool optimized = eLazyBoolNo;
529 if (cci.m_compile_opts && cci.m_compile_opts->hasOptimizations())
530 optimized = eLazyBoolYes;
531
532 llvm::SmallString<64> source_file_name =
533 m_index->compilands().GetMainSourceFile(cci);
534 FileSpec fs(llvm::sys::path::convert_to_slash(
535 source_file_name, llvm::sys::path::Style::windows_backslash));
536
537 CompUnitSP cu_sp =
538 std::make_shared<CompileUnit>(m_objfile_sp->GetModule(), nullptr, fs,
539 toOpaqueUid(cci.m_id), lang, optimized);
540
541 SetCompileUnitAtIndex(cci.m_id.modi, cu_sp);
542 return cu_sp;
543}
544
546 const ModifierRecord &mr,
547 CompilerType ct) {
548 TpiStream &stream = m_index->tpi();
549
550 std::string name;
551 if (mr.ModifiedType.isSimple())
552 name = std::string(GetSimpleTypeName(mr.ModifiedType.getSimpleKind()));
553 else
554 name = computeTypeName(stream.typeCollection(), mr.ModifiedType);
555 Declaration decl;
556 lldb::TypeSP modified_type = GetOrCreateType(mr.ModifiedType);
557
558 return MakeType(toOpaqueUid(type_id), ConstString(name),
559 modified_type->GetByteSize(nullptr), nullptr,
562}
563
566 const llvm::codeview::PointerRecord &pr,
567 CompilerType ct) {
568 TypeSP pointee = GetOrCreateType(pr.ReferentType);
569 if (!pointee)
570 return nullptr;
571
572 if (pr.isPointerToMember()) {
573 MemberPointerInfo mpi = pr.getMemberInfo();
574 GetOrCreateType(mpi.ContainingType);
575 }
576
577 Declaration decl;
578 return MakeType(toOpaqueUid(type_id), ConstString(), pr.getSize(), nullptr,
581}
582
584 CompilerType ct) {
585 uint64_t uid = toOpaqueUid(PdbTypeSymId(ti, false));
586 if (ti == TypeIndex::NullptrT()) {
587 Declaration decl;
588 return MakeType(uid, ConstString("std::nullptr_t"), 0, nullptr,
591 }
592
593 if (ti.getSimpleMode() != SimpleTypeMode::Direct) {
594 TypeSP direct_sp = GetOrCreateType(ti.makeDirect());
595 uint32_t pointer_size = 0;
596 switch (ti.getSimpleMode()) {
597 case SimpleTypeMode::FarPointer32:
598 case SimpleTypeMode::NearPointer32:
599 pointer_size = 4;
600 break;
601 case SimpleTypeMode::NearPointer64:
602 pointer_size = 8;
603 break;
604 default:
605 // 128-bit and 16-bit pointers unsupported.
606 return nullptr;
607 }
608 Declaration decl;
609 return MakeType(uid, ConstString(), pointer_size, nullptr, LLDB_INVALID_UID,
611 }
612
613 if (ti.getSimpleKind() == SimpleTypeKind::NotTranslated)
614 return nullptr;
615
616 size_t size = GetTypeSizeForSimpleKind(ti.getSimpleKind());
617 llvm::StringRef type_name = GetSimpleTypeName(ti.getSimpleKind());
618
619 Declaration decl;
620 return MakeType(uid, ConstString(type_name), size, nullptr, LLDB_INVALID_UID,
622}
623
624static std::string GetUnqualifiedTypeName(const TagRecord &record) {
625 if (!record.hasUniqueName()) {
626 MSVCUndecoratedNameParser parser(record.Name);
627 llvm::ArrayRef<MSVCUndecoratedNameSpecifier> specs = parser.GetSpecifiers();
628
629 return std::string(specs.back().GetBaseName());
630 }
631
632 llvm::ms_demangle::Demangler demangler;
633 std::string_view sv(record.UniqueName.begin(), record.UniqueName.size());
634 llvm::ms_demangle::TagTypeNode *ttn = demangler.parseTagUniqueName(sv);
635 if (demangler.Error)
636 return std::string(record.Name);
637
638 llvm::ms_demangle::IdentifierNode *idn =
639 ttn->QualifiedName->getUnqualifiedIdentifier();
640 return idn->toString();
641}
642
645 const TagRecord &record,
646 size_t size, CompilerType ct) {
647
648 std::string uname = GetUnqualifiedTypeName(record);
649
650 // FIXME: Search IPI stream for LF_UDT_MOD_SRC_LINE.
651 Declaration decl;
652 return MakeType(toOpaqueUid(type_id), ConstString(uname), size, nullptr,
655}
656
658 const ClassRecord &cr,
659 CompilerType ct) {
660 return CreateClassStructUnion(type_id, cr, cr.getSize(), ct);
661}
662
664 const UnionRecord &ur,
665 CompilerType ct) {
666 return CreateClassStructUnion(type_id, ur, ur.getSize(), ct);
667}
668
670 const EnumRecord &er,
671 CompilerType ct) {
672 std::string uname = GetUnqualifiedTypeName(er);
673
674 Declaration decl;
675 TypeSP underlying_type = GetOrCreateType(er.UnderlyingType);
676
677 return MakeType(toOpaqueUid(type_id), ConstString(uname),
678 underlying_type->GetByteSize(nullptr), nullptr,
681}
682
684 const ArrayRecord &ar,
685 CompilerType ct) {
686 TypeSP element_type = GetOrCreateType(ar.ElementType);
687
688 Declaration decl;
689 TypeSP array_sp =
690 MakeType(toOpaqueUid(type_id), ConstString(), ar.Size, nullptr,
693 array_sp->SetEncodingType(element_type.get());
694 return array_sp;
695}
696
698 const MemberFunctionRecord &mfr,
699 CompilerType ct) {
700 Declaration decl;
701 return MakeType(toOpaqueUid(type_id), ConstString(), 0, nullptr,
704}
705
707 const ProcedureRecord &pr,
708 CompilerType ct) {
709 Declaration decl;
710 return MakeType(toOpaqueUid(type_id), ConstString(), 0, nullptr,
713}
714
716 if (type_id.index.isSimple())
717 return CreateSimpleType(type_id.index, ct);
718
719 TpiStream &stream = type_id.is_ipi ? m_index->ipi() : m_index->tpi();
720 CVType cvt = stream.getType(type_id.index);
721
722 if (cvt.kind() == LF_MODIFIER) {
723 ModifierRecord modifier;
724 llvm::cantFail(
725 TypeDeserializer::deserializeAs<ModifierRecord>(cvt, modifier));
726 return CreateModifierType(type_id, modifier, ct);
727 }
728
729 if (cvt.kind() == LF_POINTER) {
730 PointerRecord pointer;
731 llvm::cantFail(
732 TypeDeserializer::deserializeAs<PointerRecord>(cvt, pointer));
733 return CreatePointerType(type_id, pointer, ct);
734 }
735
736 if (IsClassRecord(cvt.kind())) {
737 ClassRecord cr;
738 llvm::cantFail(TypeDeserializer::deserializeAs<ClassRecord>(cvt, cr));
739 return CreateTagType(type_id, cr, ct);
740 }
741
742 if (cvt.kind() == LF_ENUM) {
743 EnumRecord er;
744 llvm::cantFail(TypeDeserializer::deserializeAs<EnumRecord>(cvt, er));
745 return CreateTagType(type_id, er, ct);
746 }
747
748 if (cvt.kind() == LF_UNION) {
749 UnionRecord ur;
750 llvm::cantFail(TypeDeserializer::deserializeAs<UnionRecord>(cvt, ur));
751 return CreateTagType(type_id, ur, ct);
752 }
753
754 if (cvt.kind() == LF_ARRAY) {
755 ArrayRecord ar;
756 llvm::cantFail(TypeDeserializer::deserializeAs<ArrayRecord>(cvt, ar));
757 return CreateArrayType(type_id, ar, ct);
758 }
759
760 if (cvt.kind() == LF_PROCEDURE) {
761 ProcedureRecord pr;
762 llvm::cantFail(TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr));
763 return CreateProcedureType(type_id, pr, ct);
764 }
765 if (cvt.kind() == LF_MFUNCTION) {
766 MemberFunctionRecord mfr;
767 llvm::cantFail(TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr));
768 return CreateFunctionType(type_id, mfr, ct);
769 }
770
771 return nullptr;
772}
773
775 // If they search for a UDT which is a forward ref, try and resolve the full
776 // decl and just map the forward ref uid to the full decl record.
777 std::optional<PdbTypeSymId> full_decl_uid;
778 if (IsForwardRefUdt(type_id, m_index->tpi())) {
779 auto expected_full_ti =
780 m_index->tpi().findFullDeclForForwardRef(type_id.index);
781 if (!expected_full_ti)
782 llvm::consumeError(expected_full_ti.takeError());
783 else if (*expected_full_ti != type_id.index) {
784 full_decl_uid = PdbTypeSymId(*expected_full_ti, false);
785
786 // It's possible that a lookup would occur for the full decl causing it
787 // to be cached, then a second lookup would occur for the forward decl.
788 // We don't want to create a second full decl, so make sure the full
789 // decl hasn't already been cached.
790 auto full_iter = m_types.find(toOpaqueUid(*full_decl_uid));
791 if (full_iter != m_types.end()) {
792 TypeSP result = full_iter->second;
793 // Map the forward decl to the TypeSP for the full decl so we can take
794 // the fast path next time.
795 m_types[toOpaqueUid(type_id)] = result;
796 return result;
797 }
798 }
799 }
800
801 PdbTypeSymId best_decl_id = full_decl_uid ? *full_decl_uid : type_id;
803 if (auto err = ts_or_err.takeError())
804 return nullptr;
805 auto ts = *ts_or_err;
806 if (!ts)
807 return nullptr;
808
809 PdbAstBuilder* ast_builder = ts->GetNativePDBParser();
810 clang::QualType qt = ast_builder->GetOrCreateType(best_decl_id);
811 if (qt.isNull())
812 return nullptr;
813
814 TypeSP result = CreateType(best_decl_id, ast_builder->ToCompilerType(qt));
815 if (!result)
816 return nullptr;
817
818 uint64_t best_uid = toOpaqueUid(best_decl_id);
819 m_types[best_uid] = result;
820 // If we had both a forward decl and a full decl, make both point to the new
821 // type.
822 if (full_decl_uid)
823 m_types[toOpaqueUid(type_id)] = result;
824
825 return result;
826}
827
829 // We can't use try_emplace / overwrite here because the process of creating
830 // a type could create nested types, which could invalidate iterators. So
831 // we have to do a 2-phase lookup / insert.
832 auto iter = m_types.find(toOpaqueUid(type_id));
833 if (iter != m_types.end())
834 return iter->second;
835
836 TypeSP type = CreateAndCacheType(type_id);
837 if (type)
838 GetTypeList().Insert(type);
839 return type;
840}
841
843 CVSymbol sym = m_index->symrecords().readRecord(var_id.offset);
844 if (sym.kind() == S_CONSTANT)
845 return CreateConstantSymbol(var_id, sym);
846
848 TypeIndex ti;
849 llvm::StringRef name;
850 lldb::addr_t addr = 0;
851 uint16_t section = 0;
852 uint32_t offset = 0;
853 bool is_external = false;
854 switch (sym.kind()) {
855 case S_GDATA32:
856 is_external = true;
857 [[fallthrough]];
858 case S_LDATA32: {
859 DataSym ds(sym.kind());
860 llvm::cantFail(SymbolDeserializer::deserializeAs<DataSym>(sym, ds));
861 ti = ds.Type;
862 scope = (sym.kind() == S_GDATA32) ? eValueTypeVariableGlobal
864 name = ds.Name;
865 section = ds.Segment;
866 offset = ds.DataOffset;
867 addr = m_index->MakeVirtualAddress(ds.Segment, ds.DataOffset);
868 break;
869 }
870 case S_GTHREAD32:
871 is_external = true;
872 [[fallthrough]];
873 case S_LTHREAD32: {
874 ThreadLocalDataSym tlds(sym.kind());
875 llvm::cantFail(
876 SymbolDeserializer::deserializeAs<ThreadLocalDataSym>(sym, tlds));
877 ti = tlds.Type;
878 name = tlds.Name;
879 section = tlds.Segment;
880 offset = tlds.DataOffset;
881 addr = m_index->MakeVirtualAddress(tlds.Segment, tlds.DataOffset);
883 break;
884 }
885 default:
886 llvm_unreachable("unreachable!");
887 }
888
889 CompUnitSP comp_unit;
890 std::optional<uint16_t> modi = m_index->GetModuleIndexForVa(addr);
891 if (!modi) {
892 return nullptr;
893 }
894
895 CompilandIndexItem &cci = m_index->compilands().GetOrCreateCompiland(*modi);
896 comp_unit = GetOrCreateCompileUnit(cci);
897
898 Declaration decl;
899 PdbTypeSymId tid(ti, false);
900 SymbolFileTypeSP type_sp =
901 std::make_shared<SymbolFileType>(*this, toOpaqueUid(tid));
902 Variable::RangeList ranges;
903 auto ts_or_err = GetTypeSystemForLanguage(comp_unit->GetLanguage());
904 if (auto err = ts_or_err.takeError())
905 return nullptr;
906 auto ts = *ts_or_err;
907 if (!ts)
908 return nullptr;
909
910 ts->GetNativePDBParser()->GetOrCreateVariableDecl(var_id);
911
912 ModuleSP module_sp = GetObjectFile()->GetModule();
913 DWARFExpressionList location(
914 module_sp, MakeGlobalLocationExpression(section, offset, module_sp),
915 nullptr);
916
917 std::string global_name("::");
918 global_name += name;
919 bool artificial = false;
920 bool location_is_constant_data = false;
921 bool static_member = false;
922 VariableSP var_sp = std::make_shared<Variable>(
923 toOpaqueUid(var_id), name.str().c_str(), global_name.c_str(), type_sp,
924 scope, comp_unit.get(), ranges, &decl, location, is_external, artificial,
925 location_is_constant_data, static_member);
926
927 return var_sp;
928}
929
932 const CVSymbol &cvs) {
933 TpiStream &tpi = m_index->tpi();
934 ConstantSym constant(cvs.kind());
935
936 llvm::cantFail(SymbolDeserializer::deserializeAs<ConstantSym>(cvs, constant));
937 std::string global_name("::");
938 global_name += constant.Name;
939 PdbTypeSymId tid(constant.Type, false);
940 SymbolFileTypeSP type_sp =
941 std::make_shared<SymbolFileType>(*this, toOpaqueUid(tid));
942
943 Declaration decl;
944 Variable::RangeList ranges;
945 ModuleSP module = GetObjectFile()->GetModule();
946 DWARFExpressionList location(module,
948 constant.Type, tpi, constant.Value, module),
949 nullptr);
950
951 bool external = false;
952 bool artificial = false;
953 bool location_is_constant_data = true;
954 bool static_member = false;
955 VariableSP var_sp = std::make_shared<Variable>(
956 toOpaqueUid(var_id), constant.Name.str().c_str(), global_name.c_str(),
957 type_sp, eValueTypeVariableGlobal, module.get(), ranges, &decl, location,
958 external, artificial, location_is_constant_data, static_member);
959 return var_sp;
960}
961
964 auto emplace_result = m_global_vars.try_emplace(toOpaqueUid(var_id), nullptr);
965 if (emplace_result.second) {
966 if (VariableSP var_sp = CreateGlobalVariable(var_id))
967 emplace_result.first->second = var_sp;
968 else
969 return nullptr;
970 }
971
972 return emplace_result.first->second;
973}
974
976 return GetOrCreateType(PdbTypeSymId(ti, false));
977}
978
980 CompileUnit &comp_unit) {
981 auto emplace_result = m_functions.try_emplace(toOpaqueUid(func_id), nullptr);
982 if (emplace_result.second)
983 emplace_result.first->second = CreateFunction(func_id, comp_unit);
984
985 return emplace_result.first->second;
986}
987
990
991 auto emplace_result =
992 m_compilands.try_emplace(toOpaqueUid(cci.m_id), nullptr);
993 if (emplace_result.second)
994 emplace_result.first->second = CreateCompileUnit(cci);
995
996 lldbassert(emplace_result.first->second);
997 return emplace_result.first->second;
998}
999
1001 auto iter = m_blocks.find(toOpaqueUid(block_id));
1002 if (iter != m_blocks.end())
1003 return *iter->second;
1004
1005 return CreateBlock(block_id);
1006}
1007
1010 TypeSystem* ts_or_err = decl_ctx.GetTypeSystem();
1011 if (!ts_or_err)
1012 return;
1013 PdbAstBuilder* ast_builder = ts_or_err->GetNativePDBParser();
1014 clang::DeclContext *context = ast_builder->FromCompilerDeclContext(decl_ctx);
1015 if (!context)
1016 return;
1017 ast_builder->ParseDeclsForContext(*context);
1018}
1019
1021 if (index >= GetNumCompileUnits())
1022 return CompUnitSP();
1023 lldbassert(index < UINT16_MAX);
1024 if (index >= UINT16_MAX)
1025 return nullptr;
1026
1027 CompilandIndexItem &item = m_index->compilands().GetOrCreateCompiland(index);
1028
1029 return GetOrCreateCompileUnit(item);
1030}
1031
1033 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1034 PdbSymUid uid(comp_unit.GetID());
1036
1037 CompilandIndexItem *item =
1038 m_index->compilands().GetCompiland(uid.asCompiland().modi);
1039 lldbassert(item);
1040 if (!item->m_compile_opts)
1042
1043 return TranslateLanguage(item->m_compile_opts->getLanguage());
1044}
1045
1047
1049 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1050 PdbSymUid uid{comp_unit.GetID()};
1051 lldbassert(uid.kind() == PdbSymUidKind::Compiland);
1052 uint16_t modi = uid.asCompiland().modi;
1053 CompilandIndexItem &cii = m_index->compilands().GetOrCreateCompiland(modi);
1054
1055 size_t count = comp_unit.GetNumFunctions();
1056 const CVSymbolArray &syms = cii.m_debug_stream.getSymbolArray();
1057 for (auto iter = syms.begin(); iter != syms.end(); ++iter) {
1058 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32)
1059 continue;
1060
1061 PdbCompilandSymId sym_id{modi, iter.offset()};
1062
1063 FunctionSP func = GetOrCreateFunction(sym_id, comp_unit);
1064 }
1065
1066 size_t new_count = comp_unit.GetNumFunctions();
1067 lldbassert(new_count >= count);
1068 return new_count - count;
1069}
1070
1071static bool NeedsResolvedCompileUnit(uint32_t resolve_scope) {
1072 // If any of these flags are set, we need to resolve the compile unit.
1073 uint32_t flags = eSymbolContextCompUnit;
1074 flags |= eSymbolContextVariable;
1075 flags |= eSymbolContextFunction;
1076 flags |= eSymbolContextBlock;
1077 flags |= eSymbolContextLineEntry;
1078 return (resolve_scope & flags) != 0;
1079}
1080
1082 const Address &addr, SymbolContextItem resolve_scope, SymbolContext &sc) {
1083 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1084 uint32_t resolved_flags = 0;
1085 lldb::addr_t file_addr = addr.GetFileAddress();
1086
1087 if (NeedsResolvedCompileUnit(resolve_scope)) {
1088 std::optional<uint16_t> modi = m_index->GetModuleIndexForVa(file_addr);
1089 if (!modi)
1090 return 0;
1091 CompUnitSP cu_sp = GetCompileUnitAtIndex(*modi);
1092 if (!cu_sp)
1093 return 0;
1094
1095 sc.comp_unit = cu_sp.get();
1096 resolved_flags |= eSymbolContextCompUnit;
1097 }
1098
1099 if (resolve_scope & eSymbolContextFunction ||
1100 resolve_scope & eSymbolContextBlock) {
1102 std::vector<SymbolAndUid> matches = m_index->FindSymbolsByVa(file_addr);
1103 // Search the matches in reverse. This way if there are multiple matches
1104 // (for example we are 3 levels deep in a nested scope) it will find the
1105 // innermost one first.
1106 for (const auto &match : llvm::reverse(matches)) {
1107 if (match.uid.kind() != PdbSymUidKind::CompilandSym)
1108 continue;
1109
1110 PdbCompilandSymId csid = match.uid.asCompilandSym();
1111 CVSymbol cvs = m_index->ReadSymbolRecord(csid);
1112 PDB_SymType type = CVSymToPDBSym(cvs.kind());
1113 if (type != PDB_SymType::Function && type != PDB_SymType::Block)
1114 continue;
1115 if (type == PDB_SymType::Function) {
1116 sc.function = GetOrCreateFunction(csid, *sc.comp_unit).get();
1117 if (sc.function) {
1118 Block &block = sc.function->GetBlock(true);
1119 addr_t func_base =
1121 addr_t offset = file_addr - func_base;
1122 sc.block = block.FindInnermostBlockByOffset(offset);
1123 }
1124 }
1125
1126 if (type == PDB_SymType::Block) {
1127 Block &block = GetOrCreateBlock(csid);
1129 if (sc.function) {
1130 sc.function->GetBlock(true);
1131 addr_t func_base =
1133 addr_t offset = file_addr - func_base;
1134 sc.block = block.FindInnermostBlockByOffset(offset);
1135 }
1136 }
1137 if (sc.function)
1138 resolved_flags |= eSymbolContextFunction;
1139 if (sc.block)
1140 resolved_flags |= eSymbolContextBlock;
1141 break;
1142 }
1143 }
1144
1145 if (resolve_scope & eSymbolContextLineEntry) {
1147 if (auto *line_table = sc.comp_unit->GetLineTable()) {
1148 if (line_table->FindLineEntryByAddress(addr, sc.line_entry))
1149 resolved_flags |= eSymbolContextLineEntry;
1150 }
1151 }
1152
1153 return resolved_flags;
1154}
1155
1157 const SourceLocationSpec &src_location_spec,
1158 lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
1159 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1160 const uint32_t prev_size = sc_list.GetSize();
1161 if (resolve_scope & eSymbolContextCompUnit) {
1162 for (uint32_t cu_idx = 0, num_cus = GetNumCompileUnits(); cu_idx < num_cus;
1163 ++cu_idx) {
1164 CompileUnit *cu = ParseCompileUnitAtIndex(cu_idx).get();
1165 if (!cu)
1166 continue;
1167
1168 bool file_spec_matches_cu_file_spec = FileSpec::Match(
1169 src_location_spec.GetFileSpec(), cu->GetPrimaryFile());
1170 if (file_spec_matches_cu_file_spec) {
1171 cu->ResolveSymbolContext(src_location_spec, resolve_scope, sc_list);
1172 break;
1173 }
1174 }
1175 }
1176 return sc_list.GetSize() - prev_size;
1177}
1178
1180 // Unfortunately LLDB is set up to parse the entire compile unit line table
1181 // all at once, even if all it really needs is line info for a specific
1182 // function. In the future it would be nice if it could set the sc.m_function
1183 // member, and we could only get the line info for the function in question.
1184 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1185 PdbSymUid cu_id(comp_unit.GetID());
1187 uint16_t modi = cu_id.asCompiland().modi;
1188 CompilandIndexItem *cii = m_index->compilands().GetCompiland(modi);
1189 lldbassert(cii);
1190
1191 // Parse DEBUG_S_LINES subsections first, then parse all S_INLINESITE records
1192 // in this CU. Add line entries into the set first so that if there are line
1193 // entries with same addres, the later is always more accurate than the
1194 // former.
1195 std::set<LineTable::Entry, LineTableEntryComparator> line_set;
1196
1197 // This is basically a copy of the .debug$S subsections from all original COFF
1198 // object files merged together with address relocations applied. We are
1199 // looking for all DEBUG_S_LINES subsections.
1200 for (const DebugSubsectionRecord &dssr :
1201 cii->m_debug_stream.getSubsectionsArray()) {
1202 if (dssr.kind() != DebugSubsectionKind::Lines)
1203 continue;
1204
1205 DebugLinesSubsectionRef lines;
1206 llvm::BinaryStreamReader reader(dssr.getRecordData());
1207 if (auto EC = lines.initialize(reader)) {
1208 llvm::consumeError(std::move(EC));
1209 return false;
1210 }
1211
1212 const LineFragmentHeader *lfh = lines.header();
1213 uint64_t virtual_addr =
1214 m_index->MakeVirtualAddress(lfh->RelocSegment, lfh->RelocOffset);
1215 if (virtual_addr == LLDB_INVALID_ADDRESS)
1216 continue;
1217
1218 for (const LineColumnEntry &group : lines) {
1219 llvm::Expected<uint32_t> file_index_or_err =
1220 GetFileIndex(*cii, group.NameIndex);
1221 if (!file_index_or_err)
1222 continue;
1223 uint32_t file_index = file_index_or_err.get();
1224 lldbassert(!group.LineNumbers.empty());
1227 for (const LineNumberEntry &entry : group.LineNumbers) {
1228 LineInfo cur_info(entry.Flags);
1229
1230 if (cur_info.isAlwaysStepInto() || cur_info.isNeverStepInto())
1231 continue;
1232
1233 uint64_t addr = virtual_addr + entry.Offset;
1234
1235 bool is_statement = cur_info.isStatement();
1236 bool is_prologue = IsFunctionPrologue(*cii, addr);
1237 bool is_epilogue = IsFunctionEpilogue(*cii, addr);
1238
1239 uint32_t lno = cur_info.getStartLine();
1240
1241 LineTable::Entry new_entry(addr, lno, 0, file_index, is_statement, false,
1242 is_prologue, is_epilogue, false);
1243 // Terminal entry has lower precedence than new entry.
1244 auto iter = line_set.find(new_entry);
1245 if (iter != line_set.end() && iter->is_terminal_entry)
1246 line_set.erase(iter);
1247 line_set.insert(new_entry);
1248
1249 if (line_entry.GetRangeBase() != LLDB_INVALID_ADDRESS) {
1250 line_entry.SetRangeEnd(addr);
1251 cii->m_global_line_table.Append(line_entry);
1252 }
1253 line_entry.SetRangeBase(addr);
1254 line_entry.data = {file_index, lno};
1255 }
1256 LineInfo last_line(group.LineNumbers.back().Flags);
1257 line_set.emplace(virtual_addr + lfh->CodeSize, last_line.getEndLine(), 0,
1258 file_index, false, false, false, false, true);
1259
1260 if (line_entry.GetRangeBase() != LLDB_INVALID_ADDRESS) {
1261 line_entry.SetRangeEnd(virtual_addr + lfh->CodeSize);
1262 cii->m_global_line_table.Append(line_entry);
1263 }
1264 }
1265 }
1266
1268
1269 // Parse all S_INLINESITE in this CU.
1270 const CVSymbolArray &syms = cii->m_debug_stream.getSymbolArray();
1271 for (auto iter = syms.begin(); iter != syms.end();) {
1272 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32) {
1273 ++iter;
1274 continue;
1275 }
1276
1277 uint32_t record_offset = iter.offset();
1278 CVSymbol func_record =
1279 cii->m_debug_stream.readSymbolAtOffset(record_offset);
1281 addr_t file_vm_addr =
1282 m_index->MakeVirtualAddress(sol.so.segment, sol.so.offset);
1283 if (file_vm_addr == LLDB_INVALID_ADDRESS)
1284 continue;
1285
1286 AddressRange func_range(file_vm_addr, sol.length,
1287 comp_unit.GetModule()->GetSectionList());
1288 Address func_base = func_range.GetBaseAddress();
1289 PdbCompilandSymId func_id{modi, record_offset};
1290
1291 // Iterate all S_INLINESITEs in the function.
1292 auto parse_inline_sites = [&](SymbolKind kind, PdbCompilandSymId id) {
1293 if (kind != S_INLINESITE)
1294 return false;
1295
1296 ParseInlineSite(id, func_base);
1297
1298 for (const auto &line_entry :
1299 m_inline_sites[toOpaqueUid(id)]->line_entries) {
1300 // If line_entry is not terminal entry, remove previous line entry at
1301 // the same address and insert new one. Terminal entry inside an inline
1302 // site might not be terminal entry for its parent.
1303 if (!line_entry.is_terminal_entry)
1304 line_set.erase(line_entry);
1305 line_set.insert(line_entry);
1306 }
1307 // No longer useful after adding to line_set.
1308 m_inline_sites[toOpaqueUid(id)]->line_entries.clear();
1309 return true;
1310 };
1311 ParseSymbolArrayInScope(func_id, parse_inline_sites);
1312 // Jump to the end of the function record.
1313 iter = syms.at(getScopeEndOffset(func_record));
1314 }
1315
1317
1318 // Add line entries in line_set to line_table.
1319 auto line_table = std::make_unique<LineTable>(&comp_unit);
1320 std::unique_ptr<LineSequence> sequence(
1321 line_table->CreateLineSequenceContainer());
1322 for (const auto &line_entry : line_set) {
1323 line_table->AppendLineEntryToSequence(
1324 sequence.get(), line_entry.file_addr, line_entry.line,
1325 line_entry.column, line_entry.file_idx,
1326 line_entry.is_start_of_statement, line_entry.is_start_of_basic_block,
1327 line_entry.is_prologue_end, line_entry.is_epilogue_begin,
1328 line_entry.is_terminal_entry);
1329 }
1330 line_table->InsertSequence(sequence.get());
1331
1332 if (line_table->GetSize() == 0)
1333 return false;
1334
1335 comp_unit.SetLineTable(line_table.release());
1336 return true;
1337}
1338
1340 // PDB doesn't contain information about macros
1341 return false;
1342}
1343
1344llvm::Expected<uint32_t>
1346 uint32_t file_id) {
1347 if (!cii.m_strings.hasChecksums() || !cii.m_strings.hasStrings())
1348 return llvm::make_error<RawError>(raw_error_code::no_entry);
1349
1350 const auto &checksums = cii.m_strings.checksums().getArray();
1351 const auto &strings = cii.m_strings.strings();
1352 // Indices in this structure are actually offsets of records in the
1353 // DEBUG_S_FILECHECKSUMS subsection. Those entries then have an index
1354 // into the global PDB string table.
1355 auto iter = checksums.at(file_id);
1356 if (iter == checksums.end())
1357 return llvm::make_error<RawError>(raw_error_code::no_entry);
1358
1359 llvm::Expected<llvm::StringRef> efn = strings.getString(iter->FileNameOffset);
1360 if (!efn) {
1361 return efn.takeError();
1362 }
1363
1364 // LLDB wants the index of the file in the list of support files.
1365 auto fn_iter = llvm::find(cii.m_file_list, *efn);
1366 if (fn_iter != cii.m_file_list.end())
1367 return std::distance(cii.m_file_list.begin(), fn_iter);
1368 return llvm::make_error<RawError>(raw_error_code::no_entry);
1369}
1370
1372 FileSpecList &support_files) {
1373 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1374 PdbSymUid cu_id(comp_unit.GetID());
1376 CompilandIndexItem *cci =
1377 m_index->compilands().GetCompiland(cu_id.asCompiland().modi);
1378 lldbassert(cci);
1379
1380 for (llvm::StringRef f : cci->m_file_list) {
1381 FileSpec::Style style =
1382 f.startswith("/") ? FileSpec::Style::posix : FileSpec::Style::windows;
1383 FileSpec spec(f, style);
1384 support_files.Append(spec);
1385 }
1386 return true;
1387}
1388
1390 const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
1391 // PDB does not yet support module debug info
1392 return false;
1393}
1394
1396 Address func_addr) {
1397 lldb::user_id_t opaque_uid = toOpaqueUid(id);
1398 if (m_inline_sites.contains(opaque_uid))
1399 return;
1400
1401 addr_t func_base = func_addr.GetFileAddress();
1402 CompilandIndexItem *cii = m_index->compilands().GetCompiland(id.modi);
1403 CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(id.offset);
1404 CompUnitSP comp_unit = GetOrCreateCompileUnit(*cii);
1405
1406 InlineSiteSym inline_site(static_cast<SymbolRecordKind>(sym.kind()));
1407 cantFail(SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site));
1408 PdbCompilandSymId parent_id(id.modi, inline_site.Parent);
1409
1410 std::shared_ptr<InlineSite> inline_site_sp =
1411 std::make_shared<InlineSite>(parent_id);
1412
1413 // Get the inlined function declaration info.
1414 auto iter = cii->m_inline_map.find(inline_site.Inlinee);
1415 if (iter == cii->m_inline_map.end())
1416 return;
1417 InlineeSourceLine inlinee_line = iter->second;
1418
1419 const FileSpecList &files = comp_unit->GetSupportFiles();
1420 FileSpec decl_file;
1421 llvm::Expected<uint32_t> file_index_or_err =
1422 GetFileIndex(*cii, inlinee_line.Header->FileID);
1423 if (!file_index_or_err)
1424 return;
1425 uint32_t file_offset = file_index_or_err.get();
1426 decl_file = files.GetFileSpecAtIndex(file_offset);
1427 uint32_t decl_line = inlinee_line.Header->SourceLineNum;
1428 std::unique_ptr<Declaration> decl_up =
1429 std::make_unique<Declaration>(decl_file, decl_line);
1430
1431 // Parse range and line info.
1432 uint32_t code_offset = 0;
1433 int32_t line_offset = 0;
1434 std::optional<uint32_t> code_offset_base;
1435 std::optional<uint32_t> code_offset_end;
1436 std::optional<int32_t> cur_line_offset;
1437 std::optional<int32_t> next_line_offset;
1438 std::optional<uint32_t> next_file_offset;
1439
1440 bool is_terminal_entry = false;
1441 bool is_start_of_statement = true;
1442 // The first instruction is the prologue end.
1443 bool is_prologue_end = true;
1444
1445 auto update_code_offset = [&](uint32_t code_delta) {
1446 if (!code_offset_base)
1447 code_offset_base = code_offset;
1448 else if (!code_offset_end)
1449 code_offset_end = *code_offset_base + code_delta;
1450 };
1451 auto update_line_offset = [&](int32_t line_delta) {
1452 line_offset += line_delta;
1453 if (!code_offset_base || !cur_line_offset)
1454 cur_line_offset = line_offset;
1455 else
1456 next_line_offset = line_offset;
1457 ;
1458 };
1459 auto update_file_offset = [&](uint32_t offset) {
1460 if (!code_offset_base)
1461 file_offset = offset;
1462 else
1463 next_file_offset = offset;
1464 };
1465
1466 for (auto &annot : inline_site.annotations()) {
1467 switch (annot.OpCode) {
1468 case BinaryAnnotationsOpCode::CodeOffset:
1469 case BinaryAnnotationsOpCode::ChangeCodeOffset:
1470 case BinaryAnnotationsOpCode::ChangeCodeOffsetBase:
1471 code_offset += annot.U1;
1472 update_code_offset(annot.U1);
1473 break;
1474 case BinaryAnnotationsOpCode::ChangeLineOffset:
1475 update_line_offset(annot.S1);
1476 break;
1477 case BinaryAnnotationsOpCode::ChangeCodeLength:
1478 update_code_offset(annot.U1);
1479 code_offset += annot.U1;
1480 is_terminal_entry = true;
1481 break;
1482 case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset:
1483 code_offset += annot.U1;
1484 update_code_offset(annot.U1);
1485 update_line_offset(annot.S1);
1486 break;
1487 case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset:
1488 code_offset += annot.U2;
1489 update_code_offset(annot.U2);
1490 update_code_offset(annot.U1);
1491 code_offset += annot.U1;
1492 is_terminal_entry = true;
1493 break;
1494 case BinaryAnnotationsOpCode::ChangeFile:
1495 update_file_offset(annot.U1);
1496 break;
1497 default:
1498 break;
1499 }
1500
1501 // Add range if current range is finished.
1502 if (code_offset_base && code_offset_end && cur_line_offset) {
1503 inline_site_sp->ranges.Append(RangeSourceLineVector::Entry(
1504 *code_offset_base, *code_offset_end - *code_offset_base,
1505 decl_line + *cur_line_offset));
1506 // Set base, end, file offset and line offset for next range.
1507 if (next_file_offset)
1508 file_offset = *next_file_offset;
1509 if (next_line_offset) {
1510 cur_line_offset = next_line_offset;
1511 next_line_offset = std::nullopt;
1512 }
1513 code_offset_base = is_terminal_entry ? std::nullopt : code_offset_end;
1514 code_offset_end = next_file_offset = std::nullopt;
1515 }
1516 if (code_offset_base && cur_line_offset) {
1517 if (is_terminal_entry) {
1518 LineTable::Entry line_entry(
1519 func_base + *code_offset_base, decl_line + *cur_line_offset, 0,
1520 file_offset, false, false, false, false, true);
1521 inline_site_sp->line_entries.push_back(line_entry);
1522 } else {
1523 LineTable::Entry line_entry(func_base + *code_offset_base,
1524 decl_line + *cur_line_offset, 0,
1525 file_offset, is_start_of_statement, false,
1526 is_prologue_end, false, false);
1527 inline_site_sp->line_entries.push_back(line_entry);
1528 is_prologue_end = false;
1529 is_start_of_statement = false;
1530 }
1531 }
1532 if (is_terminal_entry)
1533 is_start_of_statement = true;
1534 is_terminal_entry = false;
1535 }
1536
1537 inline_site_sp->ranges.Sort();
1538
1539 // Get the inlined function callsite info.
1540 std::unique_ptr<Declaration> callsite_up;
1541 if (!inline_site_sp->ranges.IsEmpty()) {
1542 auto *entry = inline_site_sp->ranges.GetEntryAtIndex(0);
1543 addr_t base_offset = entry->GetRangeBase();
1544 if (cii->m_debug_stream.readSymbolAtOffset(parent_id.offset).kind() ==
1545 S_INLINESITE) {
1546 // Its parent is another inline site, lookup parent site's range vector
1547 // for callsite line.
1548 ParseInlineSite(parent_id, func_base);
1549 std::shared_ptr<InlineSite> parent_site =
1550 m_inline_sites[toOpaqueUid(parent_id)];
1551 FileSpec &parent_decl_file =
1552 parent_site->inline_function_info->GetDeclaration().GetFile();
1553 if (auto *parent_entry =
1554 parent_site->ranges.FindEntryThatContains(base_offset)) {
1555 callsite_up =
1556 std::make_unique<Declaration>(parent_decl_file, parent_entry->data);
1557 }
1558 } else {
1559 // Its parent is a function, lookup global line table for callsite.
1560 if (auto *entry = cii->m_global_line_table.FindEntryThatContains(
1561 func_base + base_offset)) {
1562 const FileSpec &callsite_file =
1563 files.GetFileSpecAtIndex(entry->data.first);
1564 callsite_up =
1565 std::make_unique<Declaration>(callsite_file, entry->data.second);
1566 }
1567 }
1568 }
1569
1570 // Get the inlined function name.
1571 CVType inlinee_cvt = m_index->ipi().getType(inline_site.Inlinee);
1572 std::string inlinee_name;
1573 if (inlinee_cvt.kind() == LF_MFUNC_ID) {
1574 MemberFuncIdRecord mfr;
1575 cantFail(
1576 TypeDeserializer::deserializeAs<MemberFuncIdRecord>(inlinee_cvt, mfr));
1577 LazyRandomTypeCollection &types = m_index->tpi().typeCollection();
1578 inlinee_name.append(std::string(types.getTypeName(mfr.ClassType)));
1579 inlinee_name.append("::");
1580 inlinee_name.append(mfr.getName().str());
1581 } else if (inlinee_cvt.kind() == LF_FUNC_ID) {
1582 FuncIdRecord fir;
1583 cantFail(TypeDeserializer::deserializeAs<FuncIdRecord>(inlinee_cvt, fir));
1584 TypeIndex parent_idx = fir.getParentScope();
1585 if (!parent_idx.isNoneType()) {
1586 LazyRandomTypeCollection &ids = m_index->ipi().typeCollection();
1587 inlinee_name.append(std::string(ids.getTypeName(parent_idx)));
1588 inlinee_name.append("::");
1589 }
1590 inlinee_name.append(fir.getName().str());
1591 }
1592 inline_site_sp->inline_function_info = std::make_shared<InlineFunctionInfo>(
1593 inlinee_name.c_str(), llvm::StringRef(), decl_up.get(),
1594 callsite_up.get());
1595
1596 m_inline_sites[opaque_uid] = inline_site_sp;
1597}
1598
1600 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1601 PdbCompilandSymId func_id = PdbSymUid(func.GetID()).asCompilandSym();
1602 // After we iterate through inline sites inside the function, we already get
1603 // all the info needed, removing from the map to save memory.
1604 std::set<uint64_t> remove_uids;
1605 auto parse_blocks = [&](SymbolKind kind, PdbCompilandSymId id) {
1606 if (kind == S_GPROC32 || kind == S_LPROC32 || kind == S_BLOCK32 ||
1607 kind == S_INLINESITE) {
1608 GetOrCreateBlock(id);
1609 if (kind == S_INLINESITE)
1610 remove_uids.insert(toOpaqueUid(id));
1611 return true;
1612 }
1613 return false;
1614 };
1615 size_t count = ParseSymbolArrayInScope(func_id, parse_blocks);
1616 for (uint64_t uid : remove_uids) {
1617 m_inline_sites.erase(uid);
1618 }
1619 return count;
1620}
1621
1623 PdbCompilandSymId parent_id,
1624 llvm::function_ref<bool(SymbolKind, PdbCompilandSymId)> fn) {
1625 CompilandIndexItem *cii = m_index->compilands().GetCompiland(parent_id.modi);
1626 CVSymbolArray syms =
1627 cii->m_debug_stream.getSymbolArrayForScope(parent_id.offset);
1628
1629 size_t count = 1;
1630 for (auto iter = syms.begin(); iter != syms.end(); ++iter) {
1631 PdbCompilandSymId child_id(parent_id.modi, iter.offset());
1632 if (fn(iter->kind(), child_id))
1633 ++count;
1634 }
1635
1636 return count;
1637}
1638
1641 if (!ts_or_err)
1642 return;
1643 auto ts = *ts_or_err;
1644 TypeSystemClang *clang = llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
1645 if (!clang)
1646 return;
1647 clang->GetNativePDBParser()->Dump(s);
1648}
1649
1651 ConstString name, const CompilerDeclContext &parent_decl_ctx,
1652 uint32_t max_matches, VariableList &variables) {
1653 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1654 using SymbolAndOffset = std::pair<uint32_t, llvm::codeview::CVSymbol>;
1655
1656 std::vector<SymbolAndOffset> results = m_index->globals().findRecordsByName(
1657 name.GetStringRef(), m_index->symrecords());
1658 for (const SymbolAndOffset &result : results) {
1659 switch (result.second.kind()) {
1660 case SymbolKind::S_GDATA32:
1661 case SymbolKind::S_LDATA32:
1662 case SymbolKind::S_GTHREAD32:
1663 case SymbolKind::S_LTHREAD32:
1664 case SymbolKind::S_CONSTANT: {
1665 PdbGlobalSymId global(result.first, false);
1666 if (VariableSP var = GetOrCreateGlobalVariable(global))
1667 variables.AddVariable(var);
1668 break;
1669 }
1670 default:
1671 continue;
1672 }
1673 }
1674}
1675
1677 const Module::LookupInfo &lookup_info,
1678 const CompilerDeclContext &parent_decl_ctx, bool include_inlines,
1679 SymbolContextList &sc_list) {
1680 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1681 ConstString name = lookup_info.GetLookupName();
1682 FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();
1683 if (name_type_mask & eFunctionNameTypeFull)
1684 name = lookup_info.GetName();
1685
1686 // For now we only support lookup by method name or full name.
1687 if (!(name_type_mask & eFunctionNameTypeFull ||
1688 name_type_mask & eFunctionNameTypeMethod))
1689 return;
1690
1691 using SymbolAndOffset = std::pair<uint32_t, llvm::codeview::CVSymbol>;
1692
1693 std::vector<SymbolAndOffset> matches = m_index->globals().findRecordsByName(
1694 name.GetStringRef(), m_index->symrecords());
1695 for (const SymbolAndOffset &match : matches) {
1696 if (match.second.kind() != S_PROCREF && match.second.kind() != S_LPROCREF)
1697 continue;
1698 ProcRefSym proc(match.second.kind());
1699 cantFail(SymbolDeserializer::deserializeAs<ProcRefSym>(match.second, proc));
1700
1701 if (!IsValidRecord(proc))
1702 continue;
1703
1704 CompilandIndexItem &cci =
1705 m_index->compilands().GetOrCreateCompiland(proc.modi());
1706 SymbolContext sc;
1707
1708 sc.comp_unit = GetOrCreateCompileUnit(cci).get();
1709 PdbCompilandSymId func_id(proc.modi(), proc.SymOffset);
1710 sc.function = GetOrCreateFunction(func_id, *sc.comp_unit).get();
1711
1712 sc_list.Append(sc);
1713 }
1714}
1715
1717 bool include_inlines,
1718 SymbolContextList &sc_list) {}
1719
1721 ConstString name, const CompilerDeclContext &parent_decl_ctx,
1722 uint32_t max_matches, llvm::DenseSet<SymbolFile *> &searched_symbol_files,
1723 TypeMap &types) {
1724 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1725 if (!name)
1726 return;
1727
1728 searched_symbol_files.clear();
1729 searched_symbol_files.insert(this);
1730
1731 // There is an assumption 'name' is not a regex
1732 FindTypesByName(name.GetStringRef(), max_matches, types);
1733}
1734
1736 llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
1737 llvm::DenseSet<SymbolFile *> &searched_symbol_files, TypeMap &types) {}
1738
1740 uint32_t max_matches,
1741 TypeMap &types) {
1742
1743 std::vector<TypeIndex> matches = m_index->tpi().findRecordsByName(name);
1744 if (max_matches > 0 && max_matches < matches.size())
1745 matches.resize(max_matches);
1746
1747 for (TypeIndex ti : matches) {
1748 TypeSP type = GetOrCreateType(ti);
1749 if (!type)
1750 continue;
1751
1752 types.Insert(type);
1753 }
1754}
1755
1757 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1758 // Only do the full type scan the first time.
1760 return 0;
1761
1762 const size_t old_count = GetTypeList().GetSize();
1763 LazyRandomTypeCollection &types = m_index->tpi().typeCollection();
1764
1765 // First process the entire TPI stream.
1766 for (auto ti = types.getFirst(); ti; ti = types.getNext(*ti)) {
1767 TypeSP type = GetOrCreateType(*ti);
1768 if (type)
1769 (void)type->GetFullCompilerType();
1770 }
1771
1772 // Next look for S_UDT records in the globals stream.
1773 for (const uint32_t gid : m_index->globals().getGlobalsTable()) {
1774 PdbGlobalSymId global{gid, false};
1775 CVSymbol sym = m_index->ReadSymbolRecord(global);
1776 if (sym.kind() != S_UDT)
1777 continue;
1778
1779 UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs<UDTSym>(sym));
1780 bool is_typedef = true;
1781 if (IsTagRecord(PdbTypeSymId{udt.Type, false}, m_index->tpi())) {
1782 CVType cvt = m_index->tpi().getType(udt.Type);
1783 llvm::StringRef name = CVTagRecord::create(cvt).name();
1784 if (name == udt.Name)
1785 is_typedef = false;
1786 }
1787
1788 if (is_typedef)
1789 GetOrCreateTypedef(global);
1790 }
1791
1792 const size_t new_count = GetTypeList().GetSize();
1793
1794 m_done_full_type_scan = true;
1795
1796 return new_count - old_count;
1797}
1798
1799size_t
1801 VariableList &variables) {
1802 PdbSymUid sym_uid(comp_unit.GetID());
1804 return 0;
1805}
1806
1808 PdbCompilandSymId var_id,
1809 bool is_param) {
1810 ModuleSP module = GetObjectFile()->GetModule();
1811 Block &block = GetOrCreateBlock(scope_id);
1812 // Get function block.
1813 Block *func_block = &block;
1814 while (func_block->GetParent()) {
1815 func_block = func_block->GetParent();
1816 }
1817 Address addr;
1818 func_block->GetStartAddress(addr);
1819 VariableInfo var_info =
1820 GetVariableLocationInfo(*m_index, var_id, *func_block, module);
1821 Function *func = func_block->CalculateSymbolContextFunction();
1822 if (!func)
1823 return nullptr;
1824 // Use empty dwarf expr if optimized away so that it won't be filtered out
1825 // when lookuping local variables in this scope.
1826 if (!var_info.location.IsValid())
1827 var_info.location = DWARFExpressionList(module, DWARFExpression(), nullptr);
1830 CompilandIndexItem *cii = m_index->compilands().GetCompiland(var_id.modi);
1831 CompUnitSP comp_unit_sp = GetOrCreateCompileUnit(*cii);
1832 TypeSP type_sp = GetOrCreateType(var_info.type);
1833 if (!type_sp)
1834 return nullptr;
1835 std::string name = var_info.name.str();
1836 Declaration decl;
1837 SymbolFileTypeSP sftype =
1838 std::make_shared<SymbolFileType>(*this, type_sp->GetID());
1839
1840 is_param |= var_info.is_param;
1841 ValueType var_scope =
1843 bool external = false;
1844 bool artificial = false;
1845 bool location_is_constant_data = false;
1846 bool static_member = false;
1847 Variable::RangeList scope_ranges;
1848 VariableSP var_sp = std::make_shared<Variable>(
1849 toOpaqueUid(var_id), name.c_str(), name.c_str(), sftype, var_scope,
1850 &block, scope_ranges, &decl, var_info.location, external, artificial,
1851 location_is_constant_data, static_member);
1852 if (!is_param) {
1853 auto ts_or_err = GetTypeSystemForLanguage(comp_unit_sp->GetLanguage());
1854 if (auto err = ts_or_err.takeError())
1855 return nullptr;
1856 auto ts = *ts_or_err;
1857 if (!ts)
1858 return nullptr;
1859
1860 ts->GetNativePDBParser()->GetOrCreateVariableDecl(scope_id, var_id);
1861 }
1862 m_local_variables[toOpaqueUid(var_id)] = var_sp;
1863 return var_sp;
1864}
1865
1867 PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param) {
1868 auto iter = m_local_variables.find(toOpaqueUid(var_id));
1869 if (iter != m_local_variables.end())
1870 return iter->second;
1871
1872 return CreateLocalVariable(scope_id, var_id, is_param);
1873}
1874
1876 CVSymbol sym = m_index->ReadSymbolRecord(id);
1877 lldbassert(sym.kind() == SymbolKind::S_UDT);
1878
1879 UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs<UDTSym>(sym));
1880
1881 TypeSP target_type = GetOrCreateType(udt.Type);
1882
1884 if (auto err = ts_or_err.takeError())
1885 return nullptr;
1886 auto ts = *ts_or_err;
1887 if (!ts)
1888 return nullptr;
1889
1890 ts->GetNativePDBParser()->GetOrCreateTypedefDecl(id);
1891
1892 Declaration decl;
1893 return MakeType(
1894 toOpaqueUid(id), ConstString(udt.Name), target_type->GetByteSize(nullptr),
1895 nullptr, target_type->GetID(), lldb_private::Type::eEncodingIsTypedefUID,
1896 decl, target_type->GetForwardCompilerType(),
1898}
1899
1901 auto iter = m_types.find(toOpaqueUid(id));
1902 if (iter != m_types.end())
1903 return iter->second;
1904
1905 return CreateTypedef(id);
1906}
1907
1909 Block &block = GetOrCreateBlock(block_id);
1910
1911 size_t count = 0;
1912
1913 CompilandIndexItem *cii = m_index->compilands().GetCompiland(block_id.modi);
1914 CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(block_id.offset);
1915 uint32_t params_remaining = 0;
1916 switch (sym.kind()) {
1917 case S_GPROC32:
1918 case S_LPROC32: {
1919 ProcSym proc(static_cast<SymbolRecordKind>(sym.kind()));
1920 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym, proc));
1921 CVType signature = m_index->tpi().getType(proc.FunctionType);
1922 if (signature.kind() == LF_PROCEDURE) {
1923 ProcedureRecord sig;
1924 if (llvm::Error e = TypeDeserializer::deserializeAs<ProcedureRecord>(
1925 signature, sig)) {
1926 llvm::consumeError(std::move(e));
1927 return 0;
1928 }
1929 params_remaining = sig.getParameterCount();
1930 } else if (signature.kind() == LF_MFUNCTION) {
1931 MemberFunctionRecord sig;
1932 if (llvm::Error e = TypeDeserializer::deserializeAs<MemberFunctionRecord>(
1933 signature, sig)) {
1934 llvm::consumeError(std::move(e));
1935 return 0;
1936 }
1937 params_remaining = sig.getParameterCount();
1938 } else
1939 return 0;
1940 break;
1941 }
1942 case S_BLOCK32:
1943 break;
1944 case S_INLINESITE:
1945 break;
1946 default:
1947 lldbassert(false && "Symbol is not a block!");
1948 return 0;
1949 }
1950
1951 VariableListSP variables = block.GetBlockVariableList(false);
1952 if (!variables) {
1953 variables = std::make_shared<VariableList>();
1954 block.SetVariableList(variables);
1955 }
1956
1957 CVSymbolArray syms = limitSymbolArrayToScope(
1958 cii->m_debug_stream.getSymbolArray(), block_id.offset);
1959
1960 // Skip the first record since it's a PROC32 or BLOCK32, and there's
1961 // no point examining it since we know it's not a local variable.
1962 syms.drop_front();
1963 auto iter = syms.begin();
1964 auto end = syms.end();
1965
1966 while (iter != end) {
1967 uint32_t record_offset = iter.offset();
1968 CVSymbol variable_cvs = *iter;
1969 PdbCompilandSymId child_sym_id(block_id.modi, record_offset);
1970 ++iter;
1971
1972 // If this is a block or inline site, recurse into its children and then
1973 // skip it.
1974 if (variable_cvs.kind() == S_BLOCK32 ||
1975 variable_cvs.kind() == S_INLINESITE) {
1976 uint32_t block_end = getScopeEndOffset(variable_cvs);
1977 count += ParseVariablesForBlock(child_sym_id);
1978 iter = syms.at(block_end);
1979 continue;
1980 }
1981
1982 bool is_param = params_remaining > 0;
1983 VariableSP variable;
1984 switch (variable_cvs.kind()) {
1985 case S_REGREL32:
1986 case S_REGISTER:
1987 case S_LOCAL:
1988 variable = GetOrCreateLocalVariable(block_id, child_sym_id, is_param);
1989 if (is_param)
1990 --params_remaining;
1991 if (variable)
1992 variables->AddVariableIfUnique(variable);
1993 break;
1994 default:
1995 break;
1996 }
1997 }
1998
1999 // Pass false for set_children, since we call this recursively so that the
2000 // children will call this for themselves.
2001 block.SetDidParseVariables(true, false);
2002
2003 return count;
2004}
2005
2007 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2008 lldbassert(sc.function || sc.comp_unit);
2009
2010 VariableListSP variables;
2011 if (sc.block) {
2012 PdbSymUid block_id(sc.block->GetID());
2013
2014 size_t count = ParseVariablesForBlock(block_id.asCompilandSym());
2015 return count;
2016 }
2017
2018 if (sc.function) {
2019 PdbSymUid block_id(sc.function->GetID());
2020
2021 size_t count = ParseVariablesForBlock(block_id.asCompilandSym());
2022 return count;
2023 }
2024
2025 if (sc.comp_unit) {
2026 variables = sc.comp_unit->GetVariableList(false);
2027 if (!variables) {
2028 variables = std::make_shared<VariableList>();
2029 sc.comp_unit->SetVariableList(variables);
2030 }
2031 return ParseVariablesForCompileUnit(*sc.comp_unit, *variables);
2032 }
2033
2034 llvm_unreachable("Unreachable!");
2035}
2036
2039 if (auto err = ts_or_err.takeError())
2040 return CompilerDecl();
2041 auto ts = *ts_or_err;
2042 if (!ts)
2043 return {};
2044
2045 if (auto decl = ts->GetNativePDBParser()->GetOrCreateDeclForUid(uid))
2046 return *decl;
2047 return CompilerDecl();
2048}
2049
2053 if (auto err = ts_or_err.takeError())
2054 return {};
2055 auto ts = *ts_or_err;
2056 if (!ts)
2057 return {};
2058
2059 PdbAstBuilder *ast_builder = ts->GetNativePDBParser();
2060 clang::DeclContext *context =
2061 ast_builder->GetOrCreateDeclContextForUid(PdbSymUid(uid));
2062 if (!context)
2063 return {};
2064
2065 return ast_builder->ToCompilerDeclContext(*context);
2066}
2067
2071 if (auto err = ts_or_err.takeError())
2072 return CompilerDeclContext();
2073 auto ts = *ts_or_err;
2074 if (!ts)
2075 return {};
2076
2077 PdbAstBuilder *ast_builder = ts->GetNativePDBParser();
2078 clang::DeclContext *context = ast_builder->GetParentDeclContext(PdbSymUid(uid));
2079 if (!context)
2080 return CompilerDeclContext();
2081 return ast_builder->ToCompilerDeclContext(*context);
2082}
2083
2085 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2086 auto iter = m_types.find(type_uid);
2087 // lldb should not be passing us non-sensical type uids. the only way it
2088 // could have a type uid in the first place is if we handed it out, in which
2089 // case we should know about the type. However, that doesn't mean we've
2090 // instantiated it yet. We can vend out a UID for a future type. So if the
2091 // type doesn't exist, let's instantiate it now.
2092 if (iter != m_types.end())
2093 return &*iter->second;
2094
2095 PdbSymUid uid(type_uid);
2097 PdbTypeSymId type_id = uid.asTypeSym();
2098 if (type_id.index.isNoneType())
2099 return nullptr;
2100
2101 TypeSP type_sp = CreateAndCacheType(type_id);
2102 if (!type_sp)
2103 return nullptr;
2104 return &*type_sp;
2105}
2106
2107std::optional<SymbolFile::ArrayInfo>
2109 lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) {
2110 return std::nullopt;
2111}
2112
2114 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2115 auto ts = compiler_type.GetTypeSystem();
2116 auto clang_type_system = ts.dyn_cast_or_null<TypeSystemClang>();
2117 if (!clang_type_system)
2118 return false;
2119
2120 PdbAstBuilder *ast_builder =
2121 static_cast<PdbAstBuilder *>(clang_type_system->GetNativePDBParser());
2122 if (ast_builder &&
2123 ast_builder->GetClangASTImporter().CanImport(compiler_type))
2124 return ast_builder->GetClangASTImporter().CompleteType(compiler_type);
2125 clang::QualType qt =
2126 clang::QualType::getFromOpaquePtr(compiler_type.GetOpaqueQualType());
2127
2128 return ast_builder->CompleteType(qt);
2129}
2130
2132 TypeClass type_mask,
2133 lldb_private::TypeList &type_list) {}
2134
2136 ConstString name, const CompilerDeclContext &parent_decl_ctx, bool) {
2137 return {};
2138}
2139
2140llvm::Expected<lldb::TypeSystemSP>
2142 auto type_system_or_err =
2143 m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
2144 if (type_system_or_err)
2145 if (auto ts = *type_system_or_err)
2146 ts->SetSymbolFile(this);
2147 return type_system_or_err;
2148}
2149
2151 // PDB files are a separate file that contains all debug info.
2152 return m_index->pdb().getFileSize();
2153}
2154
2156 LazyRandomTypeCollection &types = m_index->tpi().typeCollection();
2157
2158 llvm::DenseMap<TypeIndex, TypeIndex> forward_to_full;
2159 llvm::DenseMap<TypeIndex, TypeIndex> full_to_forward;
2160
2161 struct RecordIndices {
2162 TypeIndex forward;
2163 TypeIndex full;
2164 };
2165
2166 llvm::StringMap<RecordIndices> record_indices;
2167
2168 for (auto ti = types.getFirst(); ti; ti = types.getNext(*ti)) {
2169 CVType type = types.getType(*ti);
2170 if (!IsTagRecord(type))
2171 continue;
2172
2173 CVTagRecord tag = CVTagRecord::create(type);
2174
2175 RecordIndices &indices = record_indices[tag.asTag().getUniqueName()];
2176 if (tag.asTag().isForwardRef())
2177 indices.forward = *ti;
2178 else
2179 indices.full = *ti;
2180
2181 if (indices.full != TypeIndex::None() &&
2182 indices.forward != TypeIndex::None()) {
2183 forward_to_full[indices.forward] = indices.full;
2184 full_to_forward[indices.full] = indices.forward;
2185 }
2186
2187 // We're looking for LF_NESTTYPE records in the field list, so ignore
2188 // forward references (no field list), and anything without a nested class
2189 // (since there won't be any LF_NESTTYPE records).
2190 if (tag.asTag().isForwardRef() || !tag.asTag().containsNestedClass())
2191 continue;
2192
2193 struct ProcessTpiStream : public TypeVisitorCallbacks {
2194 ProcessTpiStream(PdbIndex &index, TypeIndex parent,
2195 const CVTagRecord &parent_cvt,
2196 llvm::DenseMap<TypeIndex, TypeIndex> &parents)
2197 : index(index), parents(parents), parent(parent),
2198 parent_cvt(parent_cvt) {}
2199
2200 PdbIndex &index;
2201 llvm::DenseMap<TypeIndex, TypeIndex> &parents;
2202
2203 unsigned unnamed_type_index = 1;
2204 TypeIndex parent;
2205 const CVTagRecord &parent_cvt;
2206
2207 llvm::Error visitKnownMember(CVMemberRecord &CVR,
2208 NestedTypeRecord &Record) override {
2209 std::string unnamed_type_name;
2210 if (Record.Name.empty()) {
2211 unnamed_type_name =
2212 llvm::formatv("<unnamed-type-$S{0}>", unnamed_type_index).str();
2213 Record.Name = unnamed_type_name;
2214 ++unnamed_type_index;
2215 }
2216 std::optional<CVTagRecord> tag =
2217 GetNestedTagDefinition(Record, parent_cvt, index.tpi());
2218 if (!tag)
2219 return llvm::ErrorSuccess();
2220
2221 parents[Record.Type] = parent;
2222 return llvm::ErrorSuccess();
2223 }
2224 };
2225
2226 CVType field_list_cvt = m_index->tpi().getType(tag.asTag().FieldList);
2227 ProcessTpiStream process(*m_index, *ti, tag, m_parent_types);
2228 FieldListRecord field_list;
2229 if (llvm::Error error = TypeDeserializer::deserializeAs<FieldListRecord>(
2230 field_list_cvt, field_list))
2231 llvm::consumeError(std::move(error));
2232 if (llvm::Error error = visitMemberRecordStream(field_list.Data, process))
2233 llvm::consumeError(std::move(error));
2234 }
2235
2236 // Now that we know the forward -> full mapping of all type indices, we can
2237 // re-write all the indices. At the end of this process, we want a mapping
2238 // consisting of fwd -> full and full -> full for all child -> parent indices.
2239 // We can re-write the values in place, but for the keys, we must save them
2240 // off so that we don't modify the map in place while also iterating it.
2241 std::vector<TypeIndex> full_keys;
2242 std::vector<TypeIndex> fwd_keys;
2243 for (auto &entry : m_parent_types) {
2244 TypeIndex key = entry.first;
2245 TypeIndex value = entry.second;
2246
2247 auto iter = forward_to_full.find(value);
2248 if (iter != forward_to_full.end())
2249 entry.second = iter->second;
2250
2251 iter = forward_to_full.find(key);
2252 if (iter != forward_to_full.end())
2253 fwd_keys.push_back(key);
2254 else
2255 full_keys.push_back(key);
2256 }
2257 for (TypeIndex fwd : fwd_keys) {
2258 TypeIndex full = forward_to_full[fwd];
2259 m_parent_types[full] = m_parent_types[fwd];
2260 }
2261 for (TypeIndex full : full_keys) {
2262 TypeIndex fwd = full_to_forward[full];
2263 m_parent_types[fwd] = m_parent_types[full];
2264 }
2265}
2266
2267std::optional<PdbCompilandSymId>
2269 CVSymbol sym = m_index->ReadSymbolRecord(id);
2270 if (symbolOpensScope(sym.kind())) {
2271 // If this exact symbol opens a scope, we can just directly access its
2272 // parent.
2273 id.offset = getScopeParentOffset(sym);
2274 // Global symbols have parent offset of 0. Return std::nullopt to indicate
2275 // this.
2276 if (id.offset == 0)
2277 return std::nullopt;
2278 return id;
2279 }
2280
2281 // Otherwise we need to start at the beginning and iterate forward until we
2282 // reach (or pass) this particular symbol
2283 CompilandIndexItem &cii = m_index->compilands().GetOrCreateCompiland(id.modi);
2284 const CVSymbolArray &syms = cii.m_debug_stream.getSymbolArray();
2285
2286 auto begin = syms.begin();
2287 auto end = syms.at(id.offset);
2288 std::vector<PdbCompilandSymId> scope_stack;
2289
2290 while (begin != end) {
2291 if (begin.offset() > id.offset) {
2292 // We passed it. We couldn't even find this symbol record.
2293 lldbassert(false && "Invalid compiland symbol id!");
2294 return std::nullopt;
2295 }
2296
2297 // We haven't found the symbol yet. Check if we need to open or close the
2298 // scope stack.
2299 if (symbolOpensScope(begin->kind())) {
2300 // We can use the end offset of the scope to determine whether or not
2301 // we can just outright skip this entire scope.
2302 uint32_t scope_end = getScopeEndOffset(*begin);
2303 if (scope_end < id.offset) {
2304 begin = syms.at(scope_end);
2305 } else {
2306 // The symbol we're looking for is somewhere in this scope.
2307 scope_stack.emplace_back(id.modi, begin.offset());
2308 }
2309 } else if (symbolEndsScope(begin->kind())) {
2310 scope_stack.pop_back();
2311 }
2312 ++begin;
2313 }
2314 if (scope_stack.empty())
2315 return std::nullopt;
2316 // We have a match! Return the top of the stack
2317 return scope_stack.back();
2318}
2319
2320std::optional<llvm::codeview::TypeIndex>
2321SymbolFileNativePDB::GetParentType(llvm::codeview::TypeIndex ti) {
2322 auto parent_iter = m_parent_types.find(ti);
2323 if (parent_iter == m_parent_types.end())
2324 return std::nullopt;
2325 return parent_iter->second;
2326}
static llvm::raw_ostream & error(Stream &strm)
#define lldbassert(x)
Definition: LLDBAssert.h:15
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:365
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:209
A section + offset based address class.
Definition: Address.h:59
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:291
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:345
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:399
Block * FindInnermostBlockByOffset(const lldb::addr_t offset)
Definition: Block.cpp:126
Function * CalculateSymbolContextFunction() override
Definition: Block.cpp:154
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
Definition: Block.h:331
Block * GetParent() const
Get the parent block.
Definition: Block.cpp:202
size_t GetNumRanges() const
Definition: Block.h:343
bool GetStartAddress(Address &addr)
Definition: Block.cpp:317
void SetDidParseVariables(bool b, bool set_children)
Definition: Block.cpp:496
void AddRange(const Range &range)
Add a new offset range to this block.
Definition: Block.cpp:335
void AddChild(const lldb::BlockSP &child_block_sp)
Add a child to this object.
Definition: Block.cpp:385
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:41
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 file associated with this compile unit.
Definition: CompileUnit.h:227
void ResolveSymbolContext(const SourceLocationSpec &src_location_spec, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list)
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:397
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:227
A uniqued constant string class.
Definition: ConstString.h:40
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:191
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:205
"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:79
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 collection class.
Definition: FileSpecList.h:24
const FileSpec & GetFileSpecAtIndex(size_t idx) const
Get file at index.
void Append(const FileSpec &file)
Append a FileSpec object to the list.
A file utility class.
Definition: FileSpec.h:57
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
Definition: FileSpec.cpp:304
const ConstString & GetFilename() const
Filename string const get accessor.
Definition: FileSpec.h:245
FileSpec CopyByRemovingLastPathComponent() const
Definition: FileSpec.cpp:427
llvm::sys::path::Style Style
Definition: FileSpec.h:59
static FileSystem & Instance()
A class that describes a function.
Definition: Function.h:399
const AddressRange & GetAddressRange()
Definition: Function.h:447
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition: Function.cpp:370
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:949
lldb::FunctionNameType GetNameTypeMask() const
Definition: Module.h:964
ConstString GetLookupName() const
Definition: Module.h:960
ConstString GetName() const
Definition: Module.h:956
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:563
"lldb/Core/SourceLocationSpec.h" A source location specifier class.
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
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:33
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:489
lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) override
Definition: SymbolFile.cpp:203
ObjectFile * GetObjectFile() override
Definition: SymbolFile.h:518
virtual TypeList & GetTypeList()
Definition: SymbolFile.h:591
lldb::ObjectFileSP m_objfile_sp
Definition: SymbolFile.h:594
void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp)
Definition: SymbolFile.cpp:214
uint32_t GetNumCompileUnits() override
Definition: SymbolFile.cpp:193
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:562
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 TypeSystem implementation based on Clang.
Interface for representing a type system.
Definition: TypeSystem.h:83
virtual npdb::PdbAstBuilder * GetNativePDBParser()
Definition: TypeSystem.h:105
@ eEncodingIsTypedefUID
This type is alias to a type whose UID is m_encoding_uid.
Definition: Type.h:85
@ eEncodingIsUID
This type is the type whose UID is m_encoding_uid.
Definition: Type.h:74
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)
Block & CreateBlock(PdbCompilandSymId block_id)
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
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)
void FindTypes(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, llvm::DenseSet< SymbolFile * > &searched_symbol_files, TypeMap &types) override
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)
size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override
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
bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, FileSpecList &support_files) override
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)
Block & GetOrCreateBlock(PdbCompilandSymId block_id)
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)
uint64_t GetDebugInfoSize() override
Metrics gathering functions.
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.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:314
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Function > FunctionSP
Definition: lldb-forward.h:343
std::shared_ptr< lldb_private::Block > BlockSP
Definition: lldb-forward.h:308
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
Definition: lldb-forward.h:363
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:445
std::shared_ptr< lldb_private::VariableList > VariableListSP
Definition: lldb-forward.h:470
std::shared_ptr< lldb_private::SymbolFileType > SymbolFileTypeSP
Definition: lldb-forward.h:425
std::shared_ptr< lldb_private::Variable > VariableSP
Definition: lldb-forward.h:469
uint64_t user_id_t
Definition: lldb-types.h:80
uint64_t addr_t
Definition: lldb-types.h:79
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:361
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
Definition: lldb-forward.h:323
@ eValueTypeInvalid
@ eValueTypeVariableGlobal
globals variable
@ eValueTypeVariableLocal
function local variables
@ eValueTypeVariableArgument
function argument variables
@ eValueTypeVariableStatic
static variable
@ eValueTypeVariableThreadLocal
thread local storage variable
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
Definition: TypeSystem.h:51
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