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