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
16#include "lldb/Core/Module.h"
26#include "lldb/Utility/Log.h"
27
28#include "llvm/DebugInfo/CodeView/CVRecord.h"
29#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
30#include "llvm/DebugInfo/CodeView/DebugLinesSubsection.h"
31#include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h"
32#include "llvm/DebugInfo/CodeView/RecordName.h"
33#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
34#include "llvm/DebugInfo/CodeView/SymbolRecordHelpers.h"
35#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
36#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
37#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
38#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
39#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h"
40#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
41#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
42#include "llvm/DebugInfo/PDB/Native/PublicsStream.h"
43#include "llvm/DebugInfo/PDB/Native/SymbolStream.h"
44#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
45#include "llvm/DebugInfo/PDB/PDB.h"
46#include "llvm/DebugInfo/PDB/PDBTypes.h"
47#include "llvm/Demangle/MicrosoftDemangle.h"
48#include "llvm/Object/COFF.h"
49#include "llvm/Support/Allocator.h"
50#include "llvm/Support/BinaryStreamReader.h"
51#include "llvm/Support/Error.h"
52#include "llvm/Support/ErrorOr.h"
53#include "llvm/Support/MemoryBuffer.h"
54
56#include "PdbSymUid.h"
57#include "PdbUtil.h"
58#include "UdtRecordCompleter.h"
59#include <optional>
60#include <string_view>
61
62using namespace lldb;
63using namespace lldb_private;
64using namespace npdb;
65using namespace llvm::codeview;
66using namespace llvm::pdb;
67
69
71 switch (lang) {
72 case PDB_Lang::Cpp:
74 case PDB_Lang::C:
76 case PDB_Lang::Swift:
78 case PDB_Lang::Rust:
80 case PDB_Lang::ObjC:
82 case PDB_Lang::ObjCpp:
84 default:
86 }
87}
88
89static std::unique_ptr<PDBFile>
90loadMatchingPDBFile(std::string exe_path, llvm::BumpPtrAllocator &allocator) {
91 // Try to find a matching PDB for an EXE.
92 using namespace llvm::object;
93 auto expected_binary = createBinary(exe_path);
94
95 // If the file isn't a PE/COFF executable, fail.
96 if (!expected_binary) {
97 llvm::consumeError(expected_binary.takeError());
98 return nullptr;
99 }
100 OwningBinary<Binary> binary = std::move(*expected_binary);
101
102 // TODO: Avoid opening the PE/COFF binary twice by reading this information
103 // directly from the lldb_private::ObjectFile.
104 auto *obj = llvm::dyn_cast<llvm::object::COFFObjectFile>(binary.getBinary());
105 if (!obj)
106 return nullptr;
107 const llvm::codeview::DebugInfo *pdb_info = nullptr;
108
109 // If it doesn't have a debug directory, fail.
110 llvm::StringRef pdb_file;
111 if (llvm::Error e = obj->getDebugPDBInfo(pdb_info, pdb_file)) {
112 consumeError(std::move(e));
113 return nullptr;
114 }
115
116 // If the file doesn't exist, perhaps the path specified at build time
117 // doesn't match the PDB's current location, so check the location of the
118 // executable.
119 if (!FileSystem::Instance().Exists(pdb_file)) {
120 const auto exe_dir = FileSpec(exe_path).CopyByRemovingLastPathComponent();
121 const auto pdb_name = FileSpec(pdb_file).GetFilename().GetCString();
122 pdb_file = exe_dir.CopyByAppendingPathComponent(pdb_name).GetPathAsConstString().GetStringRef();
123 }
124
125 // If the file is not a PDB or if it doesn't have a matching GUID, fail.
126 auto pdb = ObjectFilePDB::loadPDBFile(std::string(pdb_file), allocator);
127 if (!pdb)
128 return nullptr;
129
130 auto expected_info = pdb->getPDBInfoStream();
131 if (!expected_info) {
132 llvm::consumeError(expected_info.takeError());
133 return nullptr;
134 }
135 llvm::codeview::GUID guid;
136 memcpy(&guid, pdb_info->PDB70.Signature, 16);
137
138 if (expected_info->getGuid() != guid)
139 return nullptr;
140 return pdb;
141}
142
144 lldb::addr_t addr) {
145 // FIXME: Implement this.
146 return false;
147}
148
150 lldb::addr_t addr) {
151 // FIXME: Implement this.
152 return false;
153}
154
155// See llvm::codeview::TypeIndex::simpleTypeName as well as strForPrimitiveTi
156// from the original pdbdump:
157// https://github.com/microsoft/microsoft-pdb/blob/805655a28bd8198004be2ac27e6e0290121a5e89/pdbdump/pdbdump.cpp#L1896-L1974
158//
159// For 64bit integers we use "long long" like DIA instead of "__int64".
160static llvm::StringRef GetSimpleTypeName(SimpleTypeKind kind) {
161 switch (kind) {
162 case SimpleTypeKind::Boolean128:
163 return "__bool128";
164 case SimpleTypeKind::Boolean64:
165 return "__bool64";
166 case SimpleTypeKind::Boolean32:
167 return "__bool32";
168 case SimpleTypeKind::Boolean16:
169 return "__bool16";
170 case SimpleTypeKind::Boolean8:
171 return "bool";
172
173 case SimpleTypeKind::Byte:
174 case SimpleTypeKind::UnsignedCharacter:
175 return "unsigned char";
176 case SimpleTypeKind::NarrowCharacter:
177 return "char";
178 case SimpleTypeKind::SignedCharacter:
179 case SimpleTypeKind::SByte:
180 return "signed char";
181 case SimpleTypeKind::Character32:
182 return "char32_t";
183 case SimpleTypeKind::Character16:
184 return "char16_t";
185 case SimpleTypeKind::Character8:
186 return "char8_t";
187
188 case SimpleTypeKind::Complex128:
189 return "_Complex __float128";
190 case SimpleTypeKind::Complex80:
191 return "_Complex long double";
192 case SimpleTypeKind::Complex64:
193 return "_Complex double";
194 case SimpleTypeKind::Complex48:
195 return "_Complex __float48";
196 case SimpleTypeKind::Complex32:
197 case SimpleTypeKind::Complex32PartialPrecision:
198 return "_Complex float";
199 case SimpleTypeKind::Complex16:
200 return "_Complex _Float16";
201
202 case SimpleTypeKind::Float128:
203 return "__float128";
204 case SimpleTypeKind::Float80:
205 return "long double";
206 case SimpleTypeKind::Float64:
207 return "double";
208 case SimpleTypeKind::Float48:
209 return "__float48";
210 case SimpleTypeKind::Float32:
211 case SimpleTypeKind::Float32PartialPrecision:
212 return "float";
213 case SimpleTypeKind::Float16:
214 return "_Float16";
215
216 case SimpleTypeKind::Int128Oct:
217 case SimpleTypeKind::Int128:
218 return "__int128";
219 case SimpleTypeKind::Int64:
220 case SimpleTypeKind::Int64Quad:
221 return "long long";
222 case SimpleTypeKind::Int32Long:
223 return "long";
224 case SimpleTypeKind::Int32:
225 return "int";
226 case SimpleTypeKind::Int16:
227 case SimpleTypeKind::Int16Short:
228 return "short";
229
230 case SimpleTypeKind::UInt128Oct:
231 case SimpleTypeKind::UInt128:
232 return "unsigned __int128";
233 case SimpleTypeKind::UInt64:
234 case SimpleTypeKind::UInt64Quad:
235 return "unsigned long long";
236 case SimpleTypeKind::UInt32:
237 return "unsigned";
238 case SimpleTypeKind::UInt16:
239 case SimpleTypeKind::UInt16Short:
240 return "unsigned short";
241 case SimpleTypeKind::UInt32Long:
242 return "unsigned long";
243
244 case SimpleTypeKind::HResult:
245 return "HRESULT";
246 case SimpleTypeKind::Void:
247 return "void";
248 case SimpleTypeKind::WideCharacter:
249 return "wchar_t";
250
251 case SimpleTypeKind::None:
252 case SimpleTypeKind::NotTranslated:
253 return "";
254 }
255 return "";
256}
257
258static bool IsClassRecord(TypeLeafKind kind) {
259 switch (kind) {
260 case LF_STRUCTURE:
261 case LF_CLASS:
262 case LF_INTERFACE:
263 return true;
264 default:
265 return false;
266 }
267}
268
269static std::optional<CVTagRecord>
270GetNestedTagDefinition(const NestedTypeRecord &Record,
271 const CVTagRecord &parent, TpiStream &tpi) {
272 // An LF_NESTTYPE is essentially a nested typedef / using declaration, but it
273 // is also used to indicate the primary definition of a nested class. That is
274 // to say, if you have:
275 // struct A {
276 // struct B {};
277 // using C = B;
278 // };
279 // Then in the debug info, this will appear as:
280 // LF_STRUCTURE `A::B` [type index = N]
281 // LF_STRUCTURE `A`
282 // LF_NESTTYPE [name = `B`, index = N]
283 // LF_NESTTYPE [name = `C`, index = N]
284 // In order to accurately reconstruct the decl context hierarchy, we need to
285 // know which ones are actual definitions and which ones are just aliases.
286
287 // If it's a simple type, then this is something like `using foo = int`.
288 if (Record.Type.isSimple())
289 return std::nullopt;
290
291 CVType cvt = tpi.getType(Record.Type);
292
293 if (!IsTagRecord(cvt))
294 return std::nullopt;
295
296 // If it's an inner definition, then treat whatever name we have here as a
297 // single component of a mangled name. So we can inject it into the parent's
298 // mangled name to see if it matches.
299 CVTagRecord child = CVTagRecord::create(cvt);
300 std::string qname = std::string(parent.asTag().getUniqueName());
301 if (qname.size() < 4 || child.asTag().getUniqueName().size() < 4)
302 return std::nullopt;
303
304 // qname[3] is the tag type identifier (struct, class, union, etc). Since the
305 // inner tag type is not necessarily the same as the outer tag type, re-write
306 // it to match the inner tag type.
307 qname[3] = child.asTag().getUniqueName()[3];
308 std::string piece;
309 if (qname[3] == 'W')
310 piece = "4";
311 piece += Record.Name;
312 piece.push_back('@');
313 qname.insert(4, std::move(piece));
314 if (qname != child.asTag().UniqueName)
315 return std::nullopt;
316
317 return std::move(child);
318}
319
325
329
331
333 return "Microsoft PDB debug symbol cross-platform file reader.";
334}
335
338 return nullptr;
339
340 return new SymbolFileNativePDB(std::move(objfile_sp));
341}
342
345
347
349 uint32_t abilities = 0;
350 if (!m_objfile_sp)
351 return 0;
352
353 if (!m_index) {
354 // Lazily load and match the PDB file, but only do this once.
355 PDBFile *pdb_file;
356 if (auto *pdb = llvm::dyn_cast<ObjectFilePDB>(m_objfile_sp.get())) {
357 pdb_file = &pdb->GetPDBFile();
358 } else {
359 m_file_up = loadMatchingPDBFile(m_objfile_sp->GetFileSpec().GetPath(),
361 pdb_file = m_file_up.get();
362 }
363
364 if (!pdb_file)
365 return 0;
366
367 auto expected_index = PdbIndex::create(pdb_file);
368 if (!expected_index) {
369 llvm::consumeError(expected_index.takeError());
370 return 0;
371 }
372 m_index = std::move(*expected_index);
373 }
374 if (!m_index)
375 return 0;
376
377 // We don't especially have to be precise here. We only distinguish between
378 // stripped and not stripped.
379 abilities = kAllAbilities;
380
381 if (m_index->dbi().isStripped())
382 abilities &= ~(Blocks | LocalVariables);
383 return abilities;
384}
385
387 m_obj_load_address = m_objfile_sp->GetModule()
388 ->GetObjectFile()
389 ->GetBaseAddress()
390 .GetFileAddress();
391 m_index->SetLoadAddress(m_obj_load_address);
392 m_index->ParseSectionContribs();
393
394 auto ts_or_err = m_objfile_sp->GetModule()->GetTypeSystemForLanguage(
396 if (auto err = ts_or_err.takeError()) {
397 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), std::move(err),
398 "Failed to initialize: {0}");
399 } else {
400 if (auto ts = *ts_or_err)
401 ts->SetSymbolFile(this);
403 }
404}
405
407 const DbiModuleList &modules = m_index->dbi().modules();
408 uint32_t count = modules.getModuleCount();
409 if (count == 0)
410 return count;
411
412 // The linker can inject an additional "dummy" compilation unit into the
413 // PDB. Ignore this special compile unit for our purposes, if it is there.
414 // It is always the last one.
415 DbiModuleDescriptor last = modules.getModuleDescriptor(count - 1);
416 if (last.getModuleName() == "* Linker *")
417 --count;
418 return count;
419}
420
422 CompilandIndexItem *cii = m_index->compilands().GetCompiland(block_id.modi);
423 CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(block_id.offset);
424 CompUnitSP comp_unit = GetOrCreateCompileUnit(*cii);
425 lldb::user_id_t opaque_block_uid = toOpaqueUid(block_id);
426 auto ts_or_err = GetTypeSystemForLanguage(comp_unit->GetLanguage());
427 if (auto err = ts_or_err.takeError())
428 return nullptr;
429 auto ts = *ts_or_err;
430 if (!ts)
431 return nullptr;
432 PdbAstBuilder* ast_builder = ts->GetNativePDBParser();
433
434 switch (sym.kind()) {
435 case S_GPROC32:
436 case S_LPROC32:
437 // This is a function. It must be global. Creating the Function entry
438 // for it automatically creates a block for it.
439 if (FunctionSP func = GetOrCreateFunction(block_id, *comp_unit))
440 return &func->GetBlock(false);
441 break;
442 case S_BLOCK32: {
443 // This is a block. Its parent is either a function or another block. In
444 // either case, its parent can be viewed as a block (e.g. a function
445 // contains 1 big block. So just get the parent block and add this block
446 // to it.
447 BlockSym block(static_cast<SymbolRecordKind>(sym.kind()));
448 cantFail(SymbolDeserializer::deserializeAs<BlockSym>(sym, block));
449 lldbassert(block.Parent != 0);
450 PdbCompilandSymId parent_id(block_id.modi, block.Parent);
451 Block *parent_block = GetOrCreateBlock(parent_id);
452 if (!parent_block)
453 return nullptr;
454 Function *func = parent_block->CalculateSymbolContextFunction();
455 lldbassert(func);
456 lldb::addr_t block_base =
457 m_index->MakeVirtualAddress(block.Segment, block.CodeOffset);
458 lldb::addr_t func_base = func->GetAddress().GetFileAddress();
459 BlockSP child_block = parent_block->CreateChild(opaque_block_uid);
460 if (block_base >= func_base)
461 child_block->AddRange(Block::Range(block_base - func_base, block.CodeSize));
462 else {
463 GetObjectFile()->GetModule()->ReportError(
464 "S_BLOCK32 at modi: {0:d} offset: {1:d}: adding range "
465 "[{2:x16}-{3:x16}) which has a base that is less than the "
466 "function's "
467 "low PC 0x%" PRIx64 ". Please file a bug and attach the file at the "
468 "start of this error message",
469 block_id.modi, block_id.offset, block_base,
470 block_base + block.CodeSize, func_base);
471 }
472 ast_builder->GetOrCreateBlockDecl(block_id);
473 m_blocks.insert({opaque_block_uid, child_block});
474 break;
475 }
476 case S_INLINESITE: {
477 // This ensures line table is parsed first so we have inline sites info.
478 comp_unit->GetLineTable();
479
480 std::shared_ptr<InlineSite> inline_site = m_inline_sites[opaque_block_uid];
481 Block *parent_block = GetOrCreateBlock(inline_site->parent_id);
482 if (!parent_block)
483 return nullptr;
484 BlockSP child_block = parent_block->CreateChild(opaque_block_uid);
485 ast_builder->GetOrCreateInlinedFunctionDecl(block_id);
486 // Copy ranges from InlineSite to Block.
487 for (size_t i = 0; i < inline_site->ranges.GetSize(); ++i) {
488 auto *entry = inline_site->ranges.GetEntryAtIndex(i);
489 child_block->AddRange(
490 Block::Range(entry->GetRangeBase(), entry->GetByteSize()));
491 }
492 child_block->FinalizeRanges();
493
494 // Get the inlined function callsite info.
495 Declaration &decl = inline_site->inline_function_info->GetDeclaration();
496 Declaration &callsite = inline_site->inline_function_info->GetCallSite();
497 child_block->SetInlinedFunctionInfo(
498 inline_site->inline_function_info->GetName().GetCString(), nullptr,
499 &decl, &callsite);
500 m_blocks.insert({opaque_block_uid, child_block});
501 break;
502 }
503 default:
504 lldbassert(false && "Symbol is not a block!");
505 }
506
507 return nullptr;
508}
509
511 CompileUnit &comp_unit) {
512 const CompilandIndexItem *cci =
513 m_index->compilands().GetCompiland(func_id.modi);
514 lldbassert(cci);
515 CVSymbol sym_record = cci->m_debug_stream.readSymbolAtOffset(func_id.offset);
516
517 lldbassert(sym_record.kind() == S_LPROC32 || sym_record.kind() == S_GPROC32);
519
520 auto file_vm_addr =
521 m_index->MakeVirtualAddress(sol.so.segment, sol.so.offset);
522 if (file_vm_addr == LLDB_INVALID_ADDRESS || file_vm_addr == 0)
523 return nullptr;
524
525 Address func_addr(file_vm_addr, comp_unit.GetModule()->GetSectionList());
526 if (!func_addr.IsValid())
527 return nullptr;
528
529 ProcSym proc(static_cast<SymbolRecordKind>(sym_record.kind()));
530 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc));
531 if (proc.FunctionType == TypeIndex::None())
532 return nullptr;
533 TypeSP func_type = GetOrCreateType(proc.FunctionType);
534 if (!func_type)
535 return nullptr;
536
537 PdbTypeSymId sig_id(proc.FunctionType, false);
538
539 std::optional<llvm::StringRef> mangled_opt = FindMangledSymbol(
540 SegmentOffset(proc.Segment, proc.CodeOffset), proc.FunctionType);
541 Mangled mangled(mangled_opt.value_or(proc.Name));
542
543 FunctionSP func_sp = std::make_shared<Function>(
544 &comp_unit, toOpaqueUid(func_id), toOpaqueUid(sig_id), mangled,
545 func_type.get(), func_addr,
546 AddressRanges{AddressRange(func_addr, sol.length)});
547
548 comp_unit.AddFunction(func_sp);
549
550 auto ts_or_err = GetTypeSystemForLanguage(comp_unit.GetLanguage());
551 if (auto err = ts_or_err.takeError())
552 return func_sp;
553 auto ts = *ts_or_err;
554 if (!ts)
555 return func_sp;
556 ts->GetNativePDBParser()->GetOrCreateFunctionDecl(func_id);
557
558 return func_sp;
559}
560
563 lldb::LanguageType lang =
564 cci.m_compile_opts ? TranslateLanguage(cci.m_compile_opts->getLanguage())
566
567 LazyBool optimized = eLazyBoolNo;
568 if (cci.m_compile_opts && cci.m_compile_opts->hasOptimizations())
569 optimized = eLazyBoolYes;
570
571 llvm::SmallString<64> source_file_name =
572 m_index->compilands().GetMainSourceFile(cci);
573 FileSpec fs(llvm::sys::path::convert_to_slash(
574 source_file_name, llvm::sys::path::Style::windows_backslash));
575
576 CompUnitSP cu_sp = std::make_shared<CompileUnit>(
577 m_objfile_sp->GetModule(), nullptr, std::make_shared<SupportFile>(fs),
578 toOpaqueUid(cci.m_id), lang, optimized);
579
580 SetCompileUnitAtIndex(cci.m_id.modi, cu_sp);
581 return cu_sp;
582}
583
585 const ModifierRecord &mr,
586 CompilerType ct) {
587 TpiStream &stream = m_index->tpi();
588
589 std::string name;
590
591 if ((mr.Modifiers & ModifierOptions::Const) != ModifierOptions::None)
592 name += "const ";
593 if ((mr.Modifiers & ModifierOptions::Volatile) != ModifierOptions::None)
594 name += "volatile ";
595 if ((mr.Modifiers & ModifierOptions::Unaligned) != ModifierOptions::None)
596 name += "__unaligned ";
597
598 if (mr.ModifiedType.isSimple())
599 name += GetSimpleTypeName(mr.ModifiedType.getSimpleKind());
600 else
601 name += computeTypeName(stream.typeCollection(), mr.ModifiedType);
602 Declaration decl;
603 lldb::TypeSP modified_type = GetOrCreateType(mr.ModifiedType);
604
605 return MakeType(toOpaqueUid(type_id), ConstString(name),
606 llvm::expectedToOptional(modified_type->GetByteSize(nullptr)),
607 nullptr, LLDB_INVALID_UID, Type::eEncodingIsUID, decl, ct,
609}
610
613 const llvm::codeview::PointerRecord &pr,
614 CompilerType ct) {
615 TypeSP pointee = GetOrCreateType(pr.ReferentType);
616 if (!pointee)
617 return nullptr;
618
619 if (pr.isPointerToMember()) {
620 MemberPointerInfo mpi = pr.getMemberInfo();
621 GetOrCreateType(mpi.ContainingType);
622 }
623
624 Declaration decl;
625 return MakeType(toOpaqueUid(type_id), ConstString(), pr.getSize(), nullptr,
628}
629
631 CompilerType ct) {
632 uint64_t uid = toOpaqueUid(PdbTypeSymId(ti, false));
633 if (ti == TypeIndex::NullptrT()) {
634 Declaration decl;
635 return MakeType(uid, ConstString("decltype(nullptr)"), std::nullopt,
636 nullptr, LLDB_INVALID_UID, Type::eEncodingIsUID, decl, ct,
638 }
639
640 if (ti.getSimpleMode() != SimpleTypeMode::Direct) {
641 TypeSP direct_sp = GetOrCreateType(ti.makeDirect());
642 uint32_t pointer_size = 0;
643 switch (ti.getSimpleMode()) {
644 case SimpleTypeMode::FarPointer32:
645 case SimpleTypeMode::NearPointer32:
646 pointer_size = 4;
647 break;
648 case SimpleTypeMode::NearPointer64:
649 pointer_size = 8;
650 break;
651 default:
652 // 128-bit and 16-bit pointers unsupported.
653 return nullptr;
654 }
655 Declaration decl;
656 return MakeType(uid, ConstString(), pointer_size, nullptr, LLDB_INVALID_UID,
658 }
659
660 if (ti.getSimpleKind() == SimpleTypeKind::NotTranslated)
661 return nullptr;
662
663 size_t size = GetTypeSizeForSimpleKind(ti.getSimpleKind());
664 llvm::StringRef type_name = GetSimpleTypeName(ti.getSimpleKind());
665
666 Declaration decl;
667 return MakeType(uid, ConstString(type_name), size, nullptr, LLDB_INVALID_UID,
669}
670
671static std::string GetUnqualifiedTypeName(const TagRecord &record) {
672 if (!record.hasUniqueName())
673 return std::string(MSVCUndecoratedNameParser::DropScope(record.Name));
674
675 llvm::ms_demangle::Demangler demangler;
676 std::string_view sv(record.UniqueName.begin(), record.UniqueName.size());
677 llvm::ms_demangle::TagTypeNode *ttn = demangler.parseTagUniqueName(sv);
678 if (demangler.Error)
679 return std::string(MSVCUndecoratedNameParser::DropScope(record.Name));
680
681 llvm::ms_demangle::IdentifierNode *idn =
682 ttn->QualifiedName->getUnqualifiedIdentifier();
683 return idn->toString();
684}
685
688 const TagRecord &record,
689 size_t size, CompilerType ct) {
690
691 std::string uname = GetUnqualifiedTypeName(record);
692
693 llvm::Expected<Declaration> maybeDecl = ResolveUdtDeclaration(type_id);
694 Declaration decl;
695 if (maybeDecl)
696 decl = std::move(*maybeDecl);
697 else
698 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), maybeDecl.takeError(),
699 "Failed to resolve declaration for '{1}': {0}", uname);
700
701 return MakeType(toOpaqueUid(type_id), ConstString(uname), size, nullptr,
704}
705
707 const ClassRecord &cr,
708 CompilerType ct) {
709 return CreateClassStructUnion(type_id, cr, cr.getSize(), ct);
710}
711
713 const UnionRecord &ur,
714 CompilerType ct) {
715 return CreateClassStructUnion(type_id, ur, ur.getSize(), ct);
716}
717
719 const EnumRecord &er,
720 CompilerType ct) {
721 std::string uname = GetUnqualifiedTypeName(er);
722
723 llvm::Expected<Declaration> maybeDecl = ResolveUdtDeclaration(type_id);
724 Declaration decl;
725 if (maybeDecl)
726 decl = std::move(*maybeDecl);
727 else
728 LLDB_LOG_ERROR(GetLog(LLDBLog::Symbols), maybeDecl.takeError(),
729 "Failed to resolve declaration for '{1}': {0}", uname);
730
731 TypeSP underlying_type = GetOrCreateType(er.UnderlyingType);
732
733 return MakeType(
734 toOpaqueUid(type_id), ConstString(uname),
735 llvm::expectedToOptional(underlying_type->GetByteSize(nullptr)), nullptr,
738}
739
741 const ArrayRecord &ar,
742 CompilerType ct) {
743 TypeSP element_type = GetOrCreateType(ar.ElementType);
744
745 Declaration decl;
746 TypeSP array_sp =
747 MakeType(toOpaqueUid(type_id), ConstString(), ar.Size, nullptr,
750 array_sp->SetEncodingType(element_type.get());
751 return array_sp;
752}
753
755 const MemberFunctionRecord &mfr,
756 CompilerType ct) {
757 if (mfr.ReturnType.isSimple())
758 GetOrCreateType(mfr.ReturnType);
759 CreateSimpleArgumentListTypes(mfr.ArgumentList);
760
761 Declaration decl;
762 return MakeType(toOpaqueUid(type_id), ConstString(), 0, nullptr,
765}
766
768 const ProcedureRecord &pr,
769 CompilerType ct) {
770 if (pr.ReturnType.isSimple())
771 GetOrCreateType(pr.ReturnType);
772 CreateSimpleArgumentListTypes(pr.ArgumentList);
773
774 Declaration decl;
775 return MakeType(toOpaqueUid(type_id), ConstString(), 0, nullptr,
778}
779
781 llvm::codeview::TypeIndex arglist_ti) {
782 if (arglist_ti.isNoneType())
783 return;
784
785 CVType arglist_cvt = m_index->tpi().getType(arglist_ti);
786 if (arglist_cvt.kind() != LF_ARGLIST)
787 return; // invalid debug info
788
789 ArgListRecord alr;
790 llvm::cantFail(
791 TypeDeserializer::deserializeAs<ArgListRecord>(arglist_cvt, alr));
792 for (TypeIndex id : alr.getIndices())
793 if (!id.isNoneType() && id.isSimple())
794 GetOrCreateType(id);
795}
796
798 if (type_id.index.isSimple())
799 return CreateSimpleType(type_id.index, ct);
800
801 TpiStream &stream = type_id.is_ipi ? m_index->ipi() : m_index->tpi();
802 CVType cvt = stream.getType(type_id.index);
803
804 if (cvt.kind() == LF_MODIFIER) {
805 ModifierRecord modifier;
806 llvm::cantFail(
807 TypeDeserializer::deserializeAs<ModifierRecord>(cvt, modifier));
808 return CreateModifierType(type_id, modifier, ct);
809 }
810
811 if (cvt.kind() == LF_POINTER) {
812 PointerRecord pointer;
813 llvm::cantFail(
814 TypeDeserializer::deserializeAs<PointerRecord>(cvt, pointer));
815 return CreatePointerType(type_id, pointer, ct);
816 }
817
818 if (IsClassRecord(cvt.kind())) {
819 ClassRecord cr;
820 llvm::cantFail(TypeDeserializer::deserializeAs<ClassRecord>(cvt, cr));
821 return CreateTagType(type_id, cr, ct);
822 }
823
824 if (cvt.kind() == LF_ENUM) {
825 EnumRecord er;
826 llvm::cantFail(TypeDeserializer::deserializeAs<EnumRecord>(cvt, er));
827 return CreateTagType(type_id, er, ct);
828 }
829
830 if (cvt.kind() == LF_UNION) {
831 UnionRecord ur;
832 llvm::cantFail(TypeDeserializer::deserializeAs<UnionRecord>(cvt, ur));
833 return CreateTagType(type_id, ur, ct);
834 }
835
836 if (cvt.kind() == LF_ARRAY) {
837 ArrayRecord ar;
838 llvm::cantFail(TypeDeserializer::deserializeAs<ArrayRecord>(cvt, ar));
839 return CreateArrayType(type_id, ar, ct);
840 }
841
842 if (cvt.kind() == LF_PROCEDURE) {
843 ProcedureRecord pr;
844 llvm::cantFail(TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, pr));
845 return CreateProcedureType(type_id, pr, ct);
846 }
847 if (cvt.kind() == LF_MFUNCTION) {
848 MemberFunctionRecord mfr;
849 llvm::cantFail(TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfr));
850 return CreateFunctionType(type_id, mfr, ct);
851 }
852
853 return nullptr;
854}
855
857 // If they search for a UDT which is a forward ref, try and resolve the full
858 // decl and just map the forward ref uid to the full decl record.
859 std::optional<PdbTypeSymId> full_decl_uid;
860 if (IsForwardRefUdt(type_id, m_index->tpi())) {
861 auto expected_full_ti =
862 m_index->tpi().findFullDeclForForwardRef(type_id.index);
863 if (!expected_full_ti)
864 llvm::consumeError(expected_full_ti.takeError());
865 else if (*expected_full_ti != type_id.index) {
866 full_decl_uid = PdbTypeSymId(*expected_full_ti, false);
867
868 // It's possible that a lookup would occur for the full decl causing it
869 // to be cached, then a second lookup would occur for the forward decl.
870 // We don't want to create a second full decl, so make sure the full
871 // decl hasn't already been cached.
872 auto full_iter = m_types.find(toOpaqueUid(*full_decl_uid));
873 if (full_iter != m_types.end()) {
874 TypeSP result = full_iter->second;
875 // Map the forward decl to the TypeSP for the full decl so we can take
876 // the fast path next time.
877 m_types[toOpaqueUid(type_id)] = result;
878 return result;
879 }
880 }
881 }
882
883 PdbTypeSymId best_decl_id = full_decl_uid ? *full_decl_uid : type_id;
885 if (auto err = ts_or_err.takeError())
886 return nullptr;
887 auto ts = *ts_or_err;
888 if (!ts)
889 return nullptr;
890
891 PdbAstBuilder* ast_builder = ts->GetNativePDBParser();
892 clang::QualType qt = ast_builder->GetOrCreateType(best_decl_id);
893 if (qt.isNull())
894 return nullptr;
895
896 TypeSP result = CreateType(best_decl_id, ast_builder->ToCompilerType(qt));
897 if (!result)
898 return nullptr;
899
900 uint64_t best_uid = toOpaqueUid(best_decl_id);
901 m_types[best_uid] = result;
902 // If we had both a forward decl and a full decl, make both point to the new
903 // type.
904 if (full_decl_uid)
905 m_types[toOpaqueUid(type_id)] = result;
906
907 return result;
908}
909
911 // We can't use try_emplace / overwrite here because the process of creating
912 // a type could create nested types, which could invalidate iterators. So
913 // we have to do a 2-phase lookup / insert.
914 auto iter = m_types.find(toOpaqueUid(type_id));
915 if (iter != m_types.end())
916 return iter->second;
917
918 TypeSP type = CreateAndCacheType(type_id);
919 if (type)
920 GetTypeList().Insert(type);
921 return type;
922}
923
925 CVSymbol sym = m_index->symrecords().readRecord(var_id.offset);
926 if (sym.kind() == S_CONSTANT)
927 return CreateConstantSymbol(var_id, sym);
928
930 TypeIndex ti;
931 llvm::StringRef name;
932 lldb::addr_t addr = 0;
933 uint16_t section = 0;
934 uint32_t offset = 0;
935 bool is_external = false;
936 switch (sym.kind()) {
937 case S_GDATA32:
938 is_external = true;
939 [[fallthrough]];
940 case S_LDATA32: {
941 DataSym ds(sym.kind());
942 llvm::cantFail(SymbolDeserializer::deserializeAs<DataSym>(sym, ds));
943 ti = ds.Type;
944 scope = (sym.kind() == S_GDATA32) ? eValueTypeVariableGlobal
946 name = ds.Name;
947 section = ds.Segment;
948 offset = ds.DataOffset;
949 addr = m_index->MakeVirtualAddress(ds.Segment, ds.DataOffset);
950 break;
951 }
952 case S_GTHREAD32:
953 is_external = true;
954 [[fallthrough]];
955 case S_LTHREAD32: {
956 ThreadLocalDataSym tlds(sym.kind());
957 llvm::cantFail(
958 SymbolDeserializer::deserializeAs<ThreadLocalDataSym>(sym, tlds));
959 ti = tlds.Type;
960 name = tlds.Name;
961 section = tlds.Segment;
962 offset = tlds.DataOffset;
963 addr = m_index->MakeVirtualAddress(tlds.Segment, tlds.DataOffset);
965 break;
966 }
967 default:
968 llvm_unreachable("unreachable!");
969 }
970
971 CompUnitSP comp_unit;
972 std::optional<uint16_t> modi = m_index->GetModuleIndexForVa(addr);
973 // Some globals has modi points to the linker module, ignore them.
974 if (!modi || modi >= GetNumCompileUnits())
975 return nullptr;
976
977 CompilandIndexItem &cci = m_index->compilands().GetOrCreateCompiland(*modi);
978 comp_unit = GetOrCreateCompileUnit(cci);
979
980 Declaration decl;
981 PdbTypeSymId tid(ti, false);
982 SymbolFileTypeSP type_sp =
983 std::make_shared<SymbolFileType>(*this, toOpaqueUid(tid));
984 Variable::RangeList ranges;
985 auto ts_or_err = GetTypeSystemForLanguage(comp_unit->GetLanguage());
986 if (auto err = ts_or_err.takeError())
987 return nullptr;
988 auto ts = *ts_or_err;
989 if (!ts)
990 return nullptr;
991
992 ts->GetNativePDBParser()->GetOrCreateVariableDecl(var_id);
993
994 ModuleSP module_sp = GetObjectFile()->GetModule();
995 DWARFExpressionList location(
996 module_sp, MakeGlobalLocationExpression(section, offset, module_sp),
997 nullptr);
998
999 std::string global_name("::");
1000 global_name += name;
1001 bool artificial = false;
1002 bool location_is_constant_data = false;
1003 bool static_member = false;
1004 VariableSP var_sp = std::make_shared<Variable>(
1005 toOpaqueUid(var_id), name.str().c_str(), global_name.c_str(), type_sp,
1006 scope, comp_unit.get(), ranges, &decl, location, is_external, artificial,
1007 location_is_constant_data, static_member);
1008
1009 return var_sp;
1010}
1011
1014 const CVSymbol &cvs) {
1015 TpiStream &tpi = m_index->tpi();
1016 ConstantSym constant(cvs.kind());
1017
1018 llvm::cantFail(SymbolDeserializer::deserializeAs<ConstantSym>(cvs, constant));
1019 std::string global_name("::");
1020 global_name += constant.Name;
1021 PdbTypeSymId tid(constant.Type, false);
1022 SymbolFileTypeSP type_sp =
1023 std::make_shared<SymbolFileType>(*this, toOpaqueUid(tid));
1024
1025 Declaration decl;
1026 Variable::RangeList ranges;
1027 ModuleSP module = GetObjectFile()->GetModule();
1028 DWARFExpressionList location(module,
1030 constant.Type, tpi, constant.Value, module),
1031 nullptr);
1032
1033 bool external = false;
1034 bool artificial = false;
1035 bool location_is_constant_data = true;
1036 bool static_member = false;
1037 VariableSP var_sp = std::make_shared<Variable>(
1038 toOpaqueUid(var_id), constant.Name.str().c_str(), global_name.c_str(),
1039 type_sp, eValueTypeVariableGlobal, module.get(), ranges, &decl, location,
1040 external, artificial, location_is_constant_data, static_member);
1041 return var_sp;
1042}
1043
1046 auto emplace_result = m_global_vars.try_emplace(toOpaqueUid(var_id), nullptr);
1047 if (emplace_result.second) {
1048 if (VariableSP var_sp = CreateGlobalVariable(var_id))
1049 emplace_result.first->second = var_sp;
1050 else
1051 return nullptr;
1052 }
1053
1054 return emplace_result.first->second;
1055}
1056
1058 return GetOrCreateType(PdbTypeSymId(ti, false));
1059}
1060
1062 CompileUnit &comp_unit) {
1063 auto emplace_result = m_functions.try_emplace(toOpaqueUid(func_id), nullptr);
1064 if (emplace_result.second)
1065 emplace_result.first->second = CreateFunction(func_id, comp_unit);
1066
1067 return emplace_result.first->second;
1068}
1069
1072
1073 auto emplace_result =
1074 m_compilands.try_emplace(toOpaqueUid(cci.m_id), nullptr);
1075 if (emplace_result.second)
1076 emplace_result.first->second = CreateCompileUnit(cci);
1077
1078 lldbassert(emplace_result.first->second);
1079 return emplace_result.first->second;
1080}
1081
1083 auto iter = m_blocks.find(toOpaqueUid(block_id));
1084 if (iter != m_blocks.end())
1085 return iter->second.get();
1086
1087 return CreateBlock(block_id);
1088}
1089
1092 TypeSystem* ts_or_err = decl_ctx.GetTypeSystem();
1093 if (!ts_or_err)
1094 return;
1095 PdbAstBuilder* ast_builder = ts_or_err->GetNativePDBParser();
1096 clang::DeclContext *context = ast_builder->FromCompilerDeclContext(decl_ctx);
1097 if (!context)
1098 return;
1099 ast_builder->ParseDeclsForContext(*context);
1100}
1101
1103 if (index >= GetNumCompileUnits())
1104 return CompUnitSP();
1105 lldbassert(index < UINT16_MAX);
1106 if (index >= UINT16_MAX)
1107 return nullptr;
1108
1109 CompilandIndexItem &item = m_index->compilands().GetOrCreateCompiland(index);
1110
1111 return GetOrCreateCompileUnit(item);
1112}
1113
1115 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1116 PdbSymUid uid(comp_unit.GetID());
1118
1119 CompilandIndexItem *item =
1120 m_index->compilands().GetCompiland(uid.asCompiland().modi);
1121 lldbassert(item);
1122 if (!item->m_compile_opts)
1124
1125 return TranslateLanguage(item->m_compile_opts->getLanguage());
1126}
1127
1129 auto *section_list = m_objfile_sp->GetSectionList();
1130 if (!section_list)
1131 return;
1132
1133 PublicSym32 last_sym;
1134 size_t last_sym_idx = 0;
1135 lldb::SectionSP section_sp;
1136
1137 // To estimate the size of a symbol, we use the difference to the next symbol.
1138 // If there's no next symbol or the section/segment changed, the symbol will
1139 // take the remaining space. The estimate can be too high in case there's
1140 // padding between symbols. This similar to the algorithm used by the DIA
1141 // SDK.
1142 auto finish_last_symbol = [&](const PublicSym32 *next) {
1143 if (!section_sp)
1144 return;
1145 Symbol *last = symtab.SymbolAtIndex(last_sym_idx);
1146 if (!last)
1147 return;
1148
1149 if (next && last_sym.Segment == next->Segment) {
1150 assert(last_sym.Offset <= next->Offset);
1151 last->SetByteSize(next->Offset - last_sym.Offset);
1152 } else {
1153 // the last symbol was the last in its section
1154 assert(section_sp->GetByteSize() >= last_sym.Offset);
1155 assert(!next || next->Segment > last_sym.Segment);
1156 last->SetByteSize(section_sp->GetByteSize() - last_sym.Offset);
1157 }
1158 };
1159
1160 // The address map is sorted by the address of a symbol.
1161 for (auto pid : m_index->publics().getAddressMap()) {
1162 PdbGlobalSymId global{pid, true};
1163 CVSymbol sym = m_index->ReadSymbolRecord(global);
1164 auto kind = sym.kind();
1165 if (kind != S_PUB32)
1166 continue;
1167 PublicSym32 pub =
1168 llvm::cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(sym));
1169 finish_last_symbol(&pub);
1170
1171 if (!section_sp || last_sym.Segment != pub.Segment)
1172 section_sp = section_list->FindSectionByID(pub.Segment);
1173
1174 if (!section_sp)
1175 continue;
1176
1178 if ((pub.Flags & PublicSymFlags::Function) != PublicSymFlags::None ||
1179 (pub.Flags & PublicSymFlags::Code) != PublicSymFlags::None)
1180 type = eSymbolTypeCode;
1181
1182 last_sym_idx =
1183 symtab.AddSymbol(Symbol(/*symID=*/pid,
1184 /*name=*/pub.Name,
1185 /*type=*/type,
1186 /*external=*/true,
1187 /*is_debug=*/true,
1188 /*is_trampoline=*/false,
1189 /*is_artificial=*/false,
1190 /*section_sp=*/section_sp,
1191 /*value=*/pub.Offset,
1192 /*size=*/0,
1193 /*size_is_valid=*/false,
1194 /*contains_linker_annotations=*/false,
1195 /*flags=*/0));
1196 last_sym = pub;
1197 }
1198
1199 finish_last_symbol(nullptr);
1200}
1201
1203 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1204 PdbSymUid uid{comp_unit.GetID()};
1206 uint16_t modi = uid.asCompiland().modi;
1207 CompilandIndexItem &cii = m_index->compilands().GetOrCreateCompiland(modi);
1208
1209 size_t count = comp_unit.GetNumFunctions();
1210 const CVSymbolArray &syms = cii.m_debug_stream.getSymbolArray();
1211 for (auto iter = syms.begin(); iter != syms.end(); ++iter) {
1212 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32)
1213 continue;
1214
1215 PdbCompilandSymId sym_id{modi, iter.offset()};
1216
1217 FunctionSP func = GetOrCreateFunction(sym_id, comp_unit);
1218 }
1219
1220 size_t new_count = comp_unit.GetNumFunctions();
1221 lldbassert(new_count >= count);
1222 return new_count - count;
1223}
1224
1225static bool NeedsResolvedCompileUnit(uint32_t resolve_scope) {
1226 // If any of these flags are set, we need to resolve the compile unit.
1227 uint32_t flags = eSymbolContextCompUnit;
1228 flags |= eSymbolContextVariable;
1229 flags |= eSymbolContextFunction;
1230 flags |= eSymbolContextBlock;
1231 flags |= eSymbolContextLineEntry;
1232 return (resolve_scope & flags) != 0;
1233}
1234
1236 const Address &addr, SymbolContextItem resolve_scope, SymbolContext &sc) {
1237 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1238 uint32_t resolved_flags = 0;
1239 lldb::addr_t file_addr = addr.GetFileAddress();
1240
1241 if (NeedsResolvedCompileUnit(resolve_scope)) {
1242 std::optional<uint16_t> modi = m_index->GetModuleIndexForVa(file_addr);
1243 if (!modi)
1244 return 0;
1245 CompUnitSP cu_sp = GetCompileUnitAtIndex(*modi);
1246 if (!cu_sp)
1247 return 0;
1248
1249 sc.comp_unit = cu_sp.get();
1250 resolved_flags |= eSymbolContextCompUnit;
1251 }
1252
1253 if (resolve_scope & eSymbolContextFunction ||
1254 resolve_scope & eSymbolContextBlock) {
1256 std::vector<SymbolAndUid> matches = m_index->FindSymbolsByVa(file_addr);
1257 // Search the matches in reverse. This way if there are multiple matches
1258 // (for example we are 3 levels deep in a nested scope) it will find the
1259 // innermost one first.
1260 for (const auto &match : llvm::reverse(matches)) {
1261 if (match.uid.kind() != PdbSymUidKind::CompilandSym)
1262 continue;
1263
1264 PdbCompilandSymId csid = match.uid.asCompilandSym();
1265 CVSymbol cvs = m_index->ReadSymbolRecord(csid);
1266 PDB_SymType type = CVSymToPDBSym(cvs.kind());
1267 if (type != PDB_SymType::Function && type != PDB_SymType::Block)
1268 continue;
1269 if (type == PDB_SymType::Function) {
1270 sc.function = GetOrCreateFunction(csid, *sc.comp_unit).get();
1271 if (sc.function) {
1272 Block &block = sc.function->GetBlock(true);
1273 addr_t func_base = sc.function->GetAddress().GetFileAddress();
1274 addr_t offset = file_addr - func_base;
1275 sc.block = block.FindInnermostBlockByOffset(offset);
1276 }
1277 }
1278
1279 if (type == PDB_SymType::Block) {
1280 Block *block = GetOrCreateBlock(csid);
1281 if (!block)
1282 continue;
1284 if (sc.function) {
1285 sc.function->GetBlock(true);
1286 addr_t func_base = sc.function->GetAddress().GetFileAddress();
1287 addr_t offset = file_addr - func_base;
1288 sc.block = block->FindInnermostBlockByOffset(offset);
1289 }
1290 }
1291 if (sc.function)
1292 resolved_flags |= eSymbolContextFunction;
1293 if (sc.block)
1294 resolved_flags |= eSymbolContextBlock;
1295 break;
1296 }
1297 }
1298
1299 if (resolve_scope & eSymbolContextLineEntry) {
1301 if (auto *line_table = sc.comp_unit->GetLineTable()) {
1302 if (line_table->FindLineEntryByAddress(addr, sc.line_entry))
1303 resolved_flags |= eSymbolContextLineEntry;
1304 }
1305 }
1306
1307 return resolved_flags;
1308}
1309
1311 const SourceLocationSpec &src_location_spec,
1312 lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
1313 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1314 const uint32_t prev_size = sc_list.GetSize();
1315 if (resolve_scope & eSymbolContextCompUnit) {
1316 for (uint32_t cu_idx = 0, num_cus = GetNumCompileUnits(); cu_idx < num_cus;
1317 ++cu_idx) {
1318 CompileUnit *cu = ParseCompileUnitAtIndex(cu_idx).get();
1319 if (!cu)
1320 continue;
1321
1322 bool file_spec_matches_cu_file_spec = FileSpec::Match(
1323 src_location_spec.GetFileSpec(), cu->GetPrimaryFile());
1324 if (file_spec_matches_cu_file_spec) {
1325 cu->ResolveSymbolContext(src_location_spec, resolve_scope, sc_list);
1326 break;
1327 }
1328 }
1329 }
1330 return sc_list.GetSize() - prev_size;
1331}
1332
1334 // Unfortunately LLDB is set up to parse the entire compile unit line table
1335 // all at once, even if all it really needs is line info for a specific
1336 // function. In the future it would be nice if it could set the sc.m_function
1337 // member, and we could only get the line info for the function in question.
1338 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1339 PdbSymUid cu_id(comp_unit.GetID());
1341 uint16_t modi = cu_id.asCompiland().modi;
1342 CompilandIndexItem *cii = m_index->compilands().GetCompiland(modi);
1343 lldbassert(cii);
1344
1345 // Parse DEBUG_S_LINES subsections first, then parse all S_INLINESITE records
1346 // in this CU. Add line entries into the set first so that if there are line
1347 // entries with same addres, the later is always more accurate than the
1348 // former.
1349 std::set<LineTable::Entry, LineTableEntryComparator> line_set;
1350
1351 // This is basically a copy of the .debug$S subsections from all original COFF
1352 // object files merged together with address relocations applied. We are
1353 // looking for all DEBUG_S_LINES subsections.
1354 for (const DebugSubsectionRecord &dssr :
1355 cii->m_debug_stream.getSubsectionsArray()) {
1356 if (dssr.kind() != DebugSubsectionKind::Lines)
1357 continue;
1358
1359 DebugLinesSubsectionRef lines;
1360 llvm::BinaryStreamReader reader(dssr.getRecordData());
1361 if (auto EC = lines.initialize(reader)) {
1362 llvm::consumeError(std::move(EC));
1363 return false;
1364 }
1365
1366 const LineFragmentHeader *lfh = lines.header();
1367 uint64_t virtual_addr =
1368 m_index->MakeVirtualAddress(lfh->RelocSegment, lfh->RelocOffset);
1369 if (virtual_addr == LLDB_INVALID_ADDRESS)
1370 continue;
1371
1372 for (const LineColumnEntry &group : lines) {
1373 llvm::Expected<uint32_t> file_index_or_err =
1374 GetFileIndex(*cii, group.NameIndex);
1375 if (!file_index_or_err)
1376 continue;
1377 uint32_t file_index = file_index_or_err.get();
1378 lldbassert(!group.LineNumbers.empty());
1381 for (const LineNumberEntry &entry : group.LineNumbers) {
1382 LineInfo cur_info(entry.Flags);
1383
1384 if (cur_info.isAlwaysStepInto() || cur_info.isNeverStepInto())
1385 continue;
1386
1387 uint64_t addr = virtual_addr + entry.Offset;
1388
1389 bool is_statement = cur_info.isStatement();
1390 bool is_prologue = IsFunctionPrologue(*cii, addr);
1391 bool is_epilogue = IsFunctionEpilogue(*cii, addr);
1392
1393 uint32_t lno = cur_info.getStartLine();
1394
1395 LineTable::Entry new_entry(addr, lno, 0, file_index, is_statement, false,
1396 is_prologue, is_epilogue, false);
1397 // Terminal entry has lower precedence than new entry.
1398 auto iter = line_set.find(new_entry);
1399 if (iter != line_set.end() && iter->is_terminal_entry)
1400 line_set.erase(iter);
1401 line_set.insert(new_entry);
1402
1403 if (line_entry.GetRangeBase() != LLDB_INVALID_ADDRESS) {
1404 line_entry.SetRangeEnd(addr);
1405 cii->m_global_line_table.Append(line_entry);
1406 }
1407 line_entry.SetRangeBase(addr);
1408 line_entry.data = {file_index, lno};
1409 }
1410 LineInfo last_line(group.LineNumbers.back().Flags);
1411 line_set.emplace(virtual_addr + lfh->CodeSize, last_line.getEndLine(), 0,
1412 file_index, false, false, false, false, true);
1413
1414 if (line_entry.GetRangeBase() != LLDB_INVALID_ADDRESS) {
1415 line_entry.SetRangeEnd(virtual_addr + lfh->CodeSize);
1416 cii->m_global_line_table.Append(line_entry);
1417 }
1418 }
1419 }
1420
1422
1423 // Parse all S_INLINESITE in this CU.
1424 const CVSymbolArray &syms = cii->m_debug_stream.getSymbolArray();
1425 for (auto iter = syms.begin(); iter != syms.end();) {
1426 if (iter->kind() != S_LPROC32 && iter->kind() != S_GPROC32) {
1427 ++iter;
1428 continue;
1429 }
1430
1431 uint32_t record_offset = iter.offset();
1432 CVSymbol func_record =
1433 cii->m_debug_stream.readSymbolAtOffset(record_offset);
1435 addr_t file_vm_addr =
1436 m_index->MakeVirtualAddress(sol.so.segment, sol.so.offset);
1437 if (file_vm_addr == LLDB_INVALID_ADDRESS)
1438 continue;
1439
1440 Address func_base(file_vm_addr, comp_unit.GetModule()->GetSectionList());
1441 PdbCompilandSymId func_id{modi, record_offset};
1442
1443 // Iterate all S_INLINESITEs in the function.
1444 auto parse_inline_sites = [&](SymbolKind kind, PdbCompilandSymId id) {
1445 if (kind != S_INLINESITE)
1446 return false;
1447
1448 ParseInlineSite(id, func_base);
1449
1450 for (const auto &line_entry :
1451 m_inline_sites[toOpaqueUid(id)]->line_entries) {
1452 // If line_entry is not terminal entry, remove previous line entry at
1453 // the same address and insert new one. Terminal entry inside an inline
1454 // site might not be terminal entry for its parent.
1455 if (!line_entry.is_terminal_entry)
1456 line_set.erase(line_entry);
1457 line_set.insert(line_entry);
1458 }
1459 // No longer useful after adding to line_set.
1460 m_inline_sites[toOpaqueUid(id)]->line_entries.clear();
1461 return true;
1462 };
1463 ParseSymbolArrayInScope(func_id, parse_inline_sites);
1464 // Jump to the end of the function record.
1465 iter = syms.at(getScopeEndOffset(func_record));
1466 }
1467
1469
1470 // Add line entries in line_set to line_table.
1471 std::vector<LineTable::Sequence> sequence(1);
1472 for (const auto &line_entry : line_set) {
1474 sequence.back(), line_entry.file_addr, line_entry.line,
1475 line_entry.column, line_entry.file_idx,
1476 line_entry.is_start_of_statement, line_entry.is_start_of_basic_block,
1477 line_entry.is_prologue_end, line_entry.is_epilogue_begin,
1478 line_entry.is_terminal_entry);
1479 }
1480 auto line_table =
1481 std::make_unique<LineTable>(&comp_unit, std::move(sequence));
1482
1483 if (line_table->GetSize() == 0)
1484 return false;
1485
1486 comp_unit.SetLineTable(line_table.release());
1487 return true;
1488}
1489
1491 // PDB doesn't contain information about macros
1492 return false;
1493}
1494
1495llvm::Expected<uint32_t>
1497 uint32_t file_id) {
1498 if (!cii.m_strings.hasChecksums() || !cii.m_strings.hasStrings())
1499 return llvm::make_error<RawError>(raw_error_code::no_entry);
1500
1501 const auto &checksums = cii.m_strings.checksums().getArray();
1502 const auto &strings = cii.m_strings.strings();
1503 // Indices in this structure are actually offsets of records in the
1504 // DEBUG_S_FILECHECKSUMS subsection. Those entries then have an index
1505 // into the global PDB string table.
1506 auto iter = checksums.at(file_id);
1507 if (iter == checksums.end())
1508 return llvm::make_error<RawError>(raw_error_code::no_entry);
1509
1510 llvm::Expected<llvm::StringRef> efn = strings.getString(iter->FileNameOffset);
1511 if (!efn) {
1512 return efn.takeError();
1513 }
1514
1515 // LLDB wants the index of the file in the list of support files.
1516 auto fn_iter = llvm::find(cii.m_file_list, *efn);
1517 if (fn_iter != cii.m_file_list.end())
1518 return std::distance(cii.m_file_list.begin(), fn_iter);
1519 return llvm::make_error<RawError>(raw_error_code::no_entry);
1520}
1521
1523 SupportFileList &support_files) {
1524 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1525 PdbSymUid cu_id(comp_unit.GetID());
1527 CompilandIndexItem *cci =
1528 m_index->compilands().GetCompiland(cu_id.asCompiland().modi);
1529 lldbassert(cci);
1530
1531 for (llvm::StringRef f : cci->m_file_list) {
1532 FileSpec::Style style =
1533 f.starts_with("/") ? FileSpec::Style::posix : FileSpec::Style::windows;
1534 FileSpec spec(f, style);
1535 support_files.Append(spec);
1536 }
1537 return true;
1538}
1539
1541 const SymbolContext &sc, std::vector<SourceModule> &imported_modules) {
1542 // PDB does not yet support module debug info
1543 return false;
1544}
1545
1547 Address func_addr) {
1548 lldb::user_id_t opaque_uid = toOpaqueUid(id);
1549 if (m_inline_sites.contains(opaque_uid))
1550 return;
1551
1552 addr_t func_base = func_addr.GetFileAddress();
1553 CompilandIndexItem *cii = m_index->compilands().GetCompiland(id.modi);
1554 CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(id.offset);
1555 CompUnitSP comp_unit = GetOrCreateCompileUnit(*cii);
1556
1557 InlineSiteSym inline_site(static_cast<SymbolRecordKind>(sym.kind()));
1558 cantFail(SymbolDeserializer::deserializeAs<InlineSiteSym>(sym, inline_site));
1559 PdbCompilandSymId parent_id(id.modi, inline_site.Parent);
1560
1561 std::shared_ptr<InlineSite> inline_site_sp =
1562 std::make_shared<InlineSite>(parent_id);
1563
1564 // Get the inlined function declaration info.
1565 auto iter = cii->m_inline_map.find(inline_site.Inlinee);
1566 if (iter == cii->m_inline_map.end())
1567 return;
1568 InlineeSourceLine inlinee_line = iter->second;
1569
1570 const SupportFileList &files = comp_unit->GetSupportFiles();
1571 FileSpec decl_file;
1572 llvm::Expected<uint32_t> file_index_or_err =
1573 GetFileIndex(*cii, inlinee_line.Header->FileID);
1574 if (!file_index_or_err)
1575 return;
1576 uint32_t file_offset = file_index_or_err.get();
1577 decl_file = files.GetFileSpecAtIndex(file_offset);
1578 uint32_t decl_line = inlinee_line.Header->SourceLineNum;
1579 std::unique_ptr<Declaration> decl_up =
1580 std::make_unique<Declaration>(decl_file, decl_line);
1581
1582 // Parse range and line info.
1583 uint32_t code_offset = 0;
1584 int32_t line_offset = 0;
1585 std::optional<uint32_t> code_offset_base;
1586 std::optional<uint32_t> code_offset_end;
1587 std::optional<int32_t> cur_line_offset;
1588 std::optional<int32_t> next_line_offset;
1589 std::optional<uint32_t> next_file_offset;
1590
1591 bool is_terminal_entry = false;
1592 bool is_start_of_statement = true;
1593 // The first instruction is the prologue end.
1594 bool is_prologue_end = true;
1595
1596 auto update_code_offset = [&](uint32_t code_delta) {
1597 if (!code_offset_base)
1598 code_offset_base = code_offset;
1599 else if (!code_offset_end)
1600 code_offset_end = *code_offset_base + code_delta;
1601 };
1602 auto update_line_offset = [&](int32_t line_delta) {
1603 line_offset += line_delta;
1604 if (!code_offset_base || !cur_line_offset)
1605 cur_line_offset = line_offset;
1606 else
1607 next_line_offset = line_offset;
1608 ;
1609 };
1610 auto update_file_offset = [&](uint32_t offset) {
1611 if (!code_offset_base)
1612 file_offset = offset;
1613 else
1614 next_file_offset = offset;
1615 };
1616
1617 for (auto &annot : inline_site.annotations()) {
1618 switch (annot.OpCode) {
1619 case BinaryAnnotationsOpCode::CodeOffset:
1620 case BinaryAnnotationsOpCode::ChangeCodeOffset:
1621 case BinaryAnnotationsOpCode::ChangeCodeOffsetBase:
1622 code_offset += annot.U1;
1623 update_code_offset(annot.U1);
1624 break;
1625 case BinaryAnnotationsOpCode::ChangeLineOffset:
1626 update_line_offset(annot.S1);
1627 break;
1628 case BinaryAnnotationsOpCode::ChangeCodeLength:
1629 update_code_offset(annot.U1);
1630 code_offset += annot.U1;
1631 is_terminal_entry = true;
1632 break;
1633 case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset:
1634 code_offset += annot.U1;
1635 update_code_offset(annot.U1);
1636 update_line_offset(annot.S1);
1637 break;
1638 case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset:
1639 code_offset += annot.U2;
1640 update_code_offset(annot.U2);
1641 update_code_offset(annot.U1);
1642 code_offset += annot.U1;
1643 is_terminal_entry = true;
1644 break;
1645 case BinaryAnnotationsOpCode::ChangeFile:
1646 update_file_offset(annot.U1);
1647 break;
1648 default:
1649 break;
1650 }
1651
1652 // Add range if current range is finished.
1653 if (code_offset_base && code_offset_end && cur_line_offset) {
1654 inline_site_sp->ranges.Append(RangeSourceLineVector::Entry(
1655 *code_offset_base, *code_offset_end - *code_offset_base,
1656 decl_line + *cur_line_offset));
1657 // Set base, end, file offset and line offset for next range.
1658 if (next_file_offset)
1659 file_offset = *next_file_offset;
1660 if (next_line_offset) {
1661 cur_line_offset = next_line_offset;
1662 next_line_offset = std::nullopt;
1663 }
1664 code_offset_base = is_terminal_entry ? std::nullopt : code_offset_end;
1665 code_offset_end = next_file_offset = std::nullopt;
1666 }
1667 if (code_offset_base && cur_line_offset) {
1668 if (is_terminal_entry) {
1669 LineTable::Entry line_entry(
1670 func_base + *code_offset_base, decl_line + *cur_line_offset, 0,
1671 file_offset, false, false, false, false, true);
1672 inline_site_sp->line_entries.push_back(line_entry);
1673 } else {
1674 LineTable::Entry line_entry(func_base + *code_offset_base,
1675 decl_line + *cur_line_offset, 0,
1676 file_offset, is_start_of_statement, false,
1677 is_prologue_end, false, false);
1678 inline_site_sp->line_entries.push_back(line_entry);
1679 is_prologue_end = false;
1680 is_start_of_statement = false;
1681 }
1682 }
1683 if (is_terminal_entry)
1684 is_start_of_statement = true;
1685 is_terminal_entry = false;
1686 }
1687
1688 inline_site_sp->ranges.Sort();
1689
1690 // Get the inlined function callsite info.
1691 std::unique_ptr<Declaration> callsite_up;
1692 if (!inline_site_sp->ranges.IsEmpty()) {
1693 auto *entry = inline_site_sp->ranges.GetEntryAtIndex(0);
1694 addr_t base_offset = entry->GetRangeBase();
1695 if (cii->m_debug_stream.readSymbolAtOffset(parent_id.offset).kind() ==
1696 S_INLINESITE) {
1697 // Its parent is another inline site, lookup parent site's range vector
1698 // for callsite line.
1699 ParseInlineSite(parent_id, func_base);
1700 std::shared_ptr<InlineSite> parent_site =
1701 m_inline_sites[toOpaqueUid(parent_id)];
1702 FileSpec &parent_decl_file =
1703 parent_site->inline_function_info->GetDeclaration().GetFile();
1704 if (auto *parent_entry =
1705 parent_site->ranges.FindEntryThatContains(base_offset)) {
1706 callsite_up =
1707 std::make_unique<Declaration>(parent_decl_file, parent_entry->data);
1708 }
1709 } else {
1710 // Its parent is a function, lookup global line table for callsite.
1711 if (auto *entry = cii->m_global_line_table.FindEntryThatContains(
1712 func_base + base_offset)) {
1713 const FileSpec &callsite_file =
1714 files.GetFileSpecAtIndex(entry->data.first);
1715 callsite_up =
1716 std::make_unique<Declaration>(callsite_file, entry->data.second);
1717 }
1718 }
1719 }
1720
1721 // Get the inlined function name.
1722 CVType inlinee_cvt = m_index->ipi().getType(inline_site.Inlinee);
1723 std::string inlinee_name;
1724 if (inlinee_cvt.kind() == LF_MFUNC_ID) {
1725 MemberFuncIdRecord mfr;
1726 cantFail(
1727 TypeDeserializer::deserializeAs<MemberFuncIdRecord>(inlinee_cvt, mfr));
1728 LazyRandomTypeCollection &types = m_index->tpi().typeCollection();
1729 inlinee_name.append(std::string(types.getTypeName(mfr.ClassType)));
1730 inlinee_name.append("::");
1731 inlinee_name.append(mfr.getName().str());
1732 } else if (inlinee_cvt.kind() == LF_FUNC_ID) {
1733 FuncIdRecord fir;
1734 cantFail(TypeDeserializer::deserializeAs<FuncIdRecord>(inlinee_cvt, fir));
1735 TypeIndex parent_idx = fir.getParentScope();
1736 if (!parent_idx.isNoneType()) {
1737 LazyRandomTypeCollection &ids = m_index->ipi().typeCollection();
1738 inlinee_name.append(std::string(ids.getTypeName(parent_idx)));
1739 inlinee_name.append("::");
1740 }
1741 inlinee_name.append(fir.getName().str());
1742 }
1743 inline_site_sp->inline_function_info = std::make_shared<InlineFunctionInfo>(
1744 inlinee_name.c_str(), llvm::StringRef(), decl_up.get(),
1745 callsite_up.get());
1746
1747 m_inline_sites[opaque_uid] = inline_site_sp;
1748}
1749
1751 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1752 PdbCompilandSymId func_id = PdbSymUid(func.GetID()).asCompilandSym();
1753 // After we iterate through inline sites inside the function, we already get
1754 // all the info needed, removing from the map to save memory.
1755 std::set<uint64_t> remove_uids;
1756 auto parse_blocks = [&](SymbolKind kind, PdbCompilandSymId id) {
1757 if (kind == S_GPROC32 || kind == S_LPROC32 || kind == S_BLOCK32 ||
1758 kind == S_INLINESITE) {
1759 GetOrCreateBlock(id);
1760 if (kind == S_INLINESITE)
1761 remove_uids.insert(toOpaqueUid(id));
1762 return true;
1763 }
1764 return false;
1765 };
1766 size_t count = ParseSymbolArrayInScope(func_id, parse_blocks);
1767 for (uint64_t uid : remove_uids) {
1768 m_inline_sites.erase(uid);
1769 }
1770
1771 func.GetBlock(false).SetBlockInfoHasBeenParsed(true, true);
1772 return count;
1773}
1774
1776 PdbCompilandSymId parent_id,
1777 llvm::function_ref<bool(SymbolKind, PdbCompilandSymId)> fn) {
1778 CompilandIndexItem *cii = m_index->compilands().GetCompiland(parent_id.modi);
1779 CVSymbolArray syms =
1780 cii->m_debug_stream.getSymbolArrayForScope(parent_id.offset);
1781
1782 size_t count = 1;
1783 for (auto iter = syms.begin(); iter != syms.end(); ++iter) {
1784 PdbCompilandSymId child_id(parent_id.modi, iter.offset());
1785 if (fn(iter->kind(), child_id))
1786 ++count;
1787 }
1788
1789 return count;
1790}
1791
1792void SymbolFileNativePDB::DumpClangAST(Stream &s, llvm::StringRef filter,
1793 bool show_color) {
1795 if (!ts_or_err)
1796 return;
1797 auto ts = *ts_or_err;
1798 TypeSystemClang *clang = llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
1799 if (!clang)
1800 return;
1801 clang->GetNativePDBParser()->Dump(s, filter, show_color);
1802}
1803
1805 if (!m_func_full_names.IsEmpty() || !m_global_variable_base_names.IsEmpty())
1806 return;
1807
1808 // (segment, code offset) -> gid
1809 std::map<std::pair<uint16_t, uint32_t>, uint32_t> func_addr_ids;
1810
1811 // First, look through all items in the globals table.
1812 for (const uint32_t gid : m_index->globals().getGlobalsTable()) {
1813 CVSymbol sym = m_index->symrecords().readRecord(gid);
1814 auto kind = sym.kind();
1815
1816 // If this is a global variable, we only need to look at the name
1817 llvm::StringRef name;
1818 switch (kind) {
1819 case SymbolKind::S_GDATA32:
1820 case SymbolKind::S_LDATA32: {
1821 DataSym data =
1822 llvm::cantFail(SymbolDeserializer::deserializeAs<DataSym>(sym));
1823 name = data.Name;
1824 break;
1825 }
1826 case SymbolKind::S_GTHREAD32:
1827 case SymbolKind::S_LTHREAD32: {
1828 ThreadLocalDataSym data = llvm::cantFail(
1829 SymbolDeserializer::deserializeAs<ThreadLocalDataSym>(sym));
1830 name = data.Name;
1831 break;
1832 }
1833 case SymbolKind::S_CONSTANT: {
1834 ConstantSym data =
1835 llvm::cantFail(SymbolDeserializer::deserializeAs<ConstantSym>(sym));
1836 name = data.Name;
1837 break;
1838 }
1839 default:
1840 break;
1841 }
1842
1843 if (!name.empty()) {
1844 llvm::StringRef base = MSVCUndecoratedNameParser::DropScope(name);
1845 if (base.empty())
1846 base = name;
1847
1848 m_global_variable_base_names.Append(ConstString(base), gid);
1849 continue;
1850 }
1851
1852 if (kind != S_PROCREF && kind != S_LPROCREF)
1853 continue;
1854
1855 // For functions, we need to follow the reference to the procedure and look
1856 // at the type
1857
1858 ProcRefSym ref =
1859 llvm::cantFail(SymbolDeserializer::deserializeAs<ProcRefSym>(sym));
1860 if (ref.Name.empty())
1861 continue;
1862
1863 // Find the function this is referencing.
1864 CompilandIndexItem &cci =
1865 m_index->compilands().GetOrCreateCompiland(ref.modi());
1866 auto iter = cci.m_debug_stream.getSymbolArray().at(ref.SymOffset);
1867 if (iter == cci.m_debug_stream.getSymbolArray().end())
1868 continue;
1869 kind = iter->kind();
1870 if (kind != S_GPROC32 && kind != S_LPROC32)
1871 continue;
1872
1873 ProcSym proc =
1874 llvm::cantFail(SymbolDeserializer::deserializeAs<ProcSym>(*iter));
1875 if ((proc.Flags & ProcSymFlags::IsUnreachable) != ProcSymFlags::None)
1876 continue;
1877 if (proc.Name.empty() || proc.FunctionType.isSimple())
1878 continue;
1879
1880 // The function/procedure symbol only contains the demangled name.
1881 // The mangled names are in the publics table. Save the address of this
1882 // function to lookup the mangled name later.
1883 func_addr_ids.emplace(std::make_pair(proc.Segment, proc.CodeOffset), gid);
1884
1885 llvm::StringRef basename = MSVCUndecoratedNameParser::DropScope(proc.Name);
1886 if (basename.empty())
1887 basename = proc.Name;
1888
1889 m_func_base_names.Append(ConstString(basename), gid);
1890 m_func_full_names.Append(ConstString(proc.Name), gid);
1891
1892 // To see if this is a member function, check the type.
1893 auto type = m_index->tpi().getType(proc.FunctionType);
1894 if (type.kind() == LF_MFUNCTION) {
1895 MemberFunctionRecord mfr;
1896 llvm::cantFail(
1897 TypeDeserializer::deserializeAs<MemberFunctionRecord>(type, mfr));
1898 if (!mfr.getThisType().isNoneType())
1899 m_func_method_names.Append(ConstString(basename), gid);
1900 }
1901 }
1902
1903 // The publics stream contains all mangled function names and their address.
1904 for (auto pid : m_index->publics().getPublicsTable()) {
1905 PdbGlobalSymId global{pid, true};
1906 CVSymbol sym = m_index->ReadSymbolRecord(global);
1907 auto kind = sym.kind();
1908 if (kind != S_PUB32)
1909 continue;
1910 PublicSym32 pub =
1911 llvm::cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(sym));
1912 // We only care about mangled names - if the name isn't mangled, it's
1913 // already in the full name map.
1914 if (!Mangled::IsMangledName(pub.Name))
1915 continue;
1916
1917 // Check if this symbol is for one of our functions.
1918 auto it = func_addr_ids.find({pub.Segment, pub.Offset});
1919 if (it != func_addr_ids.end())
1920 m_func_full_names.Append(ConstString(pub.Name), it->second);
1921 }
1922
1923 // Sort them before value searching is working properly.
1924 m_func_full_names.Sort(std::less<uint32_t>());
1925 m_func_full_names.SizeToFit();
1926 m_func_method_names.Sort(std::less<uint32_t>());
1927 m_func_method_names.SizeToFit();
1928 m_func_base_names.Sort(std::less<uint32_t>());
1929 m_func_base_names.SizeToFit();
1930 m_global_variable_base_names.Sort(std::less<uint32_t>());
1931 m_global_variable_base_names.SizeToFit();
1932}
1933
1935 ConstString name, const CompilerDeclContext &parent_decl_ctx,
1936 uint32_t max_matches, VariableList &variables) {
1937 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1938
1940
1941 std::vector<uint32_t> results;
1942 m_global_variable_base_names.GetValues(name, results);
1943
1944 size_t n_matches = 0;
1945 for (uint32_t gid : results) {
1946 PdbGlobalSymId global(gid, false);
1947
1948 if (parent_decl_ctx.IsValid() &&
1949 GetDeclContextContainingUID(toOpaqueUid(global)) != parent_decl_ctx)
1950 continue;
1951
1953 if (!var)
1954 continue;
1955 variables.AddVariable(var);
1956
1957 if (++n_matches >= max_matches)
1958 break;
1959 }
1960}
1961
1963 const Module::LookupInfo &lookup_info,
1964 const CompilerDeclContext &parent_decl_ctx, bool include_inlines,
1965 SymbolContextList &sc_list) {
1966 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
1967 ConstString name = lookup_info.GetLookupName();
1968 FunctionNameType name_type_mask = lookup_info.GetNameTypeMask();
1969 if (name_type_mask & eFunctionNameTypeFull)
1970 name = lookup_info.GetName();
1971
1972 if (!(name_type_mask & eFunctionNameTypeFull ||
1973 name_type_mask & eFunctionNameTypeBase ||
1974 name_type_mask & eFunctionNameTypeMethod))
1975 return;
1977
1978 std::set<uint32_t> resolved_ids; // avoid duplicate lookups
1979 auto resolve_from = [&](UniqueCStringMap<uint32_t> &Names) {
1980 std::vector<uint32_t> ids;
1981 if (!Names.GetValues(name, ids))
1982 return;
1983
1984 for (uint32_t id : ids) {
1985 if (!resolved_ids.insert(id).second)
1986 continue;
1987
1988 PdbGlobalSymId global{id, false};
1989 if (parent_decl_ctx.IsValid() &&
1990 GetDeclContextContainingUID(toOpaqueUid(global)) != parent_decl_ctx)
1991 continue;
1992
1993 CVSymbol sym = m_index->ReadSymbolRecord(global);
1994 auto kind = sym.kind();
1995 lldbassert(kind == S_PROCREF || kind == S_LPROCREF);
1996
1997 ProcRefSym proc =
1998 cantFail(SymbolDeserializer::deserializeAs<ProcRefSym>(sym));
1999
2000 if (!IsValidRecord(proc))
2001 continue;
2002
2003 CompilandIndexItem &cci =
2004 m_index->compilands().GetOrCreateCompiland(proc.modi());
2005 SymbolContext sc;
2006
2007 sc.comp_unit = GetOrCreateCompileUnit(cci).get();
2008 if (!sc.comp_unit)
2009 continue;
2010
2011 PdbCompilandSymId func_id(proc.modi(), proc.SymOffset);
2012 sc.function = GetOrCreateFunction(func_id, *sc.comp_unit).get();
2013 if (!sc.function)
2014 continue;
2015
2016 sc_list.Append(sc);
2017 }
2018 };
2019
2020 if (name_type_mask & eFunctionNameTypeFull)
2021 resolve_from(m_func_full_names);
2022 if (name_type_mask & eFunctionNameTypeBase)
2023 resolve_from(m_func_base_names);
2024 if (name_type_mask & eFunctionNameTypeMethod)
2025 resolve_from(m_func_method_names);
2026}
2027
2029 bool include_inlines,
2030 SymbolContextList &sc_list) {}
2031
2033 lldb_private::TypeResults &results) {
2034
2035 // Make sure we haven't already searched this SymbolFile before.
2036 if (results.AlreadySearched(this))
2037 return;
2038
2039 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2040
2041 // We can't query for the full name because the type might reside
2042 // in an anonymous namespace. Search for the basename in our map and check the
2043 // matching types afterwards.
2044 std::vector<uint32_t> matches;
2045 m_type_base_names.GetValues(query.GetTypeBasename(), matches);
2046
2047 for (uint32_t match_idx : matches) {
2048 std::vector context = GetContextForType(TypeIndex(match_idx));
2049 if (context.empty())
2050 continue;
2051
2052 if (query.ContextMatches(context)) {
2053 TypeSP type_sp = GetOrCreateType(TypeIndex(match_idx));
2054 if (!type_sp)
2055 continue;
2056
2057 results.InsertUnique(type_sp);
2058 if (results.Done(query))
2059 return;
2060 }
2061 }
2062}
2063
2065 uint32_t max_matches,
2066 TypeMap &types) {
2067
2068 std::vector<TypeIndex> matches = m_index->tpi().findRecordsByName(name);
2069 if (max_matches > 0 && max_matches < matches.size())
2070 matches.resize(max_matches);
2071
2072 for (TypeIndex ti : matches) {
2073 TypeSP type = GetOrCreateType(ti);
2074 if (!type)
2075 continue;
2076
2077 types.Insert(type);
2078 }
2079}
2080
2082 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2083 // Only do the full type scan the first time.
2085 return 0;
2086
2087 const size_t old_count = GetTypeList().GetSize();
2088 LazyRandomTypeCollection &types = m_index->tpi().typeCollection();
2089
2090 // First process the entire TPI stream.
2091 for (auto ti = types.getFirst(); ti; ti = types.getNext(*ti)) {
2092 TypeSP type = GetOrCreateType(*ti);
2093 if (type)
2094 (void)type->GetFullCompilerType();
2095 }
2096
2097 // Next look for S_UDT records in the globals stream.
2098 for (const uint32_t gid : m_index->globals().getGlobalsTable()) {
2099 PdbGlobalSymId global{gid, false};
2100 CVSymbol sym = m_index->ReadSymbolRecord(global);
2101 if (sym.kind() != S_UDT)
2102 continue;
2103
2104 UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs<UDTSym>(sym));
2105 bool is_typedef = true;
2106 if (IsTagRecord(PdbTypeSymId{udt.Type, false}, m_index->tpi())) {
2107 CVType cvt = m_index->tpi().getType(udt.Type);
2108 llvm::StringRef name = CVTagRecord::create(cvt).name();
2109 if (name == udt.Name)
2110 is_typedef = false;
2111 }
2112
2113 if (is_typedef)
2114 GetOrCreateTypedef(global);
2115 }
2116
2117 const size_t new_count = GetTypeList().GetSize();
2118
2119 m_done_full_type_scan = true;
2120
2121 return new_count - old_count;
2122}
2123
2124size_t
2126 VariableList &variables) {
2127 PdbSymUid sym_uid(comp_unit.GetID());
2129 for (const uint32_t gid : m_index->globals().getGlobalsTable()) {
2130 PdbGlobalSymId global{gid, false};
2131 CVSymbol sym = m_index->ReadSymbolRecord(global);
2132 // TODO: S_CONSTANT is not handled here to prevent a possible crash in
2133 // lldb_private::npdb::MakeConstantLocationExpression when it's a record
2134 // type (e.g. std::strong_ordering::equal). That function needs to be
2135 // updated to handle this case when we add S_CONSTANT case here.
2136 switch (sym.kind()) {
2137 case SymbolKind::S_GDATA32:
2138 case SymbolKind::S_LDATA32:
2139 case SymbolKind::S_GTHREAD32:
2140 case SymbolKind::S_LTHREAD32: {
2141 if (VariableSP var = GetOrCreateGlobalVariable(global))
2142 variables.AddVariable(var);
2143 break;
2144 }
2145 default:
2146 break;
2147 }
2148 }
2149 return variables.GetSize();
2150}
2151
2153 PdbCompilandSymId var_id,
2154 bool is_param) {
2155 ModuleSP module = GetObjectFile()->GetModule();
2156 Block *block = GetOrCreateBlock(scope_id);
2157 if (!block)
2158 return nullptr;
2159
2160 // Get function block.
2161 Block *func_block = block;
2162 while (func_block->GetParent()) {
2163 func_block = func_block->GetParent();
2164 }
2165
2166 Address addr;
2167 func_block->GetStartAddress(addr);
2168 VariableInfo var_info =
2169 GetVariableLocationInfo(*m_index, var_id, *func_block, module);
2170 Function *func = func_block->CalculateSymbolContextFunction();
2171 if (!func)
2172 return nullptr;
2173 // Use empty dwarf expr if optimized away so that it won't be filtered out
2174 // when lookuping local variables in this scope.
2175 if (!var_info.location.IsValid())
2176 var_info.location = DWARFExpressionList(module, DWARFExpression(), nullptr);
2178 CompilandIndexItem *cii = m_index->compilands().GetCompiland(var_id.modi);
2179 CompUnitSP comp_unit_sp = GetOrCreateCompileUnit(*cii);
2180 TypeSP type_sp = GetOrCreateType(var_info.type);
2181 if (!type_sp)
2182 return nullptr;
2183 std::string name = var_info.name.str();
2184 Declaration decl;
2185 SymbolFileTypeSP sftype =
2186 std::make_shared<SymbolFileType>(*this, type_sp->GetID());
2187
2188 is_param |= var_info.is_param;
2189 ValueType var_scope =
2191 bool external = false;
2192 bool artificial = false;
2193 bool location_is_constant_data = false;
2194 bool static_member = false;
2195 Variable::RangeList scope_ranges;
2196 VariableSP var_sp = std::make_shared<Variable>(
2197 toOpaqueUid(var_id), name.c_str(), name.c_str(), sftype, var_scope, block,
2198 scope_ranges, &decl, var_info.location, external, artificial,
2199 location_is_constant_data, static_member);
2200 if (!is_param) {
2201 auto ts_or_err = GetTypeSystemForLanguage(comp_unit_sp->GetLanguage());
2202 if (auto err = ts_or_err.takeError())
2203 return nullptr;
2204 auto ts = *ts_or_err;
2205 if (!ts)
2206 return nullptr;
2207
2208 ts->GetNativePDBParser()->GetOrCreateVariableDecl(scope_id, var_id);
2209 }
2210 m_local_variables[toOpaqueUid(var_id)] = var_sp;
2211 return var_sp;
2212}
2213
2215 PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param) {
2216 auto iter = m_local_variables.find(toOpaqueUid(var_id));
2217 if (iter != m_local_variables.end())
2218 return iter->second;
2219
2220 return CreateLocalVariable(scope_id, var_id, is_param);
2221}
2222
2224 CVSymbol sym = m_index->ReadSymbolRecord(id);
2225 lldbassert(sym.kind() == SymbolKind::S_UDT);
2226
2227 UDTSym udt = llvm::cantFail(SymbolDeserializer::deserializeAs<UDTSym>(sym));
2228
2229 TypeSP target_type = GetOrCreateType(udt.Type);
2230
2232 if (auto err = ts_or_err.takeError())
2233 return nullptr;
2234 auto ts = *ts_or_err;
2235 if (!ts)
2236 return nullptr;
2237
2238 auto *typedef_decl = ts->GetNativePDBParser()->GetOrCreateTypedefDecl(id);
2239
2240 CompilerType ct = target_type->GetForwardCompilerType();
2241 if (auto *clang = llvm::dyn_cast_or_null<TypeSystemClang>(ts.get()))
2242 ct = clang->GetType(clang->getASTContext().getTypeDeclType(typedef_decl));
2243
2244 Declaration decl;
2245 return MakeType(toOpaqueUid(id), ConstString(udt.Name),
2246 llvm::expectedToOptional(target_type->GetByteSize(nullptr)),
2247 nullptr, target_type->GetID(),
2250}
2251
2253 auto iter = m_types.find(toOpaqueUid(id));
2254 if (iter != m_types.end())
2255 return iter->second;
2256
2257 return CreateTypedef(id);
2258}
2259
2261 Block *block = GetOrCreateBlock(block_id);
2262 if (!block)
2263 return 0;
2264
2265 size_t count = 0;
2266
2267 CompilandIndexItem *cii = m_index->compilands().GetCompiland(block_id.modi);
2268 CVSymbol sym = cii->m_debug_stream.readSymbolAtOffset(block_id.offset);
2269 uint32_t params_remaining = 0;
2270 switch (sym.kind()) {
2271 case S_GPROC32:
2272 case S_LPROC32: {
2273 ProcSym proc(static_cast<SymbolRecordKind>(sym.kind()));
2274 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym, proc));
2275 CVType signature = m_index->tpi().getType(proc.FunctionType);
2276 if (signature.kind() == LF_PROCEDURE) {
2277 ProcedureRecord sig;
2278 if (llvm::Error e = TypeDeserializer::deserializeAs<ProcedureRecord>(
2279 signature, sig)) {
2280 llvm::consumeError(std::move(e));
2281 return 0;
2282 }
2283 params_remaining = sig.getParameterCount();
2284 } else if (signature.kind() == LF_MFUNCTION) {
2285 MemberFunctionRecord sig;
2286 if (llvm::Error e = TypeDeserializer::deserializeAs<MemberFunctionRecord>(
2287 signature, sig)) {
2288 llvm::consumeError(std::move(e));
2289 return 0;
2290 }
2291 params_remaining = sig.getParameterCount();
2292 } else
2293 return 0;
2294 break;
2295 }
2296 case S_BLOCK32:
2297 break;
2298 case S_INLINESITE:
2299 break;
2300 default:
2301 lldbassert(false && "Symbol is not a block!");
2302 return 0;
2303 }
2304
2305 VariableListSP variables = block->GetBlockVariableList(false);
2306 if (!variables) {
2307 variables = std::make_shared<VariableList>();
2308 block->SetVariableList(variables);
2309 }
2310
2311 CVSymbolArray syms = limitSymbolArrayToScope(
2312 cii->m_debug_stream.getSymbolArray(), block_id.offset);
2313
2314 // Skip the first record since it's a PROC32 or BLOCK32, and there's
2315 // no point examining it since we know it's not a local variable.
2316 syms.drop_front();
2317 auto iter = syms.begin();
2318 auto end = syms.end();
2319
2320 while (iter != end) {
2321 uint32_t record_offset = iter.offset();
2322 CVSymbol variable_cvs = *iter;
2323 PdbCompilandSymId child_sym_id(block_id.modi, record_offset);
2324 ++iter;
2325
2326 // If this is a block or inline site, recurse into its children and then
2327 // skip it.
2328 if (variable_cvs.kind() == S_BLOCK32 ||
2329 variable_cvs.kind() == S_INLINESITE) {
2330 uint32_t block_end = getScopeEndOffset(variable_cvs);
2331 count += ParseVariablesForBlock(child_sym_id);
2332 iter = syms.at(block_end);
2333 continue;
2334 }
2335
2336 bool is_param = params_remaining > 0;
2337 VariableSP variable;
2338 switch (variable_cvs.kind()) {
2339 case S_REGREL32:
2340 case S_REGISTER:
2341 case S_LOCAL:
2342 variable = GetOrCreateLocalVariable(block_id, child_sym_id, is_param);
2343 if (is_param)
2344 --params_remaining;
2345 if (variable)
2346 variables->AddVariableIfUnique(variable);
2347 break;
2348 default:
2349 break;
2350 }
2351 }
2352
2353 // Pass false for set_children, since we call this recursively so that the
2354 // children will call this for themselves.
2355 block->SetDidParseVariables(true, false);
2356
2357 return count;
2358}
2359
2361 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2362 lldbassert(sc.function || sc.comp_unit);
2363
2364 VariableListSP variables;
2365 if (sc.block) {
2366 PdbSymUid block_id(sc.block->GetID());
2367
2368 size_t count = ParseVariablesForBlock(block_id.asCompilandSym());
2369 return count;
2370 }
2371
2372 if (sc.function) {
2373 PdbSymUid block_id(sc.function->GetID());
2374
2375 size_t count = ParseVariablesForBlock(block_id.asCompilandSym());
2376 return count;
2377 }
2378
2379 if (sc.comp_unit) {
2380 variables = sc.comp_unit->GetVariableList(false);
2381 if (!variables) {
2382 variables = std::make_shared<VariableList>();
2383 sc.comp_unit->SetVariableList(variables);
2384 }
2385 return ParseVariablesForCompileUnit(*sc.comp_unit, *variables);
2386 }
2387
2388 llvm_unreachable("Unreachable!");
2389}
2390
2393 if (auto err = ts_or_err.takeError())
2394 return CompilerDecl();
2395 auto ts = *ts_or_err;
2396 if (!ts)
2397 return {};
2398
2399 if (auto decl = ts->GetNativePDBParser()->GetOrCreateDeclForUid(uid))
2400 return *decl;
2401 return CompilerDecl();
2402}
2403
2407 if (auto err = ts_or_err.takeError())
2408 return {};
2409 auto ts = *ts_or_err;
2410 if (!ts)
2411 return {};
2412
2413 PdbAstBuilder *ast_builder = ts->GetNativePDBParser();
2414 clang::DeclContext *context =
2415 ast_builder->GetOrCreateDeclContextForUid(PdbSymUid(uid));
2416 if (!context)
2417 return {};
2418
2419 return ast_builder->ToCompilerDeclContext(*context);
2420}
2421
2425 if (auto err = ts_or_err.takeError())
2426 return CompilerDeclContext();
2427 auto ts = *ts_or_err;
2428 if (!ts)
2429 return {};
2430
2431 PdbAstBuilder *ast_builder = ts->GetNativePDBParser();
2432 clang::DeclContext *context = ast_builder->GetParentDeclContext(PdbSymUid(uid));
2433 if (!context)
2434 return CompilerDeclContext();
2435 return ast_builder->ToCompilerDeclContext(*context);
2436}
2437
2439 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2440 auto iter = m_types.find(type_uid);
2441 // lldb should not be passing us non-sensical type uids. the only way it
2442 // could have a type uid in the first place is if we handed it out, in which
2443 // case we should know about the type. However, that doesn't mean we've
2444 // instantiated it yet. We can vend out a UID for a future type. So if the
2445 // type doesn't exist, let's instantiate it now.
2446 if (iter != m_types.end())
2447 return &*iter->second;
2448
2449 PdbSymUid uid(type_uid);
2451 PdbTypeSymId type_id = uid.asTypeSym();
2452 if (type_id.index.isNoneType())
2453 return nullptr;
2454
2455 TypeSP type_sp = CreateAndCacheType(type_id);
2456 if (!type_sp)
2457 return nullptr;
2458 return &*type_sp;
2459}
2460
2461std::optional<SymbolFile::ArrayInfo>
2463 lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) {
2464 return std::nullopt;
2465}
2466
2468 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2469 auto clang_type_system = compiler_type.GetTypeSystem<TypeSystemClang>();
2470 if (!clang_type_system)
2471 return false;
2472
2473 PdbAstBuilder *ast_builder =
2474 static_cast<PdbAstBuilder *>(clang_type_system->GetNativePDBParser());
2475 if (ast_builder &&
2476 ast_builder->GetClangASTImporter().CanImport(compiler_type))
2477 return ast_builder->GetClangASTImporter().CompleteType(compiler_type);
2478 clang::QualType qt =
2479 clang::QualType::getFromOpaquePtr(compiler_type.GetOpaqueQualType());
2480
2481 return ast_builder->CompleteType(qt);
2482}
2483
2485 TypeClass type_mask,
2486 lldb_private::TypeList &type_list) {}
2487
2490 const CompilerDeclContext &parent_decl_ctx,
2491 bool /* only_root_namespaces */) {
2492 std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
2494 if (auto err = ts_or_err.takeError())
2495 return {};
2496 auto ts = *ts_or_err;
2497 if (!ts)
2498 return {};
2499 auto *clang = llvm::dyn_cast_or_null<TypeSystemClang>(ts.get());
2500 if (!clang)
2501 return {};
2502
2503 PdbAstBuilder *ast_builder = clang->GetNativePDBParser();
2504 if (!ast_builder)
2505 return {};
2506
2507 clang::DeclContext *decl_context = nullptr;
2508 if (parent_decl_ctx)
2509 decl_context = static_cast<clang::DeclContext *>(
2510 parent_decl_ctx.GetOpaqueDeclContext());
2511
2512 auto *namespace_decl =
2513 ast_builder->FindNamespaceDecl(decl_context, name.GetStringRef());
2514 if (!namespace_decl)
2515 return CompilerDeclContext();
2516
2517 return clang->CreateDeclContext(namespace_decl);
2518}
2519
2520llvm::Expected<lldb::TypeSystemSP>
2522 auto type_system_or_err =
2523 m_objfile_sp->GetModule()->GetTypeSystemForLanguage(language);
2524 if (type_system_or_err)
2525 if (auto ts = *type_system_or_err)
2526 ts->SetSymbolFile(this);
2527 return type_system_or_err;
2528}
2529
2530uint64_t SymbolFileNativePDB::GetDebugInfoSize(bool load_all_debug_info) {
2531 // PDB files are a separate file that contains all debug info.
2532 return m_index->pdb().getFileSize();
2533}
2534
2536 LazyRandomTypeCollection &types = m_index->tpi().typeCollection();
2537
2538 llvm::DenseMap<TypeIndex, TypeIndex> forward_to_full;
2539 llvm::DenseMap<TypeIndex, TypeIndex> full_to_forward;
2540
2541 struct RecordIndices {
2542 TypeIndex forward;
2543 TypeIndex full;
2544 };
2545
2546 llvm::StringMap<RecordIndices> record_indices;
2547
2548 for (auto ti = types.getFirst(); ti; ti = types.getNext(*ti)) {
2549 CVType type = types.getType(*ti);
2550 if (!IsTagRecord(type))
2551 continue;
2552
2553 CVTagRecord tag = CVTagRecord::create(type);
2554
2555 RecordIndices &indices = record_indices[tag.asTag().getUniqueName()];
2556 if (tag.asTag().isForwardRef()) {
2557 indices.forward = *ti;
2558 } else {
2559 indices.full = *ti;
2560
2561 auto base_name = MSVCUndecoratedNameParser::DropScope(tag.name());
2562 m_type_base_names.Append(ConstString(base_name), ti->getIndex());
2563 }
2564
2565 if (indices.full != TypeIndex::None() &&
2566 indices.forward != TypeIndex::None()) {
2567 forward_to_full[indices.forward] = indices.full;
2568 full_to_forward[indices.full] = indices.forward;
2569 }
2570
2571 // We're looking for LF_NESTTYPE records in the field list, so ignore
2572 // forward references (no field list), and anything without a nested class
2573 // (since there won't be any LF_NESTTYPE records).
2574 if (tag.asTag().isForwardRef() || !tag.asTag().containsNestedClass())
2575 continue;
2576
2577 struct ProcessTpiStream : public TypeVisitorCallbacks {
2578 ProcessTpiStream(PdbIndex &index, TypeIndex parent,
2579 const CVTagRecord &parent_cvt,
2580 llvm::DenseMap<TypeIndex, TypeIndex> &parents)
2581 : index(index), parents(parents), parent(parent),
2582 parent_cvt(parent_cvt) {}
2583
2584 PdbIndex &index;
2585 llvm::DenseMap<TypeIndex, TypeIndex> &parents;
2586
2587 unsigned unnamed_type_index = 1;
2588 TypeIndex parent;
2589 const CVTagRecord &parent_cvt;
2590
2591 llvm::Error visitKnownMember(CVMemberRecord &CVR,
2592 NestedTypeRecord &Record) override {
2593 std::string unnamed_type_name;
2594 if (Record.Name.empty()) {
2595 unnamed_type_name =
2596 llvm::formatv("<unnamed-type-$S{0}>", unnamed_type_index).str();
2597 Record.Name = unnamed_type_name;
2598 ++unnamed_type_index;
2599 }
2600 std::optional<CVTagRecord> tag =
2601 GetNestedTagDefinition(Record, parent_cvt, index.tpi());
2602 if (!tag)
2603 return llvm::ErrorSuccess();
2604
2605 parents[Record.Type] = parent;
2606 return llvm::ErrorSuccess();
2607 }
2608 };
2609
2610 CVType field_list_cvt = m_index->tpi().getType(tag.asTag().FieldList);
2611 ProcessTpiStream process(*m_index, *ti, tag, m_parent_types);
2612 FieldListRecord field_list;
2613 if (llvm::Error error = TypeDeserializer::deserializeAs<FieldListRecord>(
2614 field_list_cvt, field_list))
2615 llvm::consumeError(std::move(error));
2616 if (llvm::Error error = visitMemberRecordStream(field_list.Data, process))
2617 llvm::consumeError(std::move(error));
2618 }
2619
2620 // After calling Append(), the type-name map needs to be sorted again to be
2621 // able to look up a type by its name.
2622 m_type_base_names.Sort(std::less<uint32_t>());
2623
2624 // Now that we know the forward -> full mapping of all type indices, we can
2625 // re-write all the indices. At the end of this process, we want a mapping
2626 // consisting of fwd -> full and full -> full for all child -> parent indices.
2627 // We can re-write the values in place, but for the keys, we must save them
2628 // off so that we don't modify the map in place while also iterating it.
2629 std::vector<TypeIndex> full_keys;
2630 std::vector<TypeIndex> fwd_keys;
2631 for (auto &entry : m_parent_types) {
2632 TypeIndex key = entry.first;
2633 TypeIndex value = entry.second;
2634
2635 auto iter = forward_to_full.find(value);
2636 if (iter != forward_to_full.end())
2637 entry.second = iter->second;
2638
2639 iter = forward_to_full.find(key);
2640 if (iter != forward_to_full.end())
2641 fwd_keys.push_back(key);
2642 else
2643 full_keys.push_back(key);
2644 }
2645 for (TypeIndex fwd : fwd_keys) {
2646 TypeIndex full = forward_to_full[fwd];
2647 TypeIndex parent_idx = m_parent_types[fwd];
2648 m_parent_types[full] = parent_idx;
2649 }
2650 for (TypeIndex full : full_keys) {
2651 TypeIndex fwd = full_to_forward[full];
2652 m_parent_types[fwd] = m_parent_types[full];
2653 }
2654}
2655
2656std::optional<PdbCompilandSymId>
2658 CVSymbol sym = m_index->ReadSymbolRecord(id);
2659 if (symbolOpensScope(sym.kind())) {
2660 // If this exact symbol opens a scope, we can just directly access its
2661 // parent.
2662 id.offset = getScopeParentOffset(sym);
2663 // Global symbols have parent offset of 0. Return std::nullopt to indicate
2664 // this.
2665 if (id.offset == 0)
2666 return std::nullopt;
2667 return id;
2668 }
2669
2670 // Otherwise we need to start at the beginning and iterate forward until we
2671 // reach (or pass) this particular symbol
2672 CompilandIndexItem &cii = m_index->compilands().GetOrCreateCompiland(id.modi);
2673 const CVSymbolArray &syms = cii.m_debug_stream.getSymbolArray();
2674
2675 auto begin = syms.begin();
2676 auto end = syms.at(id.offset);
2677 std::vector<PdbCompilandSymId> scope_stack;
2678
2679 while (begin != end) {
2680 if (begin.offset() > id.offset) {
2681 // We passed it. We couldn't even find this symbol record.
2682 lldbassert(false && "Invalid compiland symbol id!");
2683 return std::nullopt;
2684 }
2685
2686 // We haven't found the symbol yet. Check if we need to open or close the
2687 // scope stack.
2688 if (symbolOpensScope(begin->kind())) {
2689 // We can use the end offset of the scope to determine whether or not
2690 // we can just outright skip this entire scope.
2691 uint32_t scope_end = getScopeEndOffset(*begin);
2692 if (scope_end < id.offset) {
2693 begin = syms.at(scope_end);
2694 } else {
2695 // The symbol we're looking for is somewhere in this scope.
2696 scope_stack.emplace_back(id.modi, begin.offset());
2697 }
2698 } else if (symbolEndsScope(begin->kind())) {
2699 scope_stack.pop_back();
2700 }
2701 ++begin;
2702 }
2703 if (scope_stack.empty())
2704 return std::nullopt;
2705 // We have a match! Return the top of the stack
2706 return scope_stack.back();
2707}
2708
2709std::optional<llvm::codeview::TypeIndex>
2710SymbolFileNativePDB::GetParentType(llvm::codeview::TypeIndex ti) {
2711 auto parent_iter = m_parent_types.find(ti);
2712 if (parent_iter == m_parent_types.end())
2713 return std::nullopt;
2714 return parent_iter->second;
2715}
2716
2717std::vector<CompilerContext>
2719 CVType type = m_index->tpi().getType(ti);
2720 if (!IsTagRecord(type))
2721 return {};
2722
2723 CVTagRecord tag = CVTagRecord::create(type);
2724
2725 std::optional<Type::ParsedName> parsed_name =
2727 if (!parsed_name)
2728 return {{tag.contextKind(), ConstString(tag.name())}};
2729
2730 std::vector<CompilerContext> ctx;
2731 // assume everything is a namespace at first
2732 for (llvm::StringRef scope : parsed_name->scope) {
2733 ctx.emplace_back(CompilerContextKind::Namespace, ConstString(scope));
2734 }
2735 // we know the kind of our own type
2736 ctx.emplace_back(tag.contextKind(), ConstString(parsed_name->basename));
2737
2738 // try to find the kind of parents
2739 for (auto &el : llvm::reverse(llvm::drop_end(ctx))) {
2740 std::optional<TypeIndex> parent = GetParentType(ti);
2741 if (!parent)
2742 break;
2743
2744 ti = *parent;
2745 type = m_index->tpi().getType(ti);
2746 switch (type.kind()) {
2747 case LF_CLASS:
2748 case LF_STRUCTURE:
2749 case LF_INTERFACE:
2751 continue;
2752 case LF_UNION:
2754 continue;
2755 case LF_ENUM:
2756 el.kind = CompilerContextKind::Enum;
2757 continue;
2758 default:
2759 break;
2760 }
2761 break;
2762 }
2763 return ctx;
2764}
2765
2766std::optional<llvm::StringRef>
2768 const CompilandIndexItem *cci =
2769 m_index->compilands().GetCompiland(func_id.modi);
2770 if (!cci)
2771 return std::nullopt;
2772
2773 CVSymbol sym_record = cci->m_debug_stream.readSymbolAtOffset(func_id.offset);
2774 if (sym_record.kind() != S_LPROC32 && sym_record.kind() != S_GPROC32)
2775 return std::nullopt;
2776
2777 ProcSym proc(static_cast<SymbolRecordKind>(sym_record.kind()));
2778 cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc));
2779
2780 return FindMangledSymbol(SegmentOffset(proc.Segment, proc.CodeOffset),
2781 proc.FunctionType);
2782}
2783
2784std::optional<llvm::StringRef>
2786 TypeIndex function_type) {
2787 auto symbol = m_index->publics().findByAddress(m_index->symrecords(),
2788 so.segment, so.offset);
2789 if (!symbol)
2790 return std::nullopt;
2791
2792 llvm::StringRef name = symbol->first.Name;
2793 // For functions, we might need to strip the mangled name. See
2794 // StripMangledFunctionName for more info.
2795 if (!function_type.isNoneType() &&
2796 (symbol->first.Flags & PublicSymFlags::Function) != PublicSymFlags::None)
2797 name = StripMangledFunctionName(name, function_type);
2798
2799 return name;
2800}
2801
2802llvm::StringRef
2804 PdbTypeSymId func_ty) {
2805 // "In non-64 bit environments" (on x86 in pactice), __cdecl functions get
2806 // prefixed with an underscore. For compilers using LLVM, this happens in LLVM
2807 // (as opposed to the compiler frontend). Because of this, DWARF doesn't
2808 // contain the "full" mangled name in DW_AT_linkage_name for these functions.
2809 // We strip the mangling here for compatibility with DWARF. See
2810 // llvm.org/pr161676 and
2811 // https://learn.microsoft.com/en-us/cpp/build/reference/decorated-names#FormatC
2812
2813 if (!mangled.starts_with('_') ||
2814 m_index->dbi().getMachineType() != PDB_Machine::x86)
2815 return mangled;
2816
2817 CVType cvt = m_index->tpi().getType(func_ty.index);
2818 PDB_CallingConv cc = PDB_CallingConv::NearC;
2819 if (cvt.kind() == LF_PROCEDURE) {
2820 ProcedureRecord proc;
2821 if (llvm::Error error =
2822 TypeDeserializer::deserializeAs<ProcedureRecord>(cvt, proc))
2823 llvm::consumeError(std::move(error));
2824 cc = proc.CallConv;
2825 } else if (cvt.kind() == LF_MFUNCTION) {
2826 MemberFunctionRecord mfunc;
2827 if (llvm::Error error =
2828 TypeDeserializer::deserializeAs<MemberFunctionRecord>(cvt, mfunc))
2829 llvm::consumeError(std::move(error));
2830 cc = mfunc.CallConv;
2831 } else {
2832 LLDB_LOG(GetLog(LLDBLog::Symbols), "Unexpected function type, got {0}",
2833 cvt.kind());
2834 return mangled;
2835 }
2836
2837 if (cc == PDB_CallingConv::NearC || cc == PDB_CallingConv::FarC)
2838 return mangled.drop_front();
2839
2840 return mangled;
2841}
2842
2844 for (CVType cvt : m_index->ipi().typeArray()) {
2845 switch (cvt.kind()) {
2846 case LF_UDT_SRC_LINE: {
2847 UdtSourceLineRecord udt_src;
2848 llvm::cantFail(TypeDeserializer::deserializeAs(cvt, udt_src));
2849 m_udt_declarations.try_emplace(
2850 udt_src.UDT, UdtDeclaration{/*FileNameIndex=*/udt_src.SourceFile,
2851 /*IsIpiIndex=*/true,
2852 /*Line=*/udt_src.LineNumber});
2853 } break;
2854 case LF_UDT_MOD_SRC_LINE: {
2855 UdtModSourceLineRecord udt_mod_src;
2856 llvm::cantFail(TypeDeserializer::deserializeAs(cvt, udt_mod_src));
2857 // Some types might be contributed by multiple modules. We assume that
2858 // they all point to the same file and line because we can only provide
2859 // one location.
2860 m_udt_declarations.try_emplace(
2861 udt_mod_src.UDT,
2862 UdtDeclaration{/*FileNameIndex=*/udt_mod_src.SourceFile,
2863 /*IsIpiIndex=*/false,
2864 /*Line=*/udt_mod_src.LineNumber});
2865 } break;
2866 default:
2867 break;
2868 }
2869 }
2870}
2871
2872llvm::Expected<Declaration>
2874 std::call_once(m_cached_udt_declarations, [this] { CacheUdtDeclarations(); });
2875
2876 auto it = m_udt_declarations.find(type_id.index);
2877 if (it == m_udt_declarations.end())
2878 return llvm::createStringError("No UDT declaration found");
2879
2880 llvm::StringRef file_name;
2881 if (it->second.IsIpiIndex) {
2882 CVType cvt = m_index->ipi().getType(it->second.FileNameIndex);
2883 if (cvt.kind() != LF_STRING_ID)
2884 return llvm::createStringError("File name was not a LF_STRING_ID");
2885
2886 StringIdRecord sid;
2887 llvm::cantFail(TypeDeserializer::deserializeAs(cvt, sid));
2888 file_name = sid.String;
2889 } else {
2890 // The file name index is an index into the string table
2891 auto string_table = m_index->pdb().getStringTable();
2892 if (!string_table)
2893 return string_table.takeError();
2894
2895 llvm::Expected<llvm::StringRef> string =
2896 string_table->getStringTable().getString(
2897 it->second.FileNameIndex.getIndex());
2898 if (!string)
2899 return string.takeError();
2900 file_name = *string;
2901 }
2902
2903 // rustc sets the filename to "<unknown>" for some files
2904 if (file_name == "\\<unknown>")
2905 return Declaration();
2906
2907 return Declaration(FileSpec(file_name), it->second.Line);
2908}
static llvm::raw_ostream & error(Stream &strm)
#define lldbassert(x)
Definition LLDBAssert.h:16
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:369
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
static std::unique_ptr< PDBFile > loadMatchingPDBFile(std::string exe_path, llvm::BumpPtrAllocator &allocator)
static std::optional< CVTagRecord > GetNestedTagDefinition(const NestedTypeRecord &Record, const CVTagRecord &parent, TpiStream &tpi)
static lldb::LanguageType TranslateLanguage(PDB_Lang lang)
static std::string GetUnqualifiedTypeName(const TagRecord &record)
static llvm::StringRef GetSimpleTypeName(SimpleTypeKind kind)
static bool IsClassRecord(TypeLeafKind kind)
static bool IsFunctionEpilogue(const CompilandIndexItem &cci, lldb::addr_t addr)
static bool NeedsResolvedCompileUnit(uint32_t resolve_scope)
static bool IsFunctionPrologue(const CompilandIndexItem &cci, lldb::addr_t addr)
static llvm::StringRef DropScope(llvm::StringRef name)
static bool UseNativePDB()
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:281
bool IsValid() const
Check if the object state is valid.
Definition Address.h:355
A class that describes a single lexical block.
Definition Block.h:41
RangeList::Entry Range
Definition Block.h:44
lldb::VariableListSP GetBlockVariableList(bool can_create)
Get the variable list for this block only.
Definition Block.cpp:392
Block * FindInnermostBlockByOffset(const lldb::addr_t offset)
Definition Block.cpp:127
void SetBlockInfoHasBeenParsed(bool b, bool set_children)
Definition Block.cpp:479
lldb::BlockSP CreateChild(lldb::user_id_t uid)
Creates a block with the specified UID uid.
Definition Block.cpp:380
Function * CalculateSymbolContextFunction() override
Definition Block.cpp:150
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
Definition Block.h:319
Block * GetParent() const
Get the parent block.
Definition Block.cpp:202
bool GetStartAddress(Address &addr)
Definition Block.cpp:317
void SetDidParseVariables(bool b, bool set_children)
Definition Block.cpp:489
bool CanImport(const CompilerType &type)
Returns true iff the given type was copied from another TypeSystemClang and the original type in this...
bool CompleteType(const CompilerType &compiler_type)
A class that describes a compilation unit.
Definition CompileUnit.h:43
void SetVariableList(lldb::VariableListSP &variable_list_sp)
Set accessor for the variable list.
lldb::VariableListSP GetVariableList(bool can_create)
Get the variable list for a compile unit.
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
void ResolveSymbolContext(const SourceLocationSpec &src_location_spec, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list, RealpathPrefixes *realpath_prefixes=nullptr)
Resolve symbol contexts by file and line.
void SetLineTable(LineTable *line_table)
Set the line table for the compile unit.
void AddFunction(lldb::FunctionSP &function_sp)
Add a function to this compile unit.
size_t GetNumFunctions() const
Returns the number of functions in this compile unit.
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.
Generic representation of a type in a programming language.
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
lldb::opaque_compiler_type_t GetOpaqueQualType() const
A uniqued constant string class.
Definition ConstString.h:40
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
bool IsValid() const
Return true if the location expression contains data.
void SetFuncFileAddress(lldb::addr_t func_file_addr)
"lldb/Expression/DWARFExpression.h" Encapsulates a DWARF location expression and interprets it.
A class to manage flag bits.
Definition Debugger.h:80
A class that describes the declaration location of a lldb object.
Definition Declaration.h:24
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file utility class.
Definition FileSpec.h:57
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
Definition FileSpec.cpp:301
const ConstString & GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:251
FileSpec CopyByRemovingLastPathComponent() const
Definition FileSpec.cpp:431
llvm::sys::path::Style Style
Definition FileSpec.h:59
static FileSystem & Instance()
A class that describes a function.
Definition Function.h:400
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:453
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition Function.cpp:382
static void AppendLineEntryToSequence(Sequence &sequence, lldb::addr_t file_addr, uint32_t line, uint16_t column, uint16_t file_idx, bool is_start_of_statement, bool is_start_of_basic_block, bool is_prologue_end, bool is_epilogue_begin, bool is_terminal_entry)
Definition LineTable.cpp:59
A class that handles mangled names.
Definition Mangled.h:34
static bool IsMangledName(llvm::StringRef name)
Definition Mangled.cpp:39
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
A class that encapsulates name lookup information.
Definition Module.h:916
lldb::FunctionNameType GetNameTypeMask() const
Definition Module.h:931
ConstString GetLookupName() const
Definition Module.h:927
ConstString GetName() const
Definition Module.h:923
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)
RangeData< lldb::addr_t, uint32_t, std::pair< uint32_t, uint32_t > > Entry
Definition RangeMap.h:462
void Append(const Entry &entry)
Definition RangeMap.h:470
Entry * FindEntryThatContains(B addr)
Definition RangeMap.h:579
"lldb/Core/SourceLocationSpec.h" A source location specifier class.
A stream class that can stream formatted output to a file.
Definition Stream.h:28
A list of support files for a CompileUnit.
const FileSpec & GetFileSpecAtIndex(size_t idx) const
void Append(const FileSpec &file)
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.
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.
lldb::CompUnitSP GetCompileUnitAtIndex(uint32_t idx) override
ObjectFile * GetObjectFile() override
Definition SymbolFile.h:566
virtual TypeList & GetTypeList()
Definition SymbolFile.h:639
lldb::ObjectFileSP m_objfile_sp
Definition SymbolFile.h:642
void SetCompileUnitAtIndex(uint32_t idx, const lldb::CompUnitSP &cu_sp)
SymbolFileCommon(lldb::ObjectFileSP objfile_sp)
Definition SymbolFile.h:551
uint32_t GetNumCompileUnits() override
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:610
virtual std::recursive_mutex & GetModuleMutex() const
Symbols file subclasses should override this to return the Module that owns the TypeSystem that this ...
void SetByteSize(lldb::addr_t size)
Definition Symbol.h:213
Symbol * SymbolAtIndex(size_t idx)
Definition Symtab.cpp:228
uint32_t AddSymbol(const Symbol &symbol)
Definition Symtab.cpp:64
uint32_t GetSize() const
Definition TypeList.cpp:60
void Insert(const lldb::TypeSP &type)
Definition TypeList.cpp:27
void Insert(const lldb::TypeSP &type)
Definition TypeMap.cpp:27
A class that contains all state required for type lookups.
Definition Type.h:104
ConstString GetTypeBasename() const
Get the type basename to use when searching the type indexes in each SymbolFile object.
Definition Type.cpp:113
bool ContextMatches(llvm::ArrayRef< lldb_private::CompilerContext > context) const
Check of a CompilerContext array from matching type from a symbol file matches the m_context.
Definition Type.cpp:129
This class tracks the state and results of a TypeQuery.
Definition Type.h:344
bool InsertUnique(const lldb::TypeSP &type_sp)
When types that match a TypeQuery are found, this API is used to insert the matching types.
Definition Type.cpp:194
bool Done(const TypeQuery &query) const
Check if the type matching has found all of the matches that it needs.
Definition Type.cpp:200
bool AlreadySearched(lldb_private::SymbolFile *sym_file)
Check if a SymbolFile object has already been searched by this type match object.
Definition Type.cpp:190
A TypeSystem implementation based on Clang.
Interface for representing a type system.
Definition TypeSystem.h:70
virtual npdb::PdbAstBuilder * GetNativePDBParser()
Definition TypeSystem.h:92
@ eEncodingIsTypedefUID
This type is alias to a type whose UID is m_encoding_uid.
Definition Type.h:434
@ eEncodingIsUID
This type is the type whose UID is m_encoding_uid.
Definition Type.h:423
static std::optional< ParsedName > GetTypeScopeAndBasename(llvm::StringRef name)
Definition Type.cpp:792
void AddVariable(const lldb::VariableSP &var_sp)
RangeVector< lldb::addr_t, lldb::addr_t > RangeList
Definition Variable.h:27
ClangASTImporter & GetClangASTImporter()
clang::DeclContext * GetParentDeclContext(PdbSymUid uid)
CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context)
clang::DeclContext * FromCompilerDeclContext(CompilerDeclContext context)
CompilerType ToCompilerType(clang::QualType qt)
clang::NamespaceDecl * FindNamespaceDecl(const clang::DeclContext *parent, llvm::StringRef name)
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
PdbCompilandSymId asCompilandSym() const
PdbTypeSymId asTypeSym() const
PdbSymUidKind kind() const
void CreateSimpleArgumentListTypes(llvm::codeview::TypeIndex arglist_ti)
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.
void CacheGlobalBaseNames()
Caches the basenames of symbols found in the globals stream.
llvm::Expected< Declaration > ResolveUdtDeclaration(PdbTypeSymId type_id)
lldb::VariableSP CreateGlobalVariable(PdbGlobalSymId var_id)
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
void InitializeObject() override
Initialize the SymbolFile object.
lldb_private::UniqueCStringMap< uint32_t > m_func_base_names
basename -> Global ID(s)
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
void DumpClangAST(Stream &s, llvm::StringRef filter, bool show_color) override
lldb::VariableSP GetOrCreateLocalVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param)
size_t ParseVariablesForContext(const SymbolContext &sc) override
size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override
lldb::TypeSP CreatePointerType(PdbTypeSymId type_id, const llvm::codeview::PointerRecord &pr, CompilerType ct)
lldb::FunctionSP CreateFunction(PdbCompilandSymId func_id, CompileUnit &comp_unit)
llvm::DenseMap< lldb::user_id_t, lldb::BlockSP > m_blocks
bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, SupportFileList &support_files) override
CompilerDecl GetDeclForUID(lldb::user_id_t uid) override
std::optional< llvm::StringRef > FindMangledFunctionName(PdbCompilandSymId id)
Find the mangled name for a function.
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)
lldb_private::UniqueCStringMap< uint32_t > m_func_method_names
method basename -> Global ID(s)
std::optional< llvm::codeview::TypeIndex > GetParentType(llvm::codeview::TypeIndex ti)
lldb_private::UniqueCStringMap< uint32_t > m_global_variable_base_names
global variable basename -> Global ID(s)
void FindFunctions(const Module::LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, bool include_inlines, SymbolContextList &sc_list) override
std::unique_ptr< llvm::pdb::PDBFile > m_file_up
lldb::VariableSP CreateLocalVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param)
lldb::TypeSP CreateProcedureType(PdbTypeSymId type_id, const llvm::codeview::ProcedureRecord &pr, CompilerType ct)
lldb::TypeSP CreateModifierType(PdbTypeSymId type_id, const llvm::codeview::ModifierRecord &mr, CompilerType ct)
uint64_t GetDebugInfoSize(bool load_all_debug_info=false) override
Metrics gathering functions.
std::optional< llvm::StringRef > FindMangledSymbol(SegmentOffset so, llvm::codeview::TypeIndex function_type=llvm::codeview::TypeIndex())
Find a symbol name at a specific address (so).
size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override
Block * GetOrCreateBlock(PdbCompilandSymId block_id)
size_t ParseBlocksRecursive(Function &func) override
lldb::CompUnitSP CreateCompileUnit(const CompilandIndexItem &cci)
std::optional< PdbCompilandSymId > FindSymbolScope(PdbCompilandSymId id)
size_t ParseSymbolArrayInScope(PdbCompilandSymId parent, llvm::function_ref< bool(llvm::codeview::SymbolKind, PdbCompilandSymId)> fn)
size_t ParseVariablesForCompileUnit(CompileUnit &comp_unit, VariableList &variables)
llvm::DenseMap< lldb::user_id_t, lldb::CompUnitSP > m_compilands
Block * CreateBlock(PdbCompilandSymId block_id)
std::vector< CompilerContext > GetContextForType(llvm::codeview::TypeIndex ti)
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
llvm::StringRef StripMangledFunctionName(llvm::StringRef mangled, PdbTypeSymId func_ty)
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
size_t ParseVariablesForBlock(PdbCompilandSymId block_id)
void ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override
lldb::FunctionSP GetOrCreateFunction(PdbCompilandSymId func_id, CompileUnit &comp_unit)
llvm::DenseMap< llvm::codeview::TypeIndex, llvm::codeview::TypeIndex > m_parent_types
lldb_private::UniqueCStringMap< uint32_t > m_func_full_names
mangled name/full function name -> Global ID(s)
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
lldb::TypeSP CreateFunctionType(PdbTypeSymId type_id, const llvm::codeview::MemberFunctionRecord &pr, CompilerType ct)
lldb_private::UniqueCStringMap< uint32_t > m_type_base_names
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)
llvm::DenseMap< llvm::codeview::TypeIndex, UdtDeclaration > m_udt_declarations
void FindTypes(const lldb_private::TypeQuery &match, lldb_private::TypeResults &results) override
Find types using a type-matching object that contains all search parameters.
uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc) override
llvm::DenseMap< lldb::user_id_t, lldb::VariableSP > m_global_vars
lldb::TypeSP CreateSimpleType(llvm::codeview::TypeIndex ti, CompilerType ct)
#define LLDB_INVALID_UID
#define LLDB_INVALID_ADDRESS
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:129
DWARFExpression MakeGlobalLocationExpression(uint16_t section, uint32_t offset, lldb::ModuleSP module)
VariableInfo GetVariableLocationInfo(PdbIndex &index, PdbCompilandSymId var_id, Block &func_block, lldb::ModuleSP module)
Definition PdbUtil.cpp:734
bool IsForwardRefUdt(llvm::codeview::CVType cvt)
llvm::pdb::PDB_SymType CVSymToPDBSym(llvm::codeview::SymbolKind kind)
DWARFExpression MakeConstantLocationExpression(llvm::codeview::TypeIndex underlying_ti, llvm::pdb::TpiStream &tpi, const llvm::APSInt &constant, lldb::ModuleSP module)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
std::shared_ptr< lldb_private::Function > FunctionSP
std::shared_ptr< lldb_private::Block > BlockSP
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
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
SymbolType
Symbol types.
std::shared_ptr< lldb_private::VariableList > VariableListSP
std::shared_ptr< lldb_private::SymbolFileType > SymbolFileTypeSP
std::shared_ptr< lldb_private::Variable > VariableSP
uint64_t user_id_t
Definition lldb-types.h:82
std::shared_ptr< lldb_private::Section > SectionSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
@ eValueTypeVariableGlobal
globals variable
@ eValueTypeVariableLocal
function local variables
@ eValueTypeVariableArgument
function argument variables
@ eValueTypeVariableStatic
static variable
@ eValueTypeVariableThreadLocal
thread local storage variable
BaseType GetRangeBase() const
Definition RangeMap.h:45
void SetRangeEnd(BaseType end)
Definition RangeMap.h:80
void SetRangeBase(BaseType b)
Set the start value for the range, and keep the same size.
Definition RangeMap.h:48
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47
CompilerContextKind contextKind() const
Definition PdbUtil.h:75
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:115
llvm::codeview::TypeIndex type
Definition PdbUtil.h:114