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