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