[Go to site: main page, start]

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