Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
CodeViewDebug.cpp
Go to the documentation of this file.
1//===- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.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//
9// This file contains support for writing Microsoft CodeView debug info.
10//
11//===----------------------------------------------------------------------===//
12
13#include "CodeViewDebug.h"
14#include "llvm/ADT/APSInt.h"
15#include "llvm/ADT/STLExtras.h"
16#include "llvm/ADT/SmallBitVector.h"
17#include "llvm/ADT/SmallString.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/ADT/TinyPtrVector.h"
20#include "llvm/ADT/Twine.h"
21#include "llvm/BinaryFormat/COFF.h"
22#include "llvm/BinaryFormat/Dwarf.h"
23#include "llvm/CodeGen/AsmPrinter.h"
24#include "llvm/CodeGen/LexicalScopes.h"
25#include "llvm/CodeGen/MachineFrameInfo.h"
26#include "llvm/CodeGen/MachineFunction.h"
27#include "llvm/CodeGen/MachineInstr.h"
28#include "llvm/CodeGen/MachineModuleInfo.h"
29#include "llvm/CodeGen/TargetFrameLowering.h"
30#include "llvm/CodeGen/TargetLowering.h"
31#include "llvm/CodeGen/TargetRegisterInfo.h"
32#include "llvm/CodeGen/TargetSubtargetInfo.h"
33#include "llvm/Config/llvm-config.h"
34#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
35#include "llvm/DebugInfo/CodeView/CodeViewRecordIO.h"
36#include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h"
37#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
38#include "llvm/DebugInfo/CodeView/EnumTables.h"
39#include "llvm/DebugInfo/CodeView/Line.h"
40#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
41#include "llvm/DebugInfo/CodeView/TypeRecord.h"
42#include "llvm/DebugInfo/CodeView/TypeTableCollection.h"
43#include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h"
44#include "llvm/IR/Constants.h"
45#include "llvm/IR/DataLayout.h"
46#include "llvm/IR/DebugInfoMetadata.h"
47#include "llvm/IR/Function.h"
48#include "llvm/IR/GlobalValue.h"
49#include "llvm/IR/GlobalVariable.h"
50#include "llvm/IR/Metadata.h"
51#include "llvm/IR/Module.h"
52#include "llvm/MC/MCAsmInfo.h"
53#include "llvm/MC/MCContext.h"
54#include "llvm/MC/MCSectionCOFF.h"
55#include "llvm/MC/MCStreamer.h"
56#include "llvm/MC/MCSymbol.h"
57#include "llvm/Support/BinaryStreamWriter.h"
58#include "llvm/Support/Casting.h"
59#include "llvm/Support/Error.h"
60#include "llvm/Support/ErrorHandling.h"
61#include "llvm/Support/FormatVariadic.h"
62#include "llvm/Support/Path.h"
63#include "llvm/Support/SMLoc.h"
64#include "llvm/Support/ScopedPrinter.h"
65#include "llvm/Target/TargetLoweringObjectFile.h"
66#include "llvm/Target/TargetMachine.h"
67#include "llvm/TargetParser/Triple.h"
68#include <algorithm>
69#include <cassert>
70#include <cctype>
71#include <cstddef>
72#include <limits>
73
74using namespacellvm;
75using namespacellvm::codeview;
76
77namespace{
78classCVMCAdapter :publicCodeViewRecordStreamer {
79public:
80 CVMCAdapter(MCStreamer &OS,TypeCollection &TypeTable)
81 :OS(&OS), TypeTable(TypeTable) {}
82
83voidemitBytes(StringRef Data) override{OS->emitBytes(Data); }
84
85voidemitIntValue(uint64_tValue,unsignedSize) override{
86OS->emitIntValueInHex(Value,Size);
87 }
88
89voidemitBinaryData(StringRef Data) override{OS->emitBinaryData(Data); }
90
91voidAddComment(constTwine &T) override{OS->AddComment(T); }
92
93voidAddRawComment(constTwine &T) override{OS->emitRawComment(T); }
94
95boolisVerboseAsm() override{returnOS->isVerboseAsm(); }
96
97 std::stringgetTypeName(TypeIndex TI) override{
98 std::stringTypeName;
99if (!TI.isNoneType()) {
100if (TI.isSimple())
101TypeName = std::string(TypeIndex::simpleTypeName(TI));
102else
103TypeName = std::string(TypeTable.getTypeName(TI));
104 }
105returnTypeName;
106 }
107
108private:
109MCStreamer *OS =nullptr;
110TypeCollection &TypeTable;
111};
112}// namespace
113
114staticCPUTypemapArchToCVCPUType(Triple::ArchTypeType) {
115switch (Type) {
116case Triple::ArchType::x86:
117return CPUType::Pentium3;
118case Triple::ArchType::x86_64:
119return CPUType::X64;
120case Triple::ArchType::thumb:
121// LLVM currently doesn't support Windows CE and so thumb
122// here is indiscriminately mapped to ARMNT specifically.
123return CPUType::ARMNT;
124case Triple::ArchType::aarch64:
125return CPUType::ARM64;
126case Triple::ArchType::mipsel:
127return CPUType::MIPS;
128default:
129report_fatal_error("target architecture doesn't map to a CodeView CPUType");
130 }
131}
132
133CodeViewDebug::CodeViewDebug(AsmPrinter *AP)
134 :DebugHandlerBase(AP),OS(*Asm->OutStreamer), TypeTable(Allocator) {}
135
136StringRef CodeViewDebug::getFullFilepath(constDIFile *File) {
137 std::string &Filepath = FileToFilepathMap[File];
138if (!Filepath.empty())
139return Filepath;
140
141StringRef Dir = File->getDirectory(), Filename = File->getFilename();
142
143// If this is a Unix-style path, just use it as is. Don't try to canonicalize
144// it textually because one of the path components could be a symlink.
145if (Dir.starts_with("/") || Filename.starts_with("/")) {
146if (llvm::sys::path::is_absolute(Filename,llvm::sys::path::Style::posix))
147return Filename;
148 Filepath = std::string(Dir);
149if (Dir.back() !='/')
150 Filepath +='/';
151 Filepath += Filename;
152return Filepath;
153 }
154
155// Clang emits directory and relative filename info into the IR, but CodeView
156// operates on full paths. We could change Clang to emit full paths too, but
157// that would increase the IR size and probably not needed for other users.
158// For now, just concatenate and canonicalize the path here.
159if (Filename.find(':') == 1)
160 Filepath = std::string(Filename);
161else
162 Filepath = (Dir +"\\" + Filename).str();
163
164// Canonicalize the path. We have to do it textually because we may no longer
165// have access the file in the filesystem.
166// First, replace all slashes with backslashes.
167 std::replace(Filepath.begin(), Filepath.end(),'/','\\');
168
169// Remove all "\.\" with "\".
170size_t Cursor = 0;
171while ((Cursor = Filepath.find("\\.\\", Cursor)) != std::string::npos)
172 Filepath.erase(Cursor, 2);
173
174// Replace all "\XXX\..\" with "\". Don't try too hard though as the original
175// path should be well-formatted, e.g. start with a drive letter, etc.
176 Cursor = 0;
177while ((Cursor = Filepath.find("\\..\\", Cursor)) != std::string::npos) {
178// Something's wrong if the path starts with "\..\", abort.
179if (Cursor == 0)
180break;
181
182size_t PrevSlash = Filepath.rfind('\\', Cursor - 1);
183if (PrevSlash == std::string::npos)
184// Something's wrong, abort.
185break;
186
187 Filepath.erase(PrevSlash, Cursor + 3 - PrevSlash);
188// The next ".." might be following the one we've just erased.
189 Cursor = PrevSlash;
190 }
191
192// Remove all duplicate backslashes.
193 Cursor = 0;
194while ((Cursor = Filepath.find("\\\\", Cursor)) != std::string::npos)
195 Filepath.erase(Cursor, 1);
196
197return Filepath;
198}
199
200unsigned CodeViewDebug::maybeRecordFile(constDIFile *F) {
201StringRef FullPath = getFullFilepath(F);
202unsigned NextId = FileIdMap.size() + 1;
203auto Insertion = FileIdMap.insert(std::make_pair(FullPath, NextId));
204if (Insertion.second) {
205// We have to compute the full filepath and emit a .cv_file directive.
206ArrayRef<uint8_t> ChecksumAsBytes;
207FileChecksumKind CSKind = FileChecksumKind::None;
208if (F->getChecksum()) {
209 std::string Checksum = fromHex(F->getChecksum()->Value);
210void *CKMem = OS.getContext().allocate(Checksum.size(), 1);
211 memcpy(CKMem, Checksum.data(), Checksum.size());
212 ChecksumAsBytes =ArrayRef<uint8_t>(
213reinterpret_cast<constuint8_t *>(CKMem), Checksum.size());
214switch (F->getChecksum()->Kind) {
215caseDIFile::CSK_MD5:
216 CSKind = FileChecksumKind::MD5;
217break;
218caseDIFile::CSK_SHA1:
219 CSKind = FileChecksumKind::SHA1;
220break;
221caseDIFile::CSK_SHA256:
222 CSKind = FileChecksumKind::SHA256;
223break;
224 }
225 }
226boolSuccess = OS.emitCVFileDirective(NextId, FullPath, ChecksumAsBytes,
227static_cast<unsigned>(CSKind));
228 (void)Success;
229assert(Success &&".cv_file directive failed");
230 }
231return Insertion.first->second;
232}
233
234CodeViewDebug::InlineSite &
235CodeViewDebug::getInlineSite(constDILocation *InlinedAt,
236constDISubprogram *Inlinee) {
237auto SiteInsertion = CurFn->InlineSites.insert({InlinedAt,InlineSite()});
238InlineSite *Site = &SiteInsertion.first->second;
239if (SiteInsertion.second) {
240unsigned ParentFuncId = CurFn->FuncId;
241if (constDILocation *OuterIA = InlinedAt->getInlinedAt())
242 ParentFuncId =
243 getInlineSite(OuterIA, InlinedAt->getScope()->getSubprogram())
244 .SiteFuncId;
245
246 Site->SiteFuncId = NextFuncId++;
247 OS.emitCVInlineSiteIdDirective(
248 Site->SiteFuncId, ParentFuncId, maybeRecordFile(InlinedAt->getFile()),
249 InlinedAt->getLine(), InlinedAt->getColumn(),SMLoc());
250 Site->Inlinee =Inlinee;
251 InlinedSubprograms.insert(Inlinee);
252auto InlineeIdx = getFuncIdForSubprogram(Inlinee);
253
254if (InlinedAt->getInlinedAt() ==nullptr)
255 CurFn->Inlinees.insert(InlineeIdx);
256 }
257return *Site;
258}
259
260staticStringRefgetPrettyScopeName(constDIScope *Scope) {
261StringRef ScopeName = Scope->getName();
262if (!ScopeName.empty())
263return ScopeName;
264
265switch (Scope->getTag()) {
266case dwarf::DW_TAG_enumeration_type:
267case dwarf::DW_TAG_class_type:
268case dwarf::DW_TAG_structure_type:
269case dwarf::DW_TAG_union_type:
270return"<unnamed-tag>";
271case dwarf::DW_TAG_namespace:
272return"`anonymous namespace'";
273default:
274returnStringRef();
275 }
276}
277
278constDISubprogram *CodeViewDebug::collectParentScopeNames(
279constDIScope *Scope,SmallVectorImpl<StringRef> &QualifiedNameComponents) {
280constDISubprogram *ClosestSubprogram =nullptr;
281while (Scope !=nullptr) {
282if (ClosestSubprogram ==nullptr)
283 ClosestSubprogram = dyn_cast<DISubprogram>(Scope);
284
285// If a type appears in a scope chain, make sure it gets emitted. The
286// frontend will be responsible for deciding if this should be a forward
287// declaration or a complete type.
288if (constauto *Ty = dyn_cast<DICompositeType>(Scope))
289 DeferredCompleteTypes.push_back(Ty);
290
291StringRef ScopeName =getPrettyScopeName(Scope);
292if (!ScopeName.empty())
293 QualifiedNameComponents.push_back(ScopeName);
294Scope =Scope->getScope();
295 }
296return ClosestSubprogram;
297}
298
299static std::stringformatNestedName(ArrayRef<StringRef> QualifiedNameComponents,
300StringRef TypeName) {
301 std::string FullyQualifiedName;
302for (StringRef QualifiedNameComponent :
303llvm::reverse(QualifiedNameComponents)) {
304 FullyQualifiedName.append(std::string(QualifiedNameComponent));
305 FullyQualifiedName.append("::");
306 }
307 FullyQualifiedName.append(std::string(TypeName));
308return FullyQualifiedName;
309}
310
311structCodeViewDebug::TypeLoweringScope {
312TypeLoweringScope(CodeViewDebug &CVD) :CVD(CVD) { ++CVD.TypeEmissionLevel; }
313~TypeLoweringScope() {
314// Don't decrement TypeEmissionLevel until after emitting deferred types, so
315// inner TypeLoweringScopes don't attempt to emit deferred types.
316if (CVD.TypeEmissionLevel == 1)
317CVD.emitDeferredCompleteTypes();
318 --CVD.TypeEmissionLevel;
319 }
320CodeViewDebug &CVD;
321};
322
323std::string CodeViewDebug::getFullyQualifiedName(constDIScope *Scope,
324StringRefName) {
325// Ensure types in the scope chain are emitted as soon as possible.
326// This can create otherwise a situation where S_UDTs are emitted while
327// looping in emitDebugInfoForUDTs.
328TypeLoweringScope S(*this);
329SmallVector<StringRef, 5> QualifiedNameComponents;
330 collectParentScopeNames(Scope, QualifiedNameComponents);
331returnformatNestedName(QualifiedNameComponents,Name);
332}
333
334std::string CodeViewDebug::getFullyQualifiedName(constDIScope *Ty) {
335constDIScope *Scope = Ty->getScope();
336return getFullyQualifiedName(Scope,getPrettyScopeName(Ty));
337}
338
339TypeIndex CodeViewDebug::getScopeIndex(constDIScope *Scope) {
340// No scope means global scope and that uses the zero index.
341//
342// We also use zero index when the scope is a DISubprogram
343// to suppress the emission of LF_STRING_ID for the function,
344// which can trigger a link-time error with the linker in
345// VS2019 version 16.11.2 or newer.
346// Note, however, skipping the debug info emission for the DISubprogram
347// is a temporary fix. The root issue here is that we need to figure out
348// the proper way to encode a function nested in another function
349// (as introduced by the Fortran 'contains' keyword) in CodeView.
350if (!Scope || isa<DIFile>(Scope) || isa<DISubprogram>(Scope))
351returnTypeIndex();
352
353assert(!isa<DIType>(Scope) &&"shouldn't make a namespace scope for a type");
354
355// Check if we've already translated this scope.
356autoI = TypeIndices.find({Scope,nullptr});
357if (I != TypeIndices.end())
358returnI->second;
359
360// Build the fully qualified name of the scope.
361 std::string ScopeName = getFullyQualifiedName(Scope);
362StringIdRecord SID(TypeIndex(), ScopeName);
363auto TI = TypeTable.writeLeafType(SID);
364return recordTypeIndexForDINode(Scope, TI);
365}
366
367staticStringRefremoveTemplateArgs(StringRefName) {
368// Remove template args from the display name. Assume that the template args
369// are the last thing in the name.
370if (Name.empty() ||Name.back() !='>')
371returnName;
372
373int OpenBrackets = 0;
374for (int i =Name.size() - 1; i >= 0; --i) {
375if (Name[i] =='>')
376 ++OpenBrackets;
377elseif (Name[i] =='<') {
378 --OpenBrackets;
379if (OpenBrackets == 0)
380returnName.substr(0, i);
381 }
382 }
383returnName;
384}
385
386TypeIndex CodeViewDebug::getFuncIdForSubprogram(constDISubprogram *SP) {
387assert(SP);
388
389// Check if we've already translated this subprogram.
390autoI = TypeIndices.find({SP,nullptr});
391if (I != TypeIndices.end())
392returnI->second;
393
394// The display name includes function template arguments. Drop them to match
395// MSVC. We need to have the template arguments in the DISubprogram name
396// because they are used in other symbol records, such as S_GPROC32_IDs.
397StringRef DisplayName =removeTemplateArgs(SP->getName());
398
399constDIScope *Scope = SP->getScope();
400TypeIndex TI;
401if (constauto *Class = dyn_cast_or_null<DICompositeType>(Scope)) {
402// If the scope is a DICompositeType, then this must be a method. Member
403// function types take some special handling, and require access to the
404// subprogram.
405TypeIndex ClassType = getTypeIndex(Class);
406MemberFuncIdRecord MFuncId(ClassType, getMemberFunctionType(SP, Class),
407 DisplayName);
408 TI = TypeTable.writeLeafType(MFuncId);
409 }else {
410// Otherwise, this must be a free function.
411TypeIndex ParentScope = getScopeIndex(Scope);
412FuncIdRecordFuncId(ParentScope, getTypeIndex(SP->getType()), DisplayName);
413 TI = TypeTable.writeLeafType(FuncId);
414 }
415
416return recordTypeIndexForDINode(SP, TI);
417}
418
419staticboolisNonTrivial(constDICompositeType *DCTy) {
420return ((DCTy->getFlags() & DINode::FlagNonTrivial) == DINode::FlagNonTrivial);
421}
422
423staticFunctionOptions
424getFunctionOptions(constDISubroutineType *Ty,
425constDICompositeType *ClassTy =nullptr,
426StringRef SPName =StringRef("")) {
427FunctionOptions FO = FunctionOptions::None;
428constDIType *ReturnTy =nullptr;
429if (auto TypeArray = Ty->getTypeArray()) {
430if (TypeArray.size())
431 ReturnTy = TypeArray[0];
432 }
433
434// Add CxxReturnUdt option to functions that return nontrivial record types
435// or methods that return record types.
436if (auto *ReturnDCTy = dyn_cast_or_null<DICompositeType>(ReturnTy))
437if (isNonTrivial(ReturnDCTy) || ClassTy)
438 FO |= FunctionOptions::CxxReturnUdt;
439
440// DISubroutineType is unnamed. Use DISubprogram's i.e. SPName in comparison.
441if (ClassTy &&isNonTrivial(ClassTy) && SPName == ClassTy->getName()) {
442 FO |= FunctionOptions::Constructor;
443
444// TODO: put the FunctionOptions::ConstructorWithVirtualBases flag.
445
446 }
447return FO;
448}
449
450TypeIndex CodeViewDebug::getMemberFunctionType(constDISubprogram *SP,
451constDICompositeType *Class) {
452// Always use the method declaration as the key for the function type. The
453// method declaration contains the this adjustment.
454if (SP->getDeclaration())
455 SP = SP->getDeclaration();
456assert(!SP->getDeclaration() &&"should use declaration as key");
457
458// Key the MemberFunctionRecord into the map as {SP, Class}. It won't collide
459// with the MemberFuncIdRecord, which is keyed in as {SP, nullptr}.
460autoI = TypeIndices.find({SP,Class});
461if (I != TypeIndices.end())
462returnI->second;
463
464// Make sure complete type info for the class is emitted *after* the member
465// function type, as the complete class type is likely to reference this
466// member function type.
467 TypeLoweringScope S(*this);
468constbool IsStaticMethod = (SP->getFlags() & DINode::FlagStaticMember) != 0;
469
470FunctionOptions FO =getFunctionOptions(SP->getType(), Class, SP->getName());
471TypeIndex TI = lowerTypeMemberFunction(
472 SP->getType(), Class, SP->getThisAdjustment(), IsStaticMethod, FO);
473return recordTypeIndexForDINode(SP, TI, Class);
474}
475
476TypeIndex CodeViewDebug::recordTypeIndexForDINode(constDINode *Node,
477TypeIndex TI,
478constDIType *ClassTy) {
479auto InsertResult = TypeIndices.insert({{Node, ClassTy}, TI});
480 (void)InsertResult;
481assert(InsertResult.second &&"DINode was already assigned a type index");
482return TI;
483}
484
485unsigned CodeViewDebug::getPointerSizeInBytes() {
486returnMMI->getModule()->getDataLayout().getPointerSizeInBits() / 8;
487}
488
489void CodeViewDebug::recordLocalVariable(LocalVariable &&Var,
490constLexicalScope *LS) {
491if (constDILocation *InlinedAt =LS->getInlinedAt()) {
492// This variable was inlined. Associate it with the InlineSite.
493constDISubprogram *Inlinee = Var.DIVar->getScope()->getSubprogram();
494InlineSite &Site = getInlineSite(InlinedAt, Inlinee);
495 Site.InlinedLocals.emplace_back(std::move(Var));
496 }else {
497// This variable goes into the corresponding lexical scope.
498 ScopeVariables[LS].emplace_back(std::move(Var));
499 }
500}
501
502staticvoidaddLocIfNotPresent(SmallVectorImpl<const DILocation *> &Locs,
503constDILocation *Loc) {
504if (!llvm::is_contained(Locs, Loc))
505 Locs.push_back(Loc);
506}
507
508void CodeViewDebug::maybeRecordLocation(constDebugLoc &DL,
509constMachineFunction *MF) {
510// Skip this instruction if it has the same location as the previous one.
511if (!DL ||DL ==PrevInstLoc)
512return;
513
514constDIScope *Scope =DL->getScope();
515if (!Scope)
516return;
517
518// Skip this line if it is longer than the maximum we can record.
519LineInfo LI(DL.getLine(),DL.getLine(),/*IsStatement=*/true);
520if (LI.getStartLine() !=DL.getLine() || LI.isAlwaysStepInto() ||
521 LI.isNeverStepInto())
522return;
523
524ColumnInfo CI(DL.getCol(),/*EndColumn=*/0);
525if (CI.getStartColumn() !=DL.getCol())
526return;
527
528if (!CurFn->HaveLineInfo)
529 CurFn->HaveLineInfo =true;
530unsigned FileId = 0;
531if (PrevInstLoc.get() &&PrevInstLoc->getFile() ==DL->getFile())
532 FileId = CurFn->LastFileId;
533else
534 FileId = CurFn->LastFileId = maybeRecordFile(DL->getFile());
535PrevInstLoc =DL;
536
537unsignedFuncId = CurFn->FuncId;
538if (constDILocation *SiteLoc =DL->getInlinedAt()) {
539constDILocation *Loc =DL.get();
540
541// If this location was actually inlined from somewhere else, give it the ID
542// of the inline call site.
543FuncId =
544 getInlineSite(SiteLoc, Loc->getScope()->getSubprogram()).SiteFuncId;
545
546// Ensure we have links in the tree of inline call sites.
547bool FirstLoc =true;
548while ((SiteLoc = Loc->getInlinedAt())) {
549InlineSite &Site =
550 getInlineSite(SiteLoc, Loc->getScope()->getSubprogram());
551if (!FirstLoc)
552addLocIfNotPresent(Site.ChildSites, Loc);
553 FirstLoc =false;
554 Loc = SiteLoc;
555 }
556addLocIfNotPresent(CurFn->ChildSites, Loc);
557 }
558
559 OS.emitCVLocDirective(FuncId, FileId,DL.getLine(),DL.getCol(),
560/*PrologueEnd=*/false,/*IsStmt=*/false,
561DL->getFilename(),SMLoc());
562}
563
564void CodeViewDebug::emitCodeViewMagicVersion() {
565 OS.emitValueToAlignment(Align(4));
566 OS.AddComment("Debug section magic");
567 OS.emitInt32(COFF::DEBUG_SECTION_MAGIC);
568}
569
570staticSourceLanguageMapDWLangToCVLang(unsigned DWLang) {
571switch (DWLang) {
572case dwarf::DW_LANG_C:
573case dwarf::DW_LANG_C89:
574case dwarf::DW_LANG_C99:
575case dwarf::DW_LANG_C11:
576return SourceLanguage::C;
577case dwarf::DW_LANG_C_plus_plus:
578case dwarf::DW_LANG_C_plus_plus_03:
579case dwarf::DW_LANG_C_plus_plus_11:
580case dwarf::DW_LANG_C_plus_plus_14:
581return SourceLanguage::Cpp;
582case dwarf::DW_LANG_Fortran77:
583case dwarf::DW_LANG_Fortran90:
584case dwarf::DW_LANG_Fortran95:
585case dwarf::DW_LANG_Fortran03:
586case dwarf::DW_LANG_Fortran08:
587return SourceLanguage::Fortran;
588case dwarf::DW_LANG_Pascal83:
589return SourceLanguage::Pascal;
590case dwarf::DW_LANG_Cobol74:
591case dwarf::DW_LANG_Cobol85:
592return SourceLanguage::Cobol;
593case dwarf::DW_LANG_Java:
594return SourceLanguage::Java;
595case dwarf::DW_LANG_D:
596return SourceLanguage::D;
597case dwarf::DW_LANG_Swift:
598return SourceLanguage::Swift;
599case dwarf::DW_LANG_Rust:
600return SourceLanguage::Rust;
601case dwarf::DW_LANG_ObjC:
602return SourceLanguage::ObjC;
603case dwarf::DW_LANG_ObjC_plus_plus:
604return SourceLanguage::ObjCpp;
605default:
606// There's no CodeView representation for this language, and CV doesn't
607// have an "unknown" option for the language field, so we'll use MASM,
608// as it's very low level.
609return SourceLanguage::Masm;
610 }
611}
612
613voidCodeViewDebug::beginModule(Module *M) {
614// If module doesn't have named metadata anchors or COFF debug section
615// is not available, skip any debug info related stuff.
616if (!Asm->hasDebugInfo() ||
617 !Asm->getObjFileLowering().getCOFFDebugSymbolsSection()) {
618Asm =nullptr;
619return;
620 }
621
622 TheCPU =mapArchToCVCPUType(Triple(M->getTargetTriple()).getArch());
623
624// Get the current source language.
625constMDNode *Node = *M->debug_compile_units_begin();
626constauto *CU = cast<DICompileUnit>(Node);
627
628 CurrentSourceLanguage =MapDWLangToCVLang(CU->getSourceLanguage());
629
630 collectGlobalVariableInfo();
631
632// Check if we should emit type record hashes.
633ConstantInt *GH =
634 mdconst::extract_or_null<ConstantInt>(M->getModuleFlag("CodeViewGHash"));
635 EmitDebugGlobalHashes = GH && !GH->isZero();
636}
637
638voidCodeViewDebug::endModule() {
639if (!Asm || !Asm->hasDebugInfo())
640return;
641
642// The COFF .debug$S section consists of several subsections, each starting
643// with a 4-byte control code (e.g. 0xF1, 0xF2, etc) and then a 4-byte length
644// of the payload followed by the payload itself. The subsections are 4-byte
645// aligned.
646
647// Use the generic .debug$S section, and make a subsection for all the inlined
648// subprograms.
649 switchToDebugSectionForSymbol(nullptr);
650
651MCSymbol *CompilerInfo = beginCVSubsection(DebugSubsectionKind::Symbols);
652 emitObjName();
653 emitCompilerInformation();
654 endCVSubsection(CompilerInfo);
655
656 emitInlineeLinesSubsection();
657
658// Emit per-function debug information.
659for (auto &P : FnDebugInfo)
660if (!P.first->isDeclarationForLinker())
661 emitDebugInfoForFunction(P.first, *P.second);
662
663// Get types used by globals without emitting anything.
664// This is meant to collect all static const data members so they can be
665// emitted as globals.
666 collectDebugInfoForGlobals();
667
668// Emit retained types.
669 emitDebugInfoForRetainedTypes();
670
671// Emit global variable debug information.
672 setCurrentSubprogram(nullptr);
673 emitDebugInfoForGlobals();
674
675// Switch back to the generic .debug$S section after potentially processing
676// comdat symbol sections.
677 switchToDebugSectionForSymbol(nullptr);
678
679// Emit UDT records for any types used by global variables.
680if (!GlobalUDTs.empty()) {
681MCSymbol *SymbolsEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
682 emitDebugInfoForUDTs(GlobalUDTs);
683 endCVSubsection(SymbolsEnd);
684 }
685
686// This subsection holds a file index to offset in string table table.
687 OS.AddComment("File index to string table offset subsection");
688 OS.emitCVFileChecksumsDirective();
689
690// This subsection holds the string table.
691 OS.AddComment("String table");
692 OS.emitCVStringTableDirective();
693
694// Emit S_BUILDINFO, which points to LF_BUILDINFO. Put this in its own symbol
695// subsection in the generic .debug$S section at the end. There is no
696// particular reason for this ordering other than to match MSVC.
697 emitBuildInfo();
698
699// Emit type information and hashes last, so that any types we translate while
700// emitting function info are included.
701 emitTypeInformation();
702
703if (EmitDebugGlobalHashes)
704 emitTypeGlobalHashes();
705
706 clear();
707}
708
709staticvoid
710emitNullTerminatedSymbolName(MCStreamer &OS,StringRef S,
711unsigned MaxFixedRecordLength = 0xF00) {
712// The maximum CV record length is 0xFF00. Most of the strings we emit appear
713// after a fixed length portion of the record. The fixed length portion should
714// always be less than 0xF00 (3840) bytes, so truncate the string so that the
715// overall record size is less than the maximum allowed.
716SmallString<32> NullTerminatedString(
717 S.take_front(MaxRecordLength - MaxFixedRecordLength - 1));
718 NullTerminatedString.push_back('\0');
719OS.emitBytes(NullTerminatedString);
720}
721
722void CodeViewDebug::emitTypeInformation() {
723if (TypeTable.empty())
724return;
725
726// Start the .debug$T or .debug$P section with 0x4.
727 OS.switchSection(Asm->getObjFileLowering().getCOFFDebugTypesSection());
728 emitCodeViewMagicVersion();
729
730TypeTableCollection Table(TypeTable.records());
731TypeVisitorCallbackPipeline Pipeline;
732
733// To emit type record using Codeview MCStreamer adapter
734 CVMCAdapter CVMCOS(OS, Table);
735TypeRecordMapping typeMapping(CVMCOS);
736 Pipeline.addCallbackToPipeline(typeMapping);
737
738 std::optional<TypeIndex>B = Table.getFirst();
739while (B) {
740// This will fail if the record data is invalid.
741CVTypeRecord = Table.getType(*B);
742
743Error E =codeview::visitTypeRecord(Record, *B, Pipeline);
744
745if (E) {
746logAllUnhandledErrors(std::move(E),errs(),"error: ");
747llvm_unreachable("produced malformed type record");
748 }
749
750B = Table.getNext(*B);
751 }
752}
753
754void CodeViewDebug::emitTypeGlobalHashes() {
755if (TypeTable.empty())
756return;
757
758// Start the .debug$H section with the version and hash algorithm, currently
759// hardcoded to version 0, SHA1.
760 OS.switchSection(Asm->getObjFileLowering().getCOFFGlobalTypeHashesSection());
761
762 OS.emitValueToAlignment(Align(4));
763 OS.AddComment("Magic");
764 OS.emitInt32(COFF::DEBUG_HASHES_SECTION_MAGIC);
765 OS.AddComment("Section Version");
766 OS.emitInt16(0);
767 OS.AddComment("Hash Algorithm");
768 OS.emitInt16(uint16_t(GlobalTypeHashAlg::BLAKE3));
769
770TypeIndex TI(TypeIndex::FirstNonSimpleIndex);
771for (constauto &GHR : TypeTable.hashes()) {
772if (OS.isVerboseAsm()) {
773// Emit an EOL-comment describing which TypeIndex this hash corresponds
774// to, as well as the stringified SHA1 hash.
775SmallString<32>Comment;
776raw_svector_ostream CommentOS(Comment);
777 CommentOS <<formatv("{0:X+} [{1}]", TI.getIndex(), GHR);
778 OS.AddComment(Comment);
779 ++TI;
780 }
781assert(GHR.Hash.size() == 8);
782StringRef S(reinterpret_cast<constchar *>(GHR.Hash.data()),
783 GHR.Hash.size());
784 OS.emitBinaryData(S);
785 }
786}
787
788void CodeViewDebug::emitObjName() {
789MCSymbol *CompilerEnd = beginSymbolRecord(SymbolKind::S_OBJNAME);
790
791StringRef PathRef(Asm->TM.Options.ObjectFilenameForDebug);
792llvm::SmallString<256> PathStore(PathRef);
793
794if (PathRef.empty() || PathRef =="-") {
795// Don't emit the filename if we're writing to stdout or to /dev/null.
796 PathRef = {};
797 }else {
798 PathRef = PathStore;
799 }
800
801 OS.AddComment("Signature");
802 OS.emitIntValue(0, 4);
803
804 OS.AddComment("Object name");
805emitNullTerminatedSymbolName(OS, PathRef);
806
807 endSymbolRecord(CompilerEnd);
808}
809
810namespace{
811structVersion {
812int Part[4];
813};
814}// end anonymous namespace
815
816// Takes a StringRef like "clang 4.0.0.0 (other nonsense 123)" and parses out
817// the version number.
818staticVersionparseVersion(StringRefName) {
819Version V = {{0}};
820intN = 0;
821for (constcharC :Name) {
822if (isdigit(C)) {
823 V.Part[N] *= 10;
824 V.Part[N] +=C -'0';
825 V.Part[N] =
826 std::min<int>(V.Part[N], std::numeric_limits<uint16_t>::max());
827 }elseif (C =='.') {
828 ++N;
829if (N >= 4)
830return V;
831 }elseif (N > 0)
832return V;
833 }
834return V;
835}
836
837void CodeViewDebug::emitCompilerInformation() {
838MCSymbol *CompilerEnd = beginSymbolRecord(SymbolKind::S_COMPILE3);
839uint32_tFlags = 0;
840
841// The low byte of the flags indicates the source language.
842Flags = CurrentSourceLanguage;
843// TODO: Figure out which other flags need to be set.
844if (MMI->getModule()->getProfileSummary(/*IsCS*/false) !=nullptr) {
845Flags |=static_cast<uint32_t>(CompileSym3Flags::PGO);
846 }
847usingArchType =llvm::Triple::ArchType;
848 ArchType Arch =Triple(MMI->getModule()->getTargetTriple()).getArch();
849if (Asm->TM.Options.Hotpatch || Arch == ArchType::thumb ||
850 Arch == ArchType::aarch64) {
851Flags |=static_cast<uint32_t>(CompileSym3Flags::HotPatch);
852 }
853
854 OS.AddComment("Flags and language");
855 OS.emitInt32(Flags);
856
857 OS.AddComment("CPUType");
858 OS.emitInt16(static_cast<uint64_t>(TheCPU));
859
860NamedMDNode *CUs =MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
861constMDNode *Node = *CUs->operands().begin();
862constauto *CU = cast<DICompileUnit>(Node);
863
864StringRef CompilerVersion =CU->getProducer();
865Version FrontVer =parseVersion(CompilerVersion);
866 OS.AddComment("Frontend version");
867for (intN : FrontVer.Part) {
868 OS.emitInt16(N);
869 }
870
871// Some Microsoft tools, like Binscope, expect a backend version number of at
872// least 8.something, so we'll coerce the LLVM version into a form that
873// guarantees it'll be big enough without really lying about the version.
874int Major = 1000 * LLVM_VERSION_MAJOR +
875 10 * LLVM_VERSION_MINOR +
876 LLVM_VERSION_PATCH;
877// Clamp it for builds that use unusually large version numbers.
878 Major = std::min<int>(Major, std::numeric_limits<uint16_t>::max());
879Version BackVer = {{ Major, 0, 0, 0 }};
880 OS.AddComment("Backend version");
881for (intN : BackVer.Part)
882 OS.emitInt16(N);
883
884 OS.AddComment("Null-terminated compiler version string");
885emitNullTerminatedSymbolName(OS, CompilerVersion);
886
887 endSymbolRecord(CompilerEnd);
888}
889
890staticTypeIndexgetStringIdTypeIdx(GlobalTypeTableBuilder &TypeTable,
891StringRef S) {
892StringIdRecord SIR(TypeIndex(0x0), S);
893return TypeTable.writeLeafType(SIR);
894}
895
896void CodeViewDebug::emitBuildInfo() {
897// First, make LF_BUILDINFO. It's a sequence of strings with various bits of
898// build info. The known prefix is:
899// - Absolute path of current directory
900// - Compiler path
901// - Main source file path, relative to CWD or absolute
902// - Type server PDB file
903// - Canonical compiler command line
904// If frontend and backend compilation are separated (think llc or LTO), it's
905// not clear if the compiler path should refer to the executable for the
906// frontend or the backend. Leave it blank for now.
907TypeIndex BuildInfoArgs[BuildInfoRecord::MaxArgs] = {};
908NamedMDNode *CUs =MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
909constMDNode *Node = *CUs->operands().begin();// FIXME: Multiple CUs.
910constauto *CU = cast<DICompileUnit>(Node);
911constDIFile *MainSourceFile =CU->getFile();
912 BuildInfoArgs[BuildInfoRecord::CurrentDirectory] =
913getStringIdTypeIdx(TypeTable, MainSourceFile->getDirectory());
914 BuildInfoArgs[BuildInfoRecord::SourceFile] =
915getStringIdTypeIdx(TypeTable, MainSourceFile->getFilename());
916// FIXME: PDB is intentionally blank unless we implement /Zi type servers.
917 BuildInfoArgs[BuildInfoRecord::TypeServerPDB] =
918getStringIdTypeIdx(TypeTable,"");
919 BuildInfoArgs[BuildInfoRecord::BuildTool] =
920getStringIdTypeIdx(TypeTable,Asm->TM.Options.MCOptions.Argv0);
921 BuildInfoArgs[BuildInfoRecord::CommandLine] =getStringIdTypeIdx(
922 TypeTable,Asm->TM.Options.MCOptions.CommandlineArgs);
923
924BuildInfoRecord BIR(BuildInfoArgs);
925TypeIndex BuildInfoIndex = TypeTable.writeLeafType(BIR);
926
927// Make a new .debug$S subsection for the S_BUILDINFO record, which points
928// from the module symbols into the type stream.
929MCSymbol *BISubsecEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
930MCSymbol *BIEnd = beginSymbolRecord(SymbolKind::S_BUILDINFO);
931 OS.AddComment("LF_BUILDINFO index");
932 OS.emitInt32(BuildInfoIndex.getIndex());
933 endSymbolRecord(BIEnd);
934 endCVSubsection(BISubsecEnd);
935}
936
937void CodeViewDebug::emitInlineeLinesSubsection() {
938if (InlinedSubprograms.empty())
939return;
940
941 OS.AddComment("Inlinee lines subsection");
942MCSymbol *InlineEnd = beginCVSubsection(DebugSubsectionKind::InlineeLines);
943
944// We emit the checksum info for files. This is used by debuggers to
945// determine if a pdb matches the source before loading it. Visual Studio,
946// for instance, will display a warning that the breakpoints are not valid if
947// the pdb does not match the source.
948 OS.AddComment("Inlinee lines signature");
949 OS.emitInt32(unsigned(InlineeLinesSignature::Normal));
950
951for (constDISubprogram *SP : InlinedSubprograms) {
952assert(TypeIndices.count({SP, nullptr}));
953TypeIndex InlineeIdx = TypeIndices[{SP,nullptr}];
954
955 OS.addBlankLine();
956unsigned FileId = maybeRecordFile(SP->getFile());
957 OS.AddComment("Inlined function " + SP->getName() +" starts at " +
958 SP->getFilename() +Twine(':') +Twine(SP->getLine()));
959 OS.addBlankLine();
960 OS.AddComment("Type index of inlined function");
961 OS.emitInt32(InlineeIdx.getIndex());
962 OS.AddComment("Offset into filechecksum table");
963 OS.emitCVFileChecksumOffsetDirective(FileId);
964 OS.AddComment("Starting line number");
965 OS.emitInt32(SP->getLine());
966 }
967
968 endCVSubsection(InlineEnd);
969}
970
971void CodeViewDebug::emitInlinedCallSite(const FunctionInfo &FI,
972constDILocation *InlinedAt,
973constInlineSite &Site) {
974assert(TypeIndices.count({Site.Inlinee, nullptr}));
975TypeIndex InlineeIdx = TypeIndices[{Site.Inlinee,nullptr}];
976
977// SymbolRecord
978MCSymbol *InlineEnd = beginSymbolRecord(SymbolKind::S_INLINESITE);
979
980 OS.AddComment("PtrParent");
981 OS.emitInt32(0);
982 OS.AddComment("PtrEnd");
983 OS.emitInt32(0);
984 OS.AddComment("Inlinee type index");
985 OS.emitInt32(InlineeIdx.getIndex());
986
987unsigned FileId = maybeRecordFile(Site.Inlinee->getFile());
988unsigned StartLineNum = Site.Inlinee->getLine();
989
990 OS.emitCVInlineLinetableDirective(Site.SiteFuncId, FileId, StartLineNum,
991 FI.Begin, FI.End);
992
993 endSymbolRecord(InlineEnd);
994
995 emitLocalVariableList(FI, Site.InlinedLocals);
996
997// Recurse on child inlined call sites before closing the scope.
998for (constDILocation *ChildSite : Site.ChildSites) {
999autoI = FI.InlineSites.find(ChildSite);
1000assert(I != FI.InlineSites.end() &&
1001"child site not in function inline site map");
1002 emitInlinedCallSite(FI, ChildSite,I->second);
1003 }
1004
1005// Close the scope.
1006 emitEndSymbolRecord(SymbolKind::S_INLINESITE_END);
1007}
1008
1009void CodeViewDebug::switchToDebugSectionForSymbol(constMCSymbol *GVSym) {
1010// If we have a symbol, it may be in a section that is COMDAT. If so, find the
1011// comdat key. A section may be comdat because of -ffunction-sections or
1012// because it is comdat in the IR.
1013MCSectionCOFF *GVSec =
1014 GVSym ? dyn_cast<MCSectionCOFF>(&GVSym->getSection()) : nullptr;
1015constMCSymbol *KeySym = GVSec ? GVSec->getCOMDATSymbol() :nullptr;
1016
1017MCSectionCOFF *DebugSec = cast<MCSectionCOFF>(
1018Asm->getObjFileLowering().getCOFFDebugSymbolsSection());
1019 DebugSec = OS.getContext().getAssociativeCOFFSection(DebugSec, KeySym);
1020
1021 OS.switchSection(DebugSec);
1022
1023// Emit the magic version number if this is the first time we've switched to
1024// this section.
1025if (ComdatDebugSections.insert(DebugSec).second)
1026 emitCodeViewMagicVersion();
1027}
1028
1029// Emit an S_THUNK32/S_END symbol pair for a thunk routine.
1030// The only supported thunk ordinal is currently the standard type.
1031void CodeViewDebug::emitDebugInfoForThunk(constFunction *GV,
1032 FunctionInfo &FI,
1033constMCSymbol *Fn) {
1034 std::string FuncName =
1035 std::string(GlobalValue::dropLLVMManglingEscape(GV->getName()));
1036constThunkOrdinal ordinal = ThunkOrdinal::Standard;// Only supported kind.
1037
1038 OS.AddComment("Symbol subsection for " +Twine(FuncName));
1039MCSymbol *SymbolsEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
1040
1041// Emit S_THUNK32
1042MCSymbol *ThunkRecordEnd = beginSymbolRecord(SymbolKind::S_THUNK32);
1043 OS.AddComment("PtrParent");
1044 OS.emitInt32(0);
1045 OS.AddComment("PtrEnd");
1046 OS.emitInt32(0);
1047 OS.AddComment("PtrNext");
1048 OS.emitInt32(0);
1049 OS.AddComment("Thunk section relative address");
1050 OS.emitCOFFSecRel32(Fn,/*Offset=*/0);
1051 OS.AddComment("Thunk section index");
1052 OS.emitCOFFSectionIndex(Fn);
1053 OS.AddComment("Code size");
1054 OS.emitAbsoluteSymbolDiff(FI.End, Fn, 2);
1055 OS.AddComment("Ordinal");
1056 OS.emitInt8(unsigned(ordinal));
1057 OS.AddComment("Function name");
1058emitNullTerminatedSymbolName(OS, FuncName);
1059// Additional fields specific to the thunk ordinal would go here.
1060 endSymbolRecord(ThunkRecordEnd);
1061
1062// Local variables/inlined routines are purposely omitted here. The point of
1063// marking this as a thunk is so Visual Studio will NOT stop in this routine.
1064
1065// Emit S_PROC_ID_END
1066 emitEndSymbolRecord(SymbolKind::S_PROC_ID_END);
1067
1068 endCVSubsection(SymbolsEnd);
1069}
1070
1071void CodeViewDebug::emitDebugInfoForFunction(constFunction *GV,
1072 FunctionInfo &FI) {
1073// For each function there is a separate subsection which holds the PC to
1074// file:line table.
1075constMCSymbol *Fn =Asm->getSymbol(GV);
1076assert(Fn);
1077
1078// Switch to the to a comdat section, if appropriate.
1079 switchToDebugSectionForSymbol(Fn);
1080
1081 std::string FuncName;
1082auto *SP = GV->getSubprogram();
1083assert(SP);
1084 setCurrentSubprogram(SP);
1085
1086if (SP->isThunk()) {
1087 emitDebugInfoForThunk(GV, FI, Fn);
1088return;
1089 }
1090
1091// If we have a display name, build the fully qualified name by walking the
1092// chain of scopes.
1093if (!SP->getName().empty())
1094 FuncName = getFullyQualifiedName(SP->getScope(), SP->getName());
1095
1096// If our DISubprogram name is empty, use the mangled name.
1097if (FuncName.empty())
1098 FuncName = std::string(GlobalValue::dropLLVMManglingEscape(GV->getName()));
1099
1100// Emit FPO data, but only on 32-bit x86. No other platforms use it.
1101if (Triple(MMI->getModule()->getTargetTriple()).getArch() ==Triple::x86)
1102 OS.emitCVFPOData(Fn);
1103
1104// Emit a symbol subsection, required by VS2012+ to find function boundaries.
1105 OS.AddComment("Symbol subsection for " +Twine(FuncName));
1106MCSymbol *SymbolsEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
1107 {
1108SymbolKind ProcKind = GV->hasLocalLinkage() ? SymbolKind::S_LPROC32_ID
1109 : SymbolKind::S_GPROC32_ID;
1110MCSymbol *ProcRecordEnd = beginSymbolRecord(ProcKind);
1111
1112// These fields are filled in by tools like CVPACK which run after the fact.
1113 OS.AddComment("PtrParent");
1114 OS.emitInt32(0);
1115 OS.AddComment("PtrEnd");
1116 OS.emitInt32(0);
1117 OS.AddComment("PtrNext");
1118 OS.emitInt32(0);
1119// This is the important bit that tells the debugger where the function
1120// code is located and what's its size:
1121 OS.AddComment("Code size");
1122 OS.emitAbsoluteSymbolDiff(FI.End, Fn, 4);
1123 OS.AddComment("Offset after prologue");
1124 OS.emitInt32(0);
1125 OS.AddComment("Offset before epilogue");
1126 OS.emitInt32(0);
1127 OS.AddComment("Function type index");
1128 OS.emitInt32(getFuncIdForSubprogram(GV->getSubprogram()).getIndex());
1129 OS.AddComment("Function section relative address");
1130 OS.emitCOFFSecRel32(Fn,/*Offset=*/0);
1131 OS.AddComment("Function section index");
1132 OS.emitCOFFSectionIndex(Fn);
1133 OS.AddComment("Flags");
1134ProcSymFlags ProcFlags = ProcSymFlags::HasOptimizedDebugInfo;
1135if (FI.HasFramePointer)
1136 ProcFlags |= ProcSymFlags::HasFP;
1137if (GV->hasFnAttribute(Attribute::NoReturn))
1138 ProcFlags |= ProcSymFlags::IsNoReturn;
1139if (GV->hasFnAttribute(Attribute::NoInline))
1140 ProcFlags |= ProcSymFlags::IsNoInline;
1141 OS.emitInt8(static_cast<uint8_t>(ProcFlags));
1142// Emit the function display name as a null-terminated string.
1143 OS.AddComment("Function name");
1144// Truncate the name so we won't overflow the record length field.
1145emitNullTerminatedSymbolName(OS, FuncName);
1146 endSymbolRecord(ProcRecordEnd);
1147
1148MCSymbol *FrameProcEnd = beginSymbolRecord(SymbolKind::S_FRAMEPROC);
1149// Subtract out the CSR size since MSVC excludes that and we include it.
1150 OS.AddComment("FrameSize");
1151 OS.emitInt32(FI.FrameSize - FI.CSRSize);
1152 OS.AddComment("Padding");
1153 OS.emitInt32(0);
1154 OS.AddComment("Offset of padding");
1155 OS.emitInt32(0);
1156 OS.AddComment("Bytes of callee saved registers");
1157 OS.emitInt32(FI.CSRSize);
1158 OS.AddComment("Exception handler offset");
1159 OS.emitInt32(0);
1160 OS.AddComment("Exception handler section");
1161 OS.emitInt16(0);
1162 OS.AddComment("Flags (defines frame register)");
1163 OS.emitInt32(uint32_t(FI.FrameProcOpts));
1164 endSymbolRecord(FrameProcEnd);
1165
1166 emitInlinees(FI.Inlinees);
1167 emitLocalVariableList(FI, FI.Locals);
1168 emitGlobalVariableList(FI.Globals);
1169 emitLexicalBlockList(FI.ChildBlocks, FI);
1170
1171// Emit inlined call site information. Only emit functions inlined directly
1172// into the parent function. We'll emit the other sites recursively as part
1173// of their parent inline site.
1174for (constDILocation *InlinedAt : FI.ChildSites) {
1175autoI = FI.InlineSites.find(InlinedAt);
1176assert(I != FI.InlineSites.end() &&
1177"child site not in function inline site map");
1178 emitInlinedCallSite(FI, InlinedAt,I->second);
1179 }
1180
1181for (auto Annot : FI.Annotations) {
1182MCSymbol *Label = Annot.first;
1183MDTuple *Strs = cast<MDTuple>(Annot.second);
1184MCSymbol *AnnotEnd = beginSymbolRecord(SymbolKind::S_ANNOTATION);
1185 OS.emitCOFFSecRel32(Label,/*Offset=*/0);
1186// FIXME: Make sure we don't overflow the max record size.
1187 OS.emitCOFFSectionIndex(Label);
1188 OS.emitInt16(Strs->getNumOperands());
1189for (Metadata *MD : Strs->operands()) {
1190// MDStrings are null terminated, so we can do EmitBytes and get the
1191// nice .asciz directive.
1192StringRef Str = cast<MDString>(MD)->getString();
1193assert(Str.data()[Str.size()] =='\0' &&"non-nullterminated MDString");
1194 OS.emitBytes(StringRef(Str.data(), Str.size() + 1));
1195 }
1196 endSymbolRecord(AnnotEnd);
1197 }
1198
1199for (auto HeapAllocSite : FI.HeapAllocSites) {
1200constMCSymbol *BeginLabel = std::get<0>(HeapAllocSite);
1201constMCSymbol *EndLabel = std::get<1>(HeapAllocSite);
1202constDIType *DITy = std::get<2>(HeapAllocSite);
1203MCSymbol *HeapAllocEnd = beginSymbolRecord(SymbolKind::S_HEAPALLOCSITE);
1204 OS.AddComment("Call site offset");
1205 OS.emitCOFFSecRel32(BeginLabel,/*Offset=*/0);
1206 OS.AddComment("Call site section index");
1207 OS.emitCOFFSectionIndex(BeginLabel);
1208 OS.AddComment("Call instruction length");
1209 OS.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 2);
1210 OS.AddComment("Type index");
1211 OS.emitInt32(getCompleteTypeIndex(DITy).getIndex());
1212 endSymbolRecord(HeapAllocEnd);
1213 }
1214
1215if (SP !=nullptr)
1216 emitDebugInfoForUDTs(LocalUDTs);
1217
1218 emitDebugInfoForJumpTables(FI);
1219
1220// We're done with this function.
1221 emitEndSymbolRecord(SymbolKind::S_PROC_ID_END);
1222 }
1223 endCVSubsection(SymbolsEnd);
1224
1225// We have an assembler directive that takes care of the whole line table.
1226 OS.emitCVLinetableDirective(FI.FuncId, Fn, FI.End);
1227}
1228
1229CodeViewDebug::LocalVarDef
1230CodeViewDebug::createDefRangeMem(uint16_t CVRegister,intOffset) {
1231 LocalVarDef DR;
1232 DR.InMemory = -1;
1233 DR.DataOffset =Offset;
1234assert(DR.DataOffset ==Offset &&"truncation");
1235 DR.IsSubfield = 0;
1236 DR.StructOffset = 0;
1237 DR.CVRegister = CVRegister;
1238return DR;
1239}
1240
1241void CodeViewDebug::collectVariableInfoFromMFTable(
1242DenseSet<InlinedEntity> &Processed) {
1243constMachineFunction &MF = *Asm->MF;
1244constTargetSubtargetInfo &TSI = MF.getSubtarget();
1245constTargetFrameLowering *TFI = TSI.getFrameLowering();
1246constTargetRegisterInfo *TRI = TSI.getRegisterInfo();
1247
1248for (constMachineFunction::VariableDbgInfo &VI :
1249 MF.getInStackSlotVariableDbgInfo()) {
1250if (!VI.Var)
1251continue;
1252assert(VI.Var->isValidLocationForIntrinsic(VI.Loc) &&
1253"Expected inlined-at fields to agree");
1254
1255 Processed.insert(InlinedEntity(VI.Var,VI.Loc->getInlinedAt()));
1256LexicalScope *Scope =LScopes.findLexicalScope(VI.Loc);
1257
1258// If variable scope is not found then skip this variable.
1259if (!Scope)
1260continue;
1261
1262// If the variable has an attached offset expression, extract it.
1263// FIXME: Try to handle DW_OP_deref as well.
1264 int64_t ExprOffset = 0;
1265bool Deref =false;
1266if (VI.Expr) {
1267// If there is one DW_OP_deref element, use offset of 0 and keep going.
1268if (VI.Expr->getNumElements() == 1 &&
1269VI.Expr->getElement(0) == llvm::dwarf::DW_OP_deref)
1270 Deref =true;
1271elseif (!VI.Expr->extractIfOffset(ExprOffset))
1272continue;
1273 }
1274
1275// Get the frame register used and the offset.
1276Register FrameReg;
1277StackOffset FrameOffset =
1278 TFI->getFrameIndexReference(*Asm->MF,VI.getStackSlot(), FrameReg);
1279uint16_t CVReg =TRI->getCodeViewRegNum(FrameReg);
1280
1281assert(!FrameOffset.getScalable() &&
1282"Frame offsets with a scalable component are not supported");
1283
1284// Calculate the label ranges.
1285 LocalVarDef DefRange =
1286 createDefRangeMem(CVReg, FrameOffset.getFixed() + ExprOffset);
1287
1288 LocalVariable Var;
1289 Var.DIVar =VI.Var;
1290
1291for (constInsnRange &Range :Scope->getRanges()) {
1292constMCSymbol *Begin =getLabelBeforeInsn(Range.first);
1293constMCSymbol *End =getLabelAfterInsn(Range.second);
1294End =End ?End :Asm->getFunctionEnd();
1295 Var.DefRanges[DefRange].emplace_back(Begin,End);
1296 }
1297
1298if (Deref)
1299 Var.UseReferenceType =true;
1300
1301 recordLocalVariable(std::move(Var), Scope);
1302 }
1303}
1304
1305staticboolcanUseReferenceType(constDbgVariableLocation &Loc) {
1306return !Loc.LoadChain.empty() && Loc.LoadChain.back() == 0;
1307}
1308
1309staticboolneedsReferenceType(constDbgVariableLocation &Loc) {
1310return Loc.LoadChain.size() == 2 && Loc.LoadChain.back() == 0;
1311}
1312
1313void CodeViewDebug::calculateRanges(
1314 LocalVariable &Var,constDbgValueHistoryMap::Entries &Entries) {
1315constTargetRegisterInfo *TRI =Asm->MF->getSubtarget().getRegisterInfo();
1316
1317// Calculate the definition ranges.
1318for (autoI = Entries.begin(), E = Entries.end();I != E; ++I) {
1319constauto &Entry = *I;
1320if (!Entry.isDbgValue())
1321continue;
1322constMachineInstr *DVInst =Entry.getInstr();
1323assert(DVInst->isDebugValue() &&"Invalid History entry");
1324// FIXME: Find a way to represent constant variables, since they are
1325// relatively common.
1326 std::optional<DbgVariableLocation>Location =
1327DbgVariableLocation::extractFromMachineInstruction(*DVInst);
1328if (!Location)
1329 {
1330// When we don't have a location this is usually because LLVM has
1331// transformed it into a constant and we only have an llvm.dbg.value. We
1332// can't represent these well in CodeView since S_LOCAL only works on
1333// registers and memory locations. Instead, we will pretend this to be a
1334// constant value to at least have it show up in the debugger.
1335autoOp = DVInst->getDebugOperand(0);
1336if (Op.isImm())
1337 Var.ConstantValue =APSInt(APInt(64,Op.getImm()),false);
1338continue;
1339 }
1340
1341// CodeView can only express variables in register and variables in memory
1342// at a constant offset from a register. However, for variables passed
1343// indirectly by pointer, it is common for that pointer to be spilled to a
1344// stack location. For the special case of one offseted load followed by a
1345// zero offset load (a pointer spilled to the stack), we change the type of
1346// the local variable from a value type to a reference type. This tricks the
1347// debugger into doing the load for us.
1348if (Var.UseReferenceType) {
1349// We're using a reference type. Drop the last zero offset load.
1350if (canUseReferenceType(*Location))
1351Location->LoadChain.pop_back();
1352else
1353continue;
1354 }elseif (needsReferenceType(*Location)) {
1355// This location can't be expressed without switching to a reference type.
1356// Start over using that.
1357 Var.UseReferenceType =true;
1358 Var.DefRanges.clear();
1359 calculateRanges(Var, Entries);
1360return;
1361 }
1362
1363// We can only handle a register or an offseted load of a register.
1364if (Location->Register == 0 ||Location->LoadChain.size() > 1)
1365continue;
1366
1367// Codeview can only express byte-aligned offsets, ensure that we have a
1368// byte-boundaried location.
1369if (Location->FragmentInfo)
1370if (Location->FragmentInfo->OffsetInBits % 8)
1371continue;
1372
1373 LocalVarDef DR;
1374 DR.CVRegister =TRI->getCodeViewRegNum(Location->Register);
1375 DR.InMemory = !Location->LoadChain.empty();
1376 DR.DataOffset =
1377 !Location->LoadChain.empty() ?Location->LoadChain.back() : 0;
1378if (Location->FragmentInfo) {
1379 DR.IsSubfield =true;
1380 DR.StructOffset =Location->FragmentInfo->OffsetInBits / 8;
1381 }else {
1382 DR.IsSubfield =false;
1383 DR.StructOffset = 0;
1384 }
1385
1386// Compute the label range.
1387constMCSymbol *Begin =getLabelBeforeInsn(Entry.getInstr());
1388constMCSymbol *End;
1389if (Entry.getEndIndex() !=DbgValueHistoryMap::NoEntry) {
1390auto &EndingEntry = Entries[Entry.getEndIndex()];
1391End = EndingEntry.isDbgValue()
1392 ?getLabelBeforeInsn(EndingEntry.getInstr())
1393 :getLabelAfterInsn(EndingEntry.getInstr());
1394 }else
1395End =Asm->getFunctionEnd();
1396
1397// If the last range end is our begin, just extend the last range.
1398// Otherwise make a new range.
1399SmallVectorImpl<std::pair<const MCSymbol *, const MCSymbol *>> &R =
1400 Var.DefRanges[DR];
1401if (!R.empty() &&R.back().second == Begin)
1402R.back().second =End;
1403else
1404R.emplace_back(Begin,End);
1405
1406// FIXME: Do more range combining.
1407 }
1408}
1409
1410void CodeViewDebug::collectVariableInfo(constDISubprogram *SP) {
1411DenseSet<InlinedEntity> Processed;
1412// Grab the variable info that was squirreled away in the MMI side-table.
1413 collectVariableInfoFromMFTable(Processed);
1414
1415for (constauto &I :DbgValues) {
1416 InlinedEntityIV =I.first;
1417if (Processed.count(IV))
1418continue;
1419constDILocalVariable *DIVar = cast<DILocalVariable>(IV.first);
1420constDILocation *InlinedAt =IV.second;
1421
1422// Instruction ranges, specifying where IV is accessible.
1423constauto &Entries =I.second;
1424
1425LexicalScope *Scope =nullptr;
1426if (InlinedAt)
1427Scope =LScopes.findInlinedScope(DIVar->getScope(), InlinedAt);
1428else
1429Scope =LScopes.findLexicalScope(DIVar->getScope());
1430// If variable scope is not found then skip this variable.
1431if (!Scope)
1432continue;
1433
1434 LocalVariable Var;
1435 Var.DIVar = DIVar;
1436
1437 calculateRanges(Var, Entries);
1438 recordLocalVariable(std::move(Var), Scope);
1439 }
1440}
1441
1442voidCodeViewDebug::beginFunctionImpl(constMachineFunction *MF) {
1443constTargetSubtargetInfo &TSI = MF->getSubtarget();
1444constTargetRegisterInfo *TRI = TSI.getRegisterInfo();
1445constMachineFrameInfo &MFI = MF->getFrameInfo();
1446constFunction &GV = MF->getFunction();
1447auto Insertion = FnDebugInfo.insert({&GV, std::make_unique<FunctionInfo>()});
1448assert(Insertion.second &&"function already has info");
1449 CurFn = Insertion.first->second.get();
1450 CurFn->FuncId = NextFuncId++;
1451 CurFn->Begin =Asm->getFunctionBegin();
1452
1453// The S_FRAMEPROC record reports the stack size, and how many bytes of
1454// callee-saved registers were used. For targets that don't use a PUSH
1455// instruction (AArch64), this will be zero.
1456 CurFn->CSRSize = MFI.getCVBytesOfCalleeSavedRegisters();
1457 CurFn->FrameSize = MFI.getStackSize();
1458 CurFn->OffsetAdjustment = MFI.getOffsetAdjustment();
1459 CurFn->HasStackRealignment =TRI->hasStackRealignment(*MF);
1460
1461// For this function S_FRAMEPROC record, figure out which codeview register
1462// will be the frame pointer.
1463 CurFn->EncodedParamFramePtrReg = EncodedFramePtrReg::None;// None.
1464 CurFn->EncodedLocalFramePtrReg = EncodedFramePtrReg::None;// None.
1465if (CurFn->FrameSize > 0) {
1466if (!TSI.getFrameLowering()->hasFP(*MF)) {
1467 CurFn->EncodedLocalFramePtrReg = EncodedFramePtrReg::StackPtr;
1468 CurFn->EncodedParamFramePtrReg = EncodedFramePtrReg::StackPtr;
1469 }else {
1470 CurFn->HasFramePointer =true;
1471// If there is an FP, parameters are always relative to it.
1472 CurFn->EncodedParamFramePtrReg = EncodedFramePtrReg::FramePtr;
1473if (CurFn->HasStackRealignment) {
1474// If the stack needs realignment, locals are relative to SP or VFRAME.
1475 CurFn->EncodedLocalFramePtrReg = EncodedFramePtrReg::StackPtr;
1476 }else {
1477// Otherwise, locals are relative to EBP, and we probably have VLAs or
1478// other stack adjustments.
1479 CurFn->EncodedLocalFramePtrReg = EncodedFramePtrReg::FramePtr;
1480 }
1481 }
1482 }
1483
1484// Compute other frame procedure options.
1485FrameProcedureOptions FPO = FrameProcedureOptions::None;
1486if (MFI.hasVarSizedObjects())
1487 FPO |= FrameProcedureOptions::HasAlloca;
1488if (MF->exposesReturnsTwice())
1489 FPO |= FrameProcedureOptions::HasSetJmp;
1490// FIXME: Set HasLongJmp if we ever track that info.
1491if (MF->hasInlineAsm())
1492 FPO |= FrameProcedureOptions::HasInlineAssembly;
1493if (GV.hasPersonalityFn()) {
1494if (isAsynchronousEHPersonality(
1495classifyEHPersonality(GV.getPersonalityFn())))
1496 FPO |= FrameProcedureOptions::HasStructuredExceptionHandling;
1497else
1498 FPO |= FrameProcedureOptions::HasExceptionHandling;
1499 }
1500if (GV.hasFnAttribute(Attribute::InlineHint))
1501 FPO |= FrameProcedureOptions::MarkedInline;
1502if (GV.hasFnAttribute(Attribute::Naked))
1503 FPO |= FrameProcedureOptions::Naked;
1504if (MFI.hasStackProtectorIndex()) {
1505 FPO |= FrameProcedureOptions::SecurityChecks;
1506if (GV.hasFnAttribute(Attribute::StackProtectStrong) ||
1507 GV.hasFnAttribute(Attribute::StackProtectReq)) {
1508 FPO |= FrameProcedureOptions::StrictSecurityChecks;
1509 }
1510 }elseif (!GV.hasStackProtectorFnAttr()) {
1511// __declspec(safebuffers) disables stack guards.
1512 FPO |= FrameProcedureOptions::SafeBuffers;
1513 }
1514 FPO |=FrameProcedureOptions(uint32_t(CurFn->EncodedLocalFramePtrReg) << 14U);
1515 FPO |=FrameProcedureOptions(uint32_t(CurFn->EncodedParamFramePtrReg) << 16U);
1516if (Asm->TM.getOptLevel() !=CodeGenOptLevel::None && !GV.hasOptSize() &&
1517 !GV.hasOptNone())
1518 FPO |= FrameProcedureOptions::OptimizedForSpeed;
1519if (GV.hasProfileData()) {
1520 FPO |= FrameProcedureOptions::ValidProfileCounts;
1521 FPO |= FrameProcedureOptions::ProfileGuidedOptimization;
1522 }
1523// FIXME: Set GuardCfg when it is implemented.
1524 CurFn->FrameProcOpts = FPO;
1525
1526 OS.emitCVFuncIdDirective(CurFn->FuncId);
1527
1528// Find the end of the function prolog. First known non-DBG_VALUE and
1529// non-frame setup location marks the beginning of the function body.
1530// FIXME: is there a simpler a way to do this? Can we just search
1531// for the first instruction of the function, not the last of the prolog?
1532DebugLocPrologEndLoc;
1533bool EmptyPrologue =true;
1534for (constauto &MBB : *MF) {
1535for (constauto &MI :MBB) {
1536if (!MI.isMetaInstruction() && !MI.getFlag(MachineInstr::FrameSetup) &&
1537MI.getDebugLoc()) {
1538PrologEndLoc =MI.getDebugLoc();
1539break;
1540 }elseif (!MI.isMetaInstruction()) {
1541 EmptyPrologue =false;
1542 }
1543 }
1544 }
1545
1546// Record beginning of function if we have a non-empty prologue.
1547if (PrologEndLoc && !EmptyPrologue) {
1548DebugLoc FnStartDL =PrologEndLoc.getFnDebugLoc();
1549 maybeRecordLocation(FnStartDL, MF);
1550 }
1551
1552// Find heap alloc sites and emit labels around them.
1553for (constauto &MBB : *MF) {
1554for (constauto &MI :MBB) {
1555if (MI.getHeapAllocMarker()) {
1556requestLabelBeforeInsn(&MI);
1557requestLabelAfterInsn(&MI);
1558 }
1559 }
1560 }
1561
1562// Mark branches that may potentially be using jump tables with labels.
1563boolisThumb =Triple(MMI->getModule()->getTargetTriple()).getArch() ==
1564llvm::Triple::ArchType::thumb;
1565 discoverJumpTableBranches(MF,isThumb);
1566}
1567
1568staticboolshouldEmitUdt(constDIType *T) {
1569if (!T)
1570returnfalse;
1571
1572// MSVC does not emit UDTs for typedefs that are scoped to classes.
1573if (T->getTag() == dwarf::DW_TAG_typedef) {
1574if (DIScope *Scope =T->getScope()) {
1575switch (Scope->getTag()) {
1576case dwarf::DW_TAG_structure_type:
1577case dwarf::DW_TAG_class_type:
1578case dwarf::DW_TAG_union_type:
1579returnfalse;
1580default:
1581// do nothing.
1582 ;
1583 }
1584 }
1585 }
1586
1587while (true) {
1588if (!T ||T->isForwardDecl())
1589returnfalse;
1590
1591constDIDerivedType *DT = dyn_cast<DIDerivedType>(T);
1592if (!DT)
1593returntrue;
1594T = DT->getBaseType();
1595 }
1596returntrue;
1597}
1598
1599void CodeViewDebug::addToUDTs(constDIType *Ty) {
1600// Don't record empty UDTs.
1601if (Ty->getName().empty())
1602return;
1603if (!shouldEmitUdt(Ty))
1604return;
1605
1606SmallVector<StringRef, 5> ParentScopeNames;
1607constDISubprogram *ClosestSubprogram =
1608 collectParentScopeNames(Ty->getScope(), ParentScopeNames);
1609
1610 std::string FullyQualifiedName =
1611formatNestedName(ParentScopeNames,getPrettyScopeName(Ty));
1612
1613if (ClosestSubprogram ==nullptr) {
1614 GlobalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);
1615 }elseif (ClosestSubprogram == CurrentSubprogram) {
1616 LocalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);
1617 }
1618
1619// TODO: What if the ClosestSubprogram is neither null or the current
1620// subprogram? Currently, the UDT just gets dropped on the floor.
1621//
1622// The current behavior is not desirable. To get maximal fidelity, we would
1623// need to perform all type translation before beginning emission of .debug$S
1624// and then make LocalUDTs a member of FunctionInfo
1625}
1626
1627TypeIndex CodeViewDebug::lowerType(constDIType *Ty,constDIType *ClassTy) {
1628// Generic dispatch for lowering an unknown type.
1629switch (Ty->getTag()) {
1630case dwarf::DW_TAG_array_type:
1631return lowerTypeArray(cast<DICompositeType>(Ty));
1632case dwarf::DW_TAG_typedef:
1633return lowerTypeAlias(cast<DIDerivedType>(Ty));
1634case dwarf::DW_TAG_base_type:
1635return lowerTypeBasic(cast<DIBasicType>(Ty));
1636case dwarf::DW_TAG_pointer_type:
1637if (cast<DIDerivedType>(Ty)->getName() =="__vtbl_ptr_type")
1638return lowerTypeVFTableShape(cast<DIDerivedType>(Ty));
1639 [[fallthrough]];
1640case dwarf::DW_TAG_reference_type:
1641case dwarf::DW_TAG_rvalue_reference_type:
1642return lowerTypePointer(cast<DIDerivedType>(Ty));
1643case dwarf::DW_TAG_ptr_to_member_type:
1644return lowerTypeMemberPointer(cast<DIDerivedType>(Ty));
1645case dwarf::DW_TAG_restrict_type:
1646case dwarf::DW_TAG_const_type:
1647case dwarf::DW_TAG_volatile_type:
1648// TODO: add support for DW_TAG_atomic_type here
1649return lowerTypeModifier(cast<DIDerivedType>(Ty));
1650case dwarf::DW_TAG_subroutine_type:
1651if (ClassTy) {
1652// The member function type of a member function pointer has no
1653// ThisAdjustment.
1654return lowerTypeMemberFunction(cast<DISubroutineType>(Ty), ClassTy,
1655/*ThisAdjustment=*/0,
1656/*IsStaticMethod=*/false);
1657 }
1658return lowerTypeFunction(cast<DISubroutineType>(Ty));
1659case dwarf::DW_TAG_enumeration_type:
1660return lowerTypeEnum(cast<DICompositeType>(Ty));
1661case dwarf::DW_TAG_class_type:
1662case dwarf::DW_TAG_structure_type:
1663return lowerTypeClass(cast<DICompositeType>(Ty));
1664case dwarf::DW_TAG_union_type:
1665return lowerTypeUnion(cast<DICompositeType>(Ty));
1666case dwarf::DW_TAG_string_type:
1667return lowerTypeString(cast<DIStringType>(Ty));
1668case dwarf::DW_TAG_unspecified_type:
1669if (Ty->getName() =="decltype(nullptr)")
1670returnTypeIndex::NullptrT();
1671returnTypeIndex::None();
1672default:
1673// Use the null type index.
1674returnTypeIndex();
1675 }
1676}
1677
1678TypeIndex CodeViewDebug::lowerTypeAlias(constDIDerivedType *Ty) {
1679TypeIndex UnderlyingTypeIndex = getTypeIndex(Ty->getBaseType());
1680StringRefTypeName = Ty->getName();
1681
1682 addToUDTs(Ty);
1683
1684if (UnderlyingTypeIndex ==TypeIndex(SimpleTypeKind::Int32Long) &&
1685 TypeName =="HRESULT")
1686returnTypeIndex(SimpleTypeKind::HResult);
1687if (UnderlyingTypeIndex ==TypeIndex(SimpleTypeKind::UInt16Short) &&
1688 TypeName =="wchar_t")
1689returnTypeIndex(SimpleTypeKind::WideCharacter);
1690
1691return UnderlyingTypeIndex;
1692}
1693
1694TypeIndex CodeViewDebug::lowerTypeArray(constDICompositeType *Ty) {
1695constDIType *ElementType = Ty->getBaseType();
1696TypeIndex ElementTypeIndex = getTypeIndex(ElementType);
1697// IndexType is size_t, which depends on the bitness of the target.
1698TypeIndex IndexType = getPointerSizeInBytes() == 8
1699 ?TypeIndex(SimpleTypeKind::UInt64Quad)
1700 :TypeIndex(SimpleTypeKind::UInt32Long);
1701
1702uint64_t ElementSize =getBaseTypeSize(ElementType) / 8;
1703
1704// Add subranges to array type.
1705 DINodeArrayElements = Ty->getElements();
1706for (int i =Elements.size() - 1; i >= 0; --i) {
1707constDINode *Element =Elements[i];
1708assert(Element->getTag() == dwarf::DW_TAG_subrange_type);
1709
1710constDISubrange *Subrange = cast<DISubrange>(Element);
1711 int64_t Count = -1;
1712
1713// If Subrange has a Count field, use it.
1714// Otherwise, if it has an upperboud, use (upperbound - lowerbound + 1),
1715// where lowerbound is from the LowerBound field of the Subrange,
1716// or the language default lowerbound if that field is unspecified.
1717if (auto *CI = dyn_cast_if_present<ConstantInt *>(Subrange->getCount()))
1718 Count = CI->getSExtValue();
1719elseif (auto *UI = dyn_cast_if_present<ConstantInt *>(
1720Subrange->getUpperBound())) {
1721// Fortran uses 1 as the default lowerbound; other languages use 0.
1722 int64_t Lowerbound = (moduleIsInFortran()) ? 1 : 0;
1723auto *LI = dyn_cast_if_present<ConstantInt *>(Subrange->getLowerBound());
1724 Lowerbound = (LI) ? LI->getSExtValue() : Lowerbound;
1725 Count = UI->getSExtValue() - Lowerbound + 1;
1726 }
1727
1728// Forward declarations of arrays without a size and VLAs use a count of -1.
1729// Emit a count of zero in these cases to match what MSVC does for arrays
1730// without a size. MSVC doesn't support VLAs, so it's not clear what we
1731// should do for them even if we could distinguish them.
1732if (Count == -1)
1733 Count = 0;
1734
1735// Update the element size and element type index for subsequent subranges.
1736 ElementSize *= Count;
1737
1738// If this is the outermost array, use the size from the array. It will be
1739// more accurate if we had a VLA or an incomplete element type size.
1740uint64_t ArraySize =
1741 (i == 0 && ElementSize == 0) ? Ty->getSizeInBits() / 8 : ElementSize;
1742
1743StringRefName = (i == 0) ? Ty->getName() :"";
1744ArrayRecord AR(ElementTypeIndex, IndexType, ArraySize,Name);
1745 ElementTypeIndex = TypeTable.writeLeafType(AR);
1746 }
1747
1748return ElementTypeIndex;
1749}
1750
1751// This function lowers a Fortran character type (DIStringType).
1752// Note that it handles only the character*n variant (using SizeInBits
1753// field in DIString to describe the type size) at the moment.
1754// Other variants (leveraging the StringLength and StringLengthExp
1755// fields in DIStringType) remain TBD.
1756TypeIndex CodeViewDebug::lowerTypeString(constDIStringType *Ty) {
1757TypeIndex CharType =TypeIndex(SimpleTypeKind::NarrowCharacter);
1758uint64_t ArraySize = Ty->getSizeInBits() >> 3;
1759StringRefName = Ty->getName();
1760// IndexType is size_t, which depends on the bitness of the target.
1761TypeIndex IndexType = getPointerSizeInBytes() == 8
1762 ?TypeIndex(SimpleTypeKind::UInt64Quad)
1763 :TypeIndex(SimpleTypeKind::UInt32Long);
1764
1765// Create a type of character array of ArraySize.
1766ArrayRecord AR(CharType, IndexType, ArraySize,Name);
1767
1768return TypeTable.writeLeafType(AR);
1769}
1770
1771TypeIndex CodeViewDebug::lowerTypeBasic(constDIBasicType *Ty) {
1772TypeIndexIndex;
1773dwarf::TypeKindKind;
1774uint32_t ByteSize;
1775
1776Kind =static_cast<dwarf::TypeKind>(Ty->getEncoding());
1777 ByteSize = Ty->getSizeInBits() / 8;
1778
1779SimpleTypeKind STK = SimpleTypeKind::None;
1780switch (Kind) {
1781case dwarf::DW_ATE_address:
1782// FIXME: Translate
1783break;
1784case dwarf::DW_ATE_boolean:
1785switch (ByteSize) {
1786case 1: STK = SimpleTypeKind::Boolean8;break;
1787case 2: STK = SimpleTypeKind::Boolean16;break;
1788case 4: STK = SimpleTypeKind::Boolean32;break;
1789case 8: STK = SimpleTypeKind::Boolean64;break;
1790case 16: STK = SimpleTypeKind::Boolean128;break;
1791 }
1792break;
1793case dwarf::DW_ATE_complex_float:
1794// The CodeView size for a complex represents the size of
1795// an individual component.
1796switch (ByteSize) {
1797case 4: STK = SimpleTypeKind::Complex16;break;
1798case 8: STK = SimpleTypeKind::Complex32;break;
1799case 16: STK = SimpleTypeKind::Complex64;break;
1800case 20: STK = SimpleTypeKind::Complex80;break;
1801case 32: STK = SimpleTypeKind::Complex128;break;
1802 }
1803break;
1804case dwarf::DW_ATE_float:
1805switch (ByteSize) {
1806case 2: STK = SimpleTypeKind::Float16;break;
1807case 4: STK = SimpleTypeKind::Float32;break;
1808case 6: STK = SimpleTypeKind::Float48;break;
1809case 8: STK = SimpleTypeKind::Float64;break;
1810case 10: STK = SimpleTypeKind::Float80;break;
1811case 16: STK = SimpleTypeKind::Float128;break;
1812 }
1813break;
1814case dwarf::DW_ATE_signed:
1815switch (ByteSize) {
1816case 1: STK = SimpleTypeKind::SignedCharacter;break;
1817case 2: STK = SimpleTypeKind::Int16Short;break;
1818case 4: STK = SimpleTypeKind::Int32;break;
1819case 8: STK = SimpleTypeKind::Int64Quad;break;
1820case 16: STK = SimpleTypeKind::Int128Oct;break;
1821 }
1822break;
1823case dwarf::DW_ATE_unsigned:
1824switch (ByteSize) {
1825case 1: STK = SimpleTypeKind::UnsignedCharacter;break;
1826case 2: STK = SimpleTypeKind::UInt16Short;break;
1827case 4: STK = SimpleTypeKind::UInt32;break;
1828case 8: STK = SimpleTypeKind::UInt64Quad;break;
1829case 16: STK = SimpleTypeKind::UInt128Oct;break;
1830 }
1831break;
1832case dwarf::DW_ATE_UTF:
1833switch (ByteSize) {
1834case 1: STK = SimpleTypeKind::Character8;break;
1835case 2: STK = SimpleTypeKind::Character16;break;
1836case 4: STK = SimpleTypeKind::Character32;break;
1837 }
1838break;
1839case dwarf::DW_ATE_signed_char:
1840if (ByteSize == 1)
1841 STK = SimpleTypeKind::SignedCharacter;
1842break;
1843case dwarf::DW_ATE_unsigned_char:
1844if (ByteSize == 1)
1845 STK = SimpleTypeKind::UnsignedCharacter;
1846break;
1847default:
1848break;
1849 }
1850
1851// Apply some fixups based on the source-level type name.
1852// Include some amount of canonicalization from an old naming scheme Clang
1853// used to use for integer types (in an outdated effort to be compatible with
1854// GCC's debug info/GDB's behavior, which has since been addressed).
1855if (STK == SimpleTypeKind::Int32 &&
1856 (Ty->getName() =="long int" || Ty->getName() =="long"))
1857 STK = SimpleTypeKind::Int32Long;
1858if (STK == SimpleTypeKind::UInt32 && (Ty->getName() =="long unsigned int" ||
1859 Ty->getName() =="unsigned long"))
1860 STK = SimpleTypeKind::UInt32Long;
1861if (STK == SimpleTypeKind::UInt16Short &&
1862 (Ty->getName() =="wchar_t" || Ty->getName() =="__wchar_t"))
1863 STK = SimpleTypeKind::WideCharacter;
1864if ((STK == SimpleTypeKind::SignedCharacter ||
1865 STK == SimpleTypeKind::UnsignedCharacter) &&
1866 Ty->getName() =="char")
1867 STK = SimpleTypeKind::NarrowCharacter;
1868
1869returnTypeIndex(STK);
1870}
1871
1872TypeIndex CodeViewDebug::lowerTypePointer(constDIDerivedType *Ty,
1873PointerOptions PO) {
1874TypeIndex PointeeTI = getTypeIndex(Ty->getBaseType());
1875
1876// Pointers to simple types without any options can use SimpleTypeMode, rather
1877// than having a dedicated pointer type record.
1878if (PointeeTI.isSimple() && PO == PointerOptions::None &&
1879 PointeeTI.getSimpleMode() == SimpleTypeMode::Direct &&
1880 Ty->getTag() == dwarf::DW_TAG_pointer_type) {
1881SimpleTypeModeMode = Ty->getSizeInBits() == 64
1882 ? SimpleTypeMode::NearPointer64
1883 : SimpleTypeMode::NearPointer32;
1884returnTypeIndex(PointeeTI.getSimpleKind(), Mode);
1885 }
1886
1887PointerKind PK =
1888 Ty->getSizeInBits() == 64 ? PointerKind::Near64 : PointerKind::Near32;
1889PointerMode PM = PointerMode::Pointer;
1890switch (Ty->getTag()) {
1891default:llvm_unreachable("not a pointer tag type");
1892case dwarf::DW_TAG_pointer_type:
1893 PM = PointerMode::Pointer;
1894break;
1895case dwarf::DW_TAG_reference_type:
1896 PM = PointerMode::LValueReference;
1897break;
1898case dwarf::DW_TAG_rvalue_reference_type:
1899 PM = PointerMode::RValueReference;
1900break;
1901 }
1902
1903if (Ty->isObjectPointer())
1904 PO |= PointerOptions::Const;
1905
1906PointerRecord PR(PointeeTI, PK, PM, PO, Ty->getSizeInBits() / 8);
1907return TypeTable.writeLeafType(PR);
1908}
1909
1910staticPointerToMemberRepresentation
1911translatePtrToMemberRep(unsigned SizeInBytes,bool IsPMF,unsigned Flags) {
1912// SizeInBytes being zero generally implies that the member pointer type was
1913// incomplete, which can happen if it is part of a function prototype. In this
1914// case, use the unknown model instead of the general model.
1915if (IsPMF) {
1916switch (Flags &DINode::FlagPtrToMemberRep) {
1917case 0:
1918return SizeInBytes == 0 ? PointerToMemberRepresentation::Unknown
1919 : PointerToMemberRepresentation::GeneralFunction;
1920case DINode::FlagSingleInheritance:
1921return PointerToMemberRepresentation::SingleInheritanceFunction;
1922case DINode::FlagMultipleInheritance:
1923return PointerToMemberRepresentation::MultipleInheritanceFunction;
1924case DINode::FlagVirtualInheritance:
1925return PointerToMemberRepresentation::VirtualInheritanceFunction;
1926 }
1927 }else {
1928switch (Flags &DINode::FlagPtrToMemberRep) {
1929case 0:
1930return SizeInBytes == 0 ? PointerToMemberRepresentation::Unknown
1931 : PointerToMemberRepresentation::GeneralData;
1932case DINode::FlagSingleInheritance:
1933return PointerToMemberRepresentation::SingleInheritanceData;
1934case DINode::FlagMultipleInheritance:
1935return PointerToMemberRepresentation::MultipleInheritanceData;
1936case DINode::FlagVirtualInheritance:
1937return PointerToMemberRepresentation::VirtualInheritanceData;
1938 }
1939 }
1940llvm_unreachable("invalid ptr to member representation");
1941}
1942
1943TypeIndex CodeViewDebug::lowerTypeMemberPointer(constDIDerivedType *Ty,
1944PointerOptions PO) {
1945assert(Ty->getTag() == dwarf::DW_TAG_ptr_to_member_type);
1946bool IsPMF = isa<DISubroutineType>(Ty->getBaseType());
1947TypeIndex ClassTI = getTypeIndex(Ty->getClassType());
1948TypeIndex PointeeTI =
1949 getTypeIndex(Ty->getBaseType(), IsPMF ? Ty->getClassType() :nullptr);
1950PointerKind PK = getPointerSizeInBytes() == 8 ? PointerKind::Near64
1951 : PointerKind::Near32;
1952PointerMode PM = IsPMF ? PointerMode::PointerToMemberFunction
1953 : PointerMode::PointerToDataMember;
1954
1955assert(Ty->getSizeInBits() / 8 <= 0xff &&"pointer size too big");
1956uint8_t SizeInBytes = Ty->getSizeInBits() / 8;
1957MemberPointerInfo MPI(
1958 ClassTI,translatePtrToMemberRep(SizeInBytes, IsPMF, Ty->getFlags()));
1959PointerRecord PR(PointeeTI, PK, PM, PO, SizeInBytes, MPI);
1960return TypeTable.writeLeafType(PR);
1961}
1962
1963/// Given a DWARF calling convention, get the CodeView equivalent. If we don't
1964/// have a translation, use the NearC convention.
1965staticCallingConventiondwarfCCToCodeView(unsigned DwarfCC) {
1966switch (DwarfCC) {
1967case dwarf::DW_CC_normal:return CallingConvention::NearC;
1968case dwarf::DW_CC_BORLAND_msfastcall:return CallingConvention::NearFast;
1969case dwarf::DW_CC_BORLAND_thiscall:return CallingConvention::ThisCall;
1970case dwarf::DW_CC_BORLAND_stdcall:return CallingConvention::NearStdCall;
1971case dwarf::DW_CC_BORLAND_pascal:return CallingConvention::NearPascal;
1972case dwarf::DW_CC_LLVM_vectorcall:return CallingConvention::NearVector;
1973 }
1974return CallingConvention::NearC;
1975}
1976
1977TypeIndex CodeViewDebug::lowerTypeModifier(constDIDerivedType *Ty) {
1978ModifierOptions Mods = ModifierOptions::None;
1979PointerOptions PO = PointerOptions::None;
1980boolIsModifier =true;
1981constDIType *BaseTy = Ty;
1982while (IsModifier &&BaseTy) {
1983// FIXME: Need to add DWARF tags for __unaligned and _Atomic
1984switch (BaseTy->getTag()) {
1985case dwarf::DW_TAG_const_type:
1986 Mods |= ModifierOptions::Const;
1987 PO |= PointerOptions::Const;
1988break;
1989case dwarf::DW_TAG_volatile_type:
1990 Mods |= ModifierOptions::Volatile;
1991 PO |= PointerOptions::Volatile;
1992break;
1993case dwarf::DW_TAG_restrict_type:
1994// Only pointer types be marked with __restrict. There is no known flag
1995// for __restrict in LF_MODIFIER records.
1996 PO |= PointerOptions::Restrict;
1997break;
1998default:
1999IsModifier =false;
2000break;
2001 }
2002if (IsModifier)
2003BaseTy = cast<DIDerivedType>(BaseTy)->getBaseType();
2004 }
2005
2006// Check if the inner type will use an LF_POINTER record. If so, the
2007// qualifiers will go in the LF_POINTER record. This comes up for types like
2008// 'int *const' and 'int *__restrict', not the more common cases like 'const
2009// char *'.
2010if (BaseTy) {
2011switch (BaseTy->getTag()) {
2012case dwarf::DW_TAG_pointer_type:
2013case dwarf::DW_TAG_reference_type:
2014case dwarf::DW_TAG_rvalue_reference_type:
2015return lowerTypePointer(cast<DIDerivedType>(BaseTy), PO);
2016case dwarf::DW_TAG_ptr_to_member_type:
2017return lowerTypeMemberPointer(cast<DIDerivedType>(BaseTy), PO);
2018default:
2019break;
2020 }
2021 }
2022
2023TypeIndex ModifiedTI = getTypeIndex(BaseTy);
2024
2025// Return the base type index if there aren't any modifiers. For example, the
2026// metadata could contain restrict wrappers around non-pointer types.
2027if (Mods == ModifierOptions::None)
2028return ModifiedTI;
2029
2030ModifierRecord MR(ModifiedTI, Mods);
2031return TypeTable.writeLeafType(MR);
2032}
2033
2034TypeIndex CodeViewDebug::lowerTypeFunction(constDISubroutineType *Ty) {
2035SmallVector<TypeIndex, 8> ReturnAndArgTypeIndices;
2036for (constDIType *ArgType : Ty->getTypeArray())
2037 ReturnAndArgTypeIndices.push_back(getTypeIndex(ArgType));
2038
2039// MSVC uses type none for variadic argument.
2040if (ReturnAndArgTypeIndices.size() > 1 &&
2041 ReturnAndArgTypeIndices.back() ==TypeIndex::Void()) {
2042 ReturnAndArgTypeIndices.back() =TypeIndex::None();
2043 }
2044TypeIndex ReturnTypeIndex =TypeIndex::Void();
2045ArrayRef<TypeIndex> ArgTypeIndices = {};
2046if (!ReturnAndArgTypeIndices.empty()) {
2047auto ReturnAndArgTypesRef =ArrayRef(ReturnAndArgTypeIndices);
2048 ReturnTypeIndex = ReturnAndArgTypesRef.front();
2049 ArgTypeIndices = ReturnAndArgTypesRef.drop_front();
2050 }
2051
2052ArgListRecord ArgListRec(TypeRecordKind::ArgList, ArgTypeIndices);
2053TypeIndex ArgListIndex = TypeTable.writeLeafType(ArgListRec);
2054
2055CallingConventionCC =dwarfCCToCodeView(Ty->getCC());
2056
2057FunctionOptions FO =getFunctionOptions(Ty);
2058ProcedureRecord Procedure(ReturnTypeIndex,CC, FO, ArgTypeIndices.size(),
2059 ArgListIndex);
2060return TypeTable.writeLeafType(Procedure);
2061}
2062
2063TypeIndex CodeViewDebug::lowerTypeMemberFunction(constDISubroutineType *Ty,
2064constDIType *ClassTy,
2065int ThisAdjustment,
2066bool IsStaticMethod,
2067FunctionOptions FO) {
2068// Lower the containing class type.
2069TypeIndex ClassType = getTypeIndex(ClassTy);
2070
2071DITypeRefArray ReturnAndArgs = Ty->getTypeArray();
2072
2073unsignedIndex = 0;
2074SmallVector<TypeIndex, 8> ArgTypeIndices;
2075TypeIndex ReturnTypeIndex =TypeIndex::Void();
2076if (ReturnAndArgs.size() > Index) {
2077 ReturnTypeIndex = getTypeIndex(ReturnAndArgs[Index++]);
2078 }
2079
2080// If the first argument is a pointer type and this isn't a static method,
2081// treat it as the special 'this' parameter, which is encoded separately from
2082// the arguments.
2083TypeIndex ThisTypeIndex;
2084if (!IsStaticMethod && ReturnAndArgs.size() > Index) {
2085if (constDIDerivedType *PtrTy =
2086 dyn_cast_or_null<DIDerivedType>(ReturnAndArgs[Index])) {
2087if (PtrTy->getTag() == dwarf::DW_TAG_pointer_type) {
2088 ThisTypeIndex = getTypeIndexForThisPtr(PtrTy, Ty);
2089Index++;
2090 }
2091 }
2092 }
2093
2094while (Index < ReturnAndArgs.size())
2095 ArgTypeIndices.push_back(getTypeIndex(ReturnAndArgs[Index++]));
2096
2097// MSVC uses type none for variadic argument.
2098if (!ArgTypeIndices.empty() && ArgTypeIndices.back() ==TypeIndex::Void())
2099 ArgTypeIndices.back() =TypeIndex::None();
2100
2101ArgListRecord ArgListRec(TypeRecordKind::ArgList, ArgTypeIndices);
2102TypeIndex ArgListIndex = TypeTable.writeLeafType(ArgListRec);
2103
2104CallingConventionCC =dwarfCCToCodeView(Ty->getCC());
2105
2106MemberFunctionRecord MFR(ReturnTypeIndex, ClassType, ThisTypeIndex,CC, FO,
2107 ArgTypeIndices.size(), ArgListIndex, ThisAdjustment);
2108return TypeTable.writeLeafType(MFR);
2109}
2110
2111TypeIndex CodeViewDebug::lowerTypeVFTableShape(constDIDerivedType *Ty) {
2112unsigned VSlotCount =
2113 Ty->getSizeInBits() / (8 *Asm->MAI->getCodePointerSize());
2114SmallVector<VFTableSlotKind, 4> Slots(VSlotCount, VFTableSlotKind::Near);
2115
2116VFTableShapeRecord VFTSR(Slots);
2117return TypeTable.writeLeafType(VFTSR);
2118}
2119
2120staticMemberAccesstranslateAccessFlags(unsigned RecordTag,unsigned Flags) {
2121switch (Flags &DINode::FlagAccessibility) {
2122case DINode::FlagPrivate:return MemberAccess::Private;
2123case DINode::FlagPublic:return MemberAccess::Public;
2124case DINode::FlagProtected:return MemberAccess::Protected;
2125case 0:
2126// If there was no explicit access control, provide the default for the tag.
2127return RecordTag == dwarf::DW_TAG_class_type ? MemberAccess::Private
2128 : MemberAccess::Public;
2129 }
2130llvm_unreachable("access flags are exclusive");
2131}
2132
2133staticMethodOptionstranslateMethodOptionFlags(constDISubprogram *SP) {
2134if (SP->isArtificial())
2135return MethodOptions::CompilerGenerated;
2136
2137// FIXME: Handle other MethodOptions.
2138
2139return MethodOptions::None;
2140}
2141
2142staticMethodKindtranslateMethodKindFlags(constDISubprogram *SP,
2143bool Introduced) {
2144if (SP->getFlags() & DINode::FlagStaticMember)
2145return MethodKind::Static;
2146
2147switch (SP->getVirtuality()) {
2148case dwarf::DW_VIRTUALITY_none:
2149break;
2150case dwarf::DW_VIRTUALITY_virtual:
2151return Introduced ? MethodKind::IntroducingVirtual : MethodKind::Virtual;
2152case dwarf::DW_VIRTUALITY_pure_virtual:
2153return Introduced ? MethodKind::PureIntroducingVirtual
2154 : MethodKind::PureVirtual;
2155default:
2156llvm_unreachable("unhandled virtuality case");
2157 }
2158
2159return MethodKind::Vanilla;
2160}
2161
2162staticTypeRecordKindgetRecordKind(constDICompositeType *Ty) {
2163switch (Ty->getTag()) {
2164case dwarf::DW_TAG_class_type:
2165return TypeRecordKind::Class;
2166case dwarf::DW_TAG_structure_type:
2167return TypeRecordKind::Struct;
2168default:
2169llvm_unreachable("unexpected tag");
2170 }
2171}
2172
2173/// Return ClassOptions that should be present on both the forward declaration
2174/// and the defintion of a tag type.
2175staticClassOptionsgetCommonClassOptions(constDICompositeType *Ty) {
2176ClassOptions CO = ClassOptions::None;
2177
2178// MSVC always sets this flag, even for local types. Clang doesn't always
2179// appear to give every type a linkage name, which may be problematic for us.
2180// FIXME: Investigate the consequences of not following them here.
2181if (!Ty->getIdentifier().empty())
2182 CO |= ClassOptions::HasUniqueName;
2183
2184// Put the Nested flag on a type if it appears immediately inside a tag type.
2185// Do not walk the scope chain. Do not attempt to compute ContainsNestedClass
2186// here. That flag is only set on definitions, and not forward declarations.
2187constDIScope *ImmediateScope = Ty->getScope();
2188if (ImmediateScope && isa<DICompositeType>(ImmediateScope))
2189 CO |= ClassOptions::Nested;
2190
2191// Put the Scoped flag on function-local types. MSVC puts this flag for enum
2192// type only when it has an immediate function scope. Clang never puts enums
2193// inside DILexicalBlock scopes. Enum types, as generated by clang, are
2194// always in function, class, or file scopes.
2195if (Ty->getTag() == dwarf::DW_TAG_enumeration_type) {
2196if (ImmediateScope && isa<DISubprogram>(ImmediateScope))
2197 CO |= ClassOptions::Scoped;
2198 }else {
2199for (constDIScope *Scope = ImmediateScope; Scope !=nullptr;
2200 Scope = Scope->getScope()) {
2201if (isa<DISubprogram>(Scope)) {
2202 CO |= ClassOptions::Scoped;
2203break;
2204 }
2205 }
2206 }
2207
2208return CO;
2209}
2210
2211void CodeViewDebug::addUDTSrcLine(constDIType *Ty,TypeIndex TI) {
2212switch (Ty->getTag()) {
2213case dwarf::DW_TAG_class_type:
2214case dwarf::DW_TAG_structure_type:
2215case dwarf::DW_TAG_union_type:
2216case dwarf::DW_TAG_enumeration_type:
2217break;
2218default:
2219return;
2220 }
2221
2222if (constauto *File = Ty->getFile()) {
2223StringIdRecord SIDR(TypeIndex(0x0), getFullFilepath(File));
2224TypeIndex SIDI = TypeTable.writeLeafType(SIDR);
2225
2226UdtSourceLineRecord USLR(TI, SIDI, Ty->getLine());
2227 TypeTable.writeLeafType(USLR);
2228 }
2229}
2230
2231TypeIndex CodeViewDebug::lowerTypeEnum(constDICompositeType *Ty) {
2232ClassOptions CO =getCommonClassOptions(Ty);
2233TypeIndex FTI;
2234unsigned EnumeratorCount = 0;
2235
2236if (Ty->isForwardDecl()) {
2237 CO |= ClassOptions::ForwardReference;
2238 }else {
2239ContinuationRecordBuilder ContinuationBuilder;
2240 ContinuationBuilder.begin(ContinuationRecordKind::FieldList);
2241for (constDINode *Element : Ty->getElements()) {
2242// We assume that the frontend provides all members in source declaration
2243// order, which is what MSVC does.
2244if (auto *Enumerator = dyn_cast_or_null<DIEnumerator>(Element)) {
2245// FIXME: Is it correct to always emit these as unsigned here?
2246EnumeratorRecord ER(MemberAccess::Public,
2247APSInt(Enumerator->getValue(),true),
2248Enumerator->getName());
2249 ContinuationBuilder.writeMemberType(ER);
2250 EnumeratorCount++;
2251 }
2252 }
2253 FTI = TypeTable.insertRecord(ContinuationBuilder);
2254 }
2255
2256 std::string FullName = getFullyQualifiedName(Ty);
2257
2258EnumRecord ER(EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier(),
2259 getTypeIndex(Ty->getBaseType()));
2260TypeIndex EnumTI = TypeTable.writeLeafType(ER);
2261
2262 addUDTSrcLine(Ty, EnumTI);
2263
2264return EnumTI;
2265}
2266
2267//===----------------------------------------------------------------------===//
2268// ClassInfo
2269//===----------------------------------------------------------------------===//
2270
2271structllvm::ClassInfo {
2272structMemberInfo {
2273constDIDerivedType *MemberTypeNode;
2274uint64_tBaseOffset;
2275 };
2276// [MemberInfo]
2277usingMemberList = std::vector<MemberInfo>;
2278
2279usingMethodsList =TinyPtrVector<const DISubprogram *>;
2280// MethodName -> MethodsList
2281usingMethodsMap =MapVector<MDString *, MethodsList>;
2282
2283 /// Base classes.
2284 std::vector<const DIDerivedType *>Inheritance;
2285
2286 /// Direct members.
2287MemberListMembers;
2288// Direct overloaded methods gathered by name.
2289MethodsMapMethods;
2290
2291TypeIndexVShapeTI;
2292
2293 std::vector<const DIType *>NestedTypes;
2294};
2295
2296void CodeViewDebug::clear() {
2297assert(CurFn ==nullptr);
2298 FileIdMap.clear();
2299 FnDebugInfo.clear();
2300 FileToFilepathMap.clear();
2301 LocalUDTs.clear();
2302 GlobalUDTs.clear();
2303 TypeIndices.clear();
2304 CompleteTypeIndices.clear();
2305 ScopeGlobals.clear();
2306 CVGlobalVariableOffsets.clear();
2307}
2308
2309void CodeViewDebug::collectMemberInfo(ClassInfo &Info,
2310constDIDerivedType *DDTy) {
2311if (!DDTy->getName().empty()) {
2312Info.Members.push_back({DDTy, 0});
2313
2314// Collect static const data members with values.
2315if ((DDTy->getFlags() & DINode::FlagStaticMember) ==
2316 DINode::FlagStaticMember) {
2317if (DDTy->getConstant() && (isa<ConstantInt>(DDTy->getConstant()) ||
2318 isa<ConstantFP>(DDTy->getConstant())))
2319 StaticConstMembers.push_back(DDTy);
2320 }
2321
2322return;
2323 }
2324
2325// An unnamed member may represent a nested struct or union. Attempt to
2326// interpret the unnamed member as a DICompositeType possibly wrapped in
2327// qualifier types. Add all the indirect fields to the current record if that
2328// succeeds, and drop the member if that fails.
2329assert((DDTy->getOffsetInBits() % 8) == 0 &&"Unnamed bitfield member!");
2330uint64_tOffset = DDTy->getOffsetInBits();
2331constDIType *Ty = DDTy->getBaseType();
2332bool FullyResolved =false;
2333while (!FullyResolved) {
2334switch (Ty->getTag()) {
2335case dwarf::DW_TAG_const_type:
2336case dwarf::DW_TAG_volatile_type:
2337// FIXME: we should apply the qualifier types to the indirect fields
2338// rather than dropping them.
2339 Ty = cast<DIDerivedType>(Ty)->getBaseType();
2340break;
2341default:
2342 FullyResolved =true;
2343break;
2344 }
2345 }
2346
2347constDICompositeType *DCTy = dyn_cast<DICompositeType>(Ty);
2348if (!DCTy)
2349return;
2350
2351ClassInfo NestedInfo = collectClassInfo(DCTy);
2352for (constClassInfo::MemberInfo &IndirectField : NestedInfo.Members)
2353Info.Members.push_back(
2354 {IndirectField.MemberTypeNode, IndirectField.BaseOffset +Offset});
2355}
2356
2357ClassInfo CodeViewDebug::collectClassInfo(constDICompositeType *Ty) {
2358ClassInfoInfo;
2359// Add elements to structure type.
2360 DINodeArrayElements = Ty->getElements();
2361for (auto *Element : Elements) {
2362// We assume that the frontend provides all members in source declaration
2363// order, which is what MSVC does.
2364if (!Element)
2365continue;
2366if (auto *SP = dyn_cast<DISubprogram>(Element)) {
2367Info.Methods[SP->getRawName()].push_back(SP);
2368 }elseif (auto *DDTy = dyn_cast<DIDerivedType>(Element)) {
2369if (DDTy->getTag() == dwarf::DW_TAG_member) {
2370 collectMemberInfo(Info, DDTy);
2371 }elseif (DDTy->getTag() == dwarf::DW_TAG_inheritance) {
2372Info.Inheritance.push_back(DDTy);
2373 }elseif (DDTy->getTag() == dwarf::DW_TAG_pointer_type &&
2374 DDTy->getName() =="__vtbl_ptr_type") {
2375Info.VShapeTI = getTypeIndex(DDTy);
2376 }elseif (DDTy->getTag() == dwarf::DW_TAG_typedef) {
2377Info.NestedTypes.push_back(DDTy);
2378 }elseif (DDTy->getTag() == dwarf::DW_TAG_friend) {
2379// Ignore friend members. It appears that MSVC emitted info about
2380// friends in the past, but modern versions do not.
2381 }
2382 }elseif (auto *Composite = dyn_cast<DICompositeType>(Element)) {
2383Info.NestedTypes.push_back(Composite);
2384 }
2385// Skip other unrecognized kinds of elements.
2386 }
2387returnInfo;
2388}
2389
2390staticboolshouldAlwaysEmitCompleteClassType(constDICompositeType *Ty) {
2391// This routine is used by lowerTypeClass and lowerTypeUnion to determine
2392// if a complete type should be emitted instead of a forward reference.
2393return Ty->getName().empty() && Ty->getIdentifier().empty() &&
2394 !Ty->isForwardDecl();
2395}
2396
2397TypeIndex CodeViewDebug::lowerTypeClass(constDICompositeType *Ty) {
2398// Emit the complete type for unnamed structs. C++ classes with methods
2399// which have a circular reference back to the class type are expected to
2400// be named by the front-end and should not be "unnamed". C unnamed
2401// structs should not have circular references.
2402if (shouldAlwaysEmitCompleteClassType(Ty)) {
2403// If this unnamed complete type is already in the process of being defined
2404// then the description of the type is malformed and cannot be emitted
2405// into CodeView correctly so report a fatal error.
2406autoI = CompleteTypeIndices.find(Ty);
2407if (I != CompleteTypeIndices.end() &&I->second ==TypeIndex())
2408report_fatal_error("cannot debug circular reference to unnamed type");
2409return getCompleteTypeIndex(Ty);
2410 }
2411
2412// First, construct the forward decl. Don't look into Ty to compute the
2413// forward decl options, since it might not be available in all TUs.
2414TypeRecordKindKind =getRecordKind(Ty);
2415ClassOptions CO =
2416 ClassOptions::ForwardReference |getCommonClassOptions(Ty);
2417 std::string FullName = getFullyQualifiedName(Ty);
2418ClassRecord CR(Kind, 0, CO,TypeIndex(),TypeIndex(),TypeIndex(), 0,
2419 FullName, Ty->getIdentifier());
2420TypeIndex FwdDeclTI = TypeTable.writeLeafType(CR);
2421if (!Ty->isForwardDecl())
2422 DeferredCompleteTypes.push_back(Ty);
2423return FwdDeclTI;
2424}
2425
2426TypeIndex CodeViewDebug::lowerCompleteTypeClass(constDICompositeType *Ty) {
2427// Construct the field list and complete type record.
2428TypeRecordKindKind =getRecordKind(Ty);
2429ClassOptions CO =getCommonClassOptions(Ty);
2430TypeIndex FieldTI;
2431TypeIndex VShapeTI;
2432unsigned FieldCount;
2433boolContainsNestedClass;
2434 std::tie(FieldTI, VShapeTI, FieldCount,ContainsNestedClass) =
2435 lowerRecordFieldList(Ty);
2436
2437if (ContainsNestedClass)
2438 CO |= ClassOptions::ContainsNestedClass;
2439
2440// MSVC appears to set this flag by searching any destructor or method with
2441// FunctionOptions::Constructor among the emitted members. Clang AST has all
2442// the members, however special member functions are not yet emitted into
2443// debug information. For now checking a class's non-triviality seems enough.
2444// FIXME: not true for a nested unnamed struct.
2445if (isNonTrivial(Ty))
2446 CO |= ClassOptions::HasConstructorOrDestructor;
2447
2448 std::string FullName = getFullyQualifiedName(Ty);
2449
2450uint64_t SizeInBytes = Ty->getSizeInBits() / 8;
2451
2452ClassRecord CR(Kind, FieldCount, CO, FieldTI,TypeIndex(), VShapeTI,
2453 SizeInBytes, FullName, Ty->getIdentifier());
2454TypeIndex ClassTI = TypeTable.writeLeafType(CR);
2455
2456 addUDTSrcLine(Ty, ClassTI);
2457
2458 addToUDTs(Ty);
2459
2460return ClassTI;
2461}
2462
2463TypeIndex CodeViewDebug::lowerTypeUnion(constDICompositeType *Ty) {
2464// Emit the complete type for unnamed unions.
2465if (shouldAlwaysEmitCompleteClassType(Ty))
2466return getCompleteTypeIndex(Ty);
2467
2468ClassOptions CO =
2469 ClassOptions::ForwardReference |getCommonClassOptions(Ty);
2470 std::string FullName = getFullyQualifiedName(Ty);
2471UnionRecord UR(0, CO,TypeIndex(), 0, FullName, Ty->getIdentifier());
2472TypeIndex FwdDeclTI = TypeTable.writeLeafType(UR);
2473if (!Ty->isForwardDecl())
2474 DeferredCompleteTypes.push_back(Ty);
2475return FwdDeclTI;
2476}
2477
2478TypeIndex CodeViewDebug::lowerCompleteTypeUnion(constDICompositeType *Ty) {
2479ClassOptions CO = ClassOptions::Sealed |getCommonClassOptions(Ty);
2480TypeIndex FieldTI;
2481unsigned FieldCount;
2482boolContainsNestedClass;
2483 std::tie(FieldTI, std::ignore, FieldCount,ContainsNestedClass) =
2484 lowerRecordFieldList(Ty);
2485
2486if (ContainsNestedClass)
2487 CO |= ClassOptions::ContainsNestedClass;
2488
2489uint64_t SizeInBytes = Ty->getSizeInBits() / 8;
2490 std::string FullName = getFullyQualifiedName(Ty);
2491
2492UnionRecord UR(FieldCount, CO, FieldTI, SizeInBytes, FullName,
2493 Ty->getIdentifier());
2494TypeIndex UnionTI = TypeTable.writeLeafType(UR);
2495
2496 addUDTSrcLine(Ty, UnionTI);
2497
2498 addToUDTs(Ty);
2499
2500return UnionTI;
2501}
2502
2503std::tuple<TypeIndex, TypeIndex, unsigned, bool>
2504CodeViewDebug::lowerRecordFieldList(constDICompositeType *Ty) {
2505// Manually count members. MSVC appears to count everything that generates a
2506// field list record. Each individual overload in a method overload group
2507// contributes to this count, even though the overload group is a single field
2508// list record.
2509unsigned MemberCount = 0;
2510ClassInfoInfo = collectClassInfo(Ty);
2511ContinuationRecordBuilder ContinuationBuilder;
2512 ContinuationBuilder.begin(ContinuationRecordKind::FieldList);
2513
2514// Create base classes.
2515for (constDIDerivedType *I :Info.Inheritance) {
2516if (I->getFlags() & DINode::FlagVirtual) {
2517// Virtual base.
2518unsigned VBPtrOffset =I->getVBPtrOffset();
2519// FIXME: Despite the accessor name, the offset is really in bytes.
2520unsigned VBTableIndex =I->getOffsetInBits() / 4;
2521auto RecordKind = (I->getFlags() & DINode::FlagIndirectVirtualBase) == DINode::FlagIndirectVirtualBase
2522 ? TypeRecordKind::IndirectVirtualBaseClass
2523 : TypeRecordKind::VirtualBaseClass;
2524VirtualBaseClassRecord VBCR(
2525 RecordKind,translateAccessFlags(Ty->getTag(),I->getFlags()),
2526 getTypeIndex(I->getBaseType()), getVBPTypeIndex(), VBPtrOffset,
2527 VBTableIndex);
2528
2529 ContinuationBuilder.writeMemberType(VBCR);
2530 MemberCount++;
2531 }else {
2532assert(I->getOffsetInBits() % 8 == 0 &&
2533"bases must be on byte boundaries");
2534BaseClassRecord BCR(translateAccessFlags(Ty->getTag(),I->getFlags()),
2535 getTypeIndex(I->getBaseType()),
2536I->getOffsetInBits() / 8);
2537 ContinuationBuilder.writeMemberType(BCR);
2538 MemberCount++;
2539 }
2540 }
2541
2542// Create members.
2543for (ClassInfo::MemberInfo &MemberInfo :Info.Members) {
2544constDIDerivedType *Member = MemberInfo.MemberTypeNode;
2545TypeIndex MemberBaseType = getTypeIndex(Member->getBaseType());
2546StringRef MemberName =Member->getName();
2547MemberAccessAccess =
2548translateAccessFlags(Ty->getTag(),Member->getFlags());
2549
2550if (Member->isStaticMember()) {
2551StaticDataMemberRecord SDMR(Access, MemberBaseType, MemberName);
2552 ContinuationBuilder.writeMemberType(SDMR);
2553 MemberCount++;
2554continue;
2555 }
2556
2557// Virtual function pointer member.
2558if ((Member->getFlags() & DINode::FlagArtificial) &&
2559Member->getName().starts_with("_vptr$")) {
2560VFPtrRecord VFPR(getTypeIndex(Member->getBaseType()));
2561 ContinuationBuilder.writeMemberType(VFPR);
2562 MemberCount++;
2563continue;
2564 }
2565
2566// Data member.
2567uint64_t MemberOffsetInBits =
2568Member->getOffsetInBits() + MemberInfo.BaseOffset;
2569if (Member->isBitField()) {
2570uint64_t StartBitOffset = MemberOffsetInBits;
2571if (constauto *CI =
2572 dyn_cast_or_null<ConstantInt>(Member->getStorageOffsetInBits())) {
2573 MemberOffsetInBits = CI->getZExtValue() + MemberInfo.BaseOffset;
2574 }
2575 StartBitOffset -= MemberOffsetInBits;
2576BitFieldRecord BFR(MemberBaseType,Member->getSizeInBits(),
2577 StartBitOffset);
2578 MemberBaseType = TypeTable.writeLeafType(BFR);
2579 }
2580uint64_t MemberOffsetInBytes = MemberOffsetInBits / 8;
2581DataMemberRecord DMR(Access, MemberBaseType, MemberOffsetInBytes,
2582 MemberName);
2583 ContinuationBuilder.writeMemberType(DMR);
2584 MemberCount++;
2585 }
2586
2587// Create methods
2588for (auto &MethodItr :Info.Methods) {
2589StringRefName = MethodItr.first->getString();
2590
2591 std::vector<OneMethodRecord> Methods;
2592for (constDISubprogram *SP : MethodItr.second) {
2593TypeIndex MethodType = getMemberFunctionType(SP, Ty);
2594bool Introduced = SP->getFlags() & DINode::FlagIntroducedVirtual;
2595
2596unsigned VFTableOffset = -1;
2597if (Introduced)
2598 VFTableOffset = SP->getVirtualIndex() * getPointerSizeInBytes();
2599
2600 Methods.push_back(OneMethodRecord(
2601 MethodType,translateAccessFlags(Ty->getTag(), SP->getFlags()),
2602translateMethodKindFlags(SP, Introduced),
2603translateMethodOptionFlags(SP), VFTableOffset,Name));
2604 MemberCount++;
2605 }
2606assert(!Methods.empty() &&"Empty methods map entry");
2607if (Methods.size() == 1)
2608 ContinuationBuilder.writeMemberType(Methods[0]);
2609else {
2610// FIXME: Make this use its own ContinuationBuilder so that
2611// MethodOverloadList can be split correctly.
2612MethodOverloadListRecord MOLR(Methods);
2613TypeIndex MethodList = TypeTable.writeLeafType(MOLR);
2614
2615OverloadedMethodRecord OMR(Methods.size(), MethodList,Name);
2616 ContinuationBuilder.writeMemberType(OMR);
2617 }
2618 }
2619
2620// Create nested classes.
2621for (constDIType *Nested :Info.NestedTypes) {
2622NestedTypeRecordR(getTypeIndex(Nested),Nested->getName());
2623 ContinuationBuilder.writeMemberType(R);
2624 MemberCount++;
2625 }
2626
2627TypeIndex FieldTI = TypeTable.insertRecord(ContinuationBuilder);
2628return std::make_tuple(FieldTI,Info.VShapeTI, MemberCount,
2629 !Info.NestedTypes.empty());
2630}
2631
2632TypeIndex CodeViewDebug::getVBPTypeIndex() {
2633if (!VBPType.getIndex()) {
2634// Make a 'const int *' type.
2635ModifierRecord MR(TypeIndex::Int32(), ModifierOptions::Const);
2636TypeIndex ModifiedTI = TypeTable.writeLeafType(MR);
2637
2638PointerKind PK = getPointerSizeInBytes() == 8 ? PointerKind::Near64
2639 : PointerKind::Near32;
2640PointerMode PM = PointerMode::Pointer;
2641PointerOptions PO = PointerOptions::None;
2642PointerRecord PR(ModifiedTI, PK, PM, PO, getPointerSizeInBytes());
2643 VBPType = TypeTable.writeLeafType(PR);
2644 }
2645
2646return VBPType;
2647}
2648
2649TypeIndex CodeViewDebug::getTypeIndex(constDIType *Ty,constDIType *ClassTy) {
2650// The null DIType is the void type. Don't try to hash it.
2651if (!Ty)
2652returnTypeIndex::Void();
2653
2654// Check if we've already translated this type. Don't try to do a
2655// get-or-create style insertion that caches the hash lookup across the
2656// lowerType call. It will update the TypeIndices map.
2657autoI = TypeIndices.find({Ty, ClassTy});
2658if (I != TypeIndices.end())
2659returnI->second;
2660
2661 TypeLoweringScope S(*this);
2662TypeIndex TI = lowerType(Ty, ClassTy);
2663return recordTypeIndexForDINode(Ty, TI, ClassTy);
2664}
2665
2666codeview::TypeIndex
2667CodeViewDebug::getTypeIndexForThisPtr(constDIDerivedType *PtrTy,
2668constDISubroutineType *SubroutineTy) {
2669assert(PtrTy->getTag() == dwarf::DW_TAG_pointer_type &&
2670"this type must be a pointer type");
2671
2672PointerOptionsOptions = PointerOptions::None;
2673if (SubroutineTy->getFlags() & DINode::DIFlags::FlagLValueReference)
2674Options = PointerOptions::LValueRefThisPointer;
2675elseif (SubroutineTy->getFlags() & DINode::DIFlags::FlagRValueReference)
2676Options = PointerOptions::RValueRefThisPointer;
2677
2678// Check if we've already translated this type. If there is no ref qualifier
2679// on the function then we look up this pointer type with no associated class
2680// so that the TypeIndex for the this pointer can be shared with the type
2681// index for other pointers to this class type. If there is a ref qualifier
2682// then we lookup the pointer using the subroutine as the parent type.
2683autoI = TypeIndices.find({PtrTy, SubroutineTy});
2684if (I != TypeIndices.end())
2685returnI->second;
2686
2687 TypeLoweringScope S(*this);
2688TypeIndex TI = lowerTypePointer(PtrTy,Options);
2689return recordTypeIndexForDINode(PtrTy, TI, SubroutineTy);
2690}
2691
2692TypeIndex CodeViewDebug::getTypeIndexForReferenceTo(constDIType *Ty) {
2693PointerRecord PR(getTypeIndex(Ty),
2694 getPointerSizeInBytes() == 8 ? PointerKind::Near64
2695 : PointerKind::Near32,
2696 PointerMode::LValueReference, PointerOptions::None,
2697 Ty->getSizeInBits() / 8);
2698return TypeTable.writeLeafType(PR);
2699}
2700
2701TypeIndex CodeViewDebug::getCompleteTypeIndex(constDIType *Ty) {
2702// The null DIType is the void type. Don't try to hash it.
2703if (!Ty)
2704returnTypeIndex::Void();
2705
2706// Look through typedefs when getting the complete type index. Call
2707// getTypeIndex on the typdef to ensure that any UDTs are accumulated and are
2708// emitted only once.
2709if (Ty->getTag() == dwarf::DW_TAG_typedef)
2710 (void)getTypeIndex(Ty);
2711while (Ty->getTag() == dwarf::DW_TAG_typedef)
2712 Ty = cast<DIDerivedType>(Ty)->getBaseType();
2713
2714// If this is a non-record type, the complete type index is the same as the
2715// normal type index. Just call getTypeIndex.
2716switch (Ty->getTag()) {
2717case dwarf::DW_TAG_class_type:
2718case dwarf::DW_TAG_structure_type:
2719case dwarf::DW_TAG_union_type:
2720break;
2721default:
2722return getTypeIndex(Ty);
2723 }
2724
2725constauto *CTy = cast<DICompositeType>(Ty);
2726
2727 TypeLoweringScope S(*this);
2728
2729// Make sure the forward declaration is emitted first. It's unclear if this
2730// is necessary, but MSVC does it, and we should follow suit until we can show
2731// otherwise.
2732// We only emit a forward declaration for named types.
2733if (!CTy->getName().empty() || !CTy->getIdentifier().empty()) {
2734TypeIndex FwdDeclTI = getTypeIndex(CTy);
2735
2736// Just use the forward decl if we don't have complete type info. This
2737// might happen if the frontend is using modules and expects the complete
2738// definition to be emitted elsewhere.
2739if (CTy->isForwardDecl())
2740return FwdDeclTI;
2741 }
2742
2743// Check if we've already translated the complete record type.
2744// Insert the type with a null TypeIndex to signify that the type is currently
2745// being lowered.
2746auto InsertResult = CompleteTypeIndices.insert({CTy,TypeIndex()});
2747if (!InsertResult.second)
2748return InsertResult.first->second;
2749
2750TypeIndex TI;
2751switch (CTy->getTag()) {
2752case dwarf::DW_TAG_class_type:
2753case dwarf::DW_TAG_structure_type:
2754 TI = lowerCompleteTypeClass(CTy);
2755break;
2756case dwarf::DW_TAG_union_type:
2757 TI = lowerCompleteTypeUnion(CTy);
2758break;
2759default:
2760llvm_unreachable("not a record");
2761 }
2762
2763// Update the type index associated with this CompositeType. This cannot
2764// use the 'InsertResult' iterator above because it is potentially
2765// invalidated by map insertions which can occur while lowering the class
2766// type above.
2767 CompleteTypeIndices[CTy] = TI;
2768return TI;
2769}
2770
2771/// Emit all the deferred complete record types. Try to do this in FIFO order,
2772/// and do this until fixpoint, as each complete record type typically
2773/// references
2774/// many other record types.
2775void CodeViewDebug::emitDeferredCompleteTypes() {
2776SmallVector<const DICompositeType *, 4> TypesToEmit;
2777while (!DeferredCompleteTypes.empty()) {
2778std::swap(DeferredCompleteTypes, TypesToEmit);
2779for (constDICompositeType *RecordTy : TypesToEmit)
2780 getCompleteTypeIndex(RecordTy);
2781 TypesToEmit.clear();
2782 }
2783}
2784
2785void CodeViewDebug::emitLocalVariableList(const FunctionInfo &FI,
2786ArrayRef<LocalVariable> Locals) {
2787// Get the sorted list of parameters and emit them first.
2788SmallVector<const LocalVariable *, 6> Params;
2789for (const LocalVariable &L : Locals)
2790if (L.DIVar->isParameter())
2791 Params.push_back(&L);
2792llvm::sort(Params, [](const LocalVariable *L,const LocalVariable *R) {
2793returnL->DIVar->getArg() <R->DIVar->getArg();
2794 });
2795for (const LocalVariable *L : Params)
2796 emitLocalVariable(FI, *L);
2797
2798// Next emit all non-parameters in the order that we found them.
2799for (const LocalVariable &L : Locals) {
2800if (!L.DIVar->isParameter()) {
2801if (L.ConstantValue) {
2802// If ConstantValue is set we will emit it as a S_CONSTANT instead of a
2803// S_LOCAL in order to be able to represent it at all.
2804constDIType *Ty =L.DIVar->getType();
2805APSInt Val(*L.ConstantValue);
2806 emitConstantSymbolRecord(Ty, Val, std::string(L.DIVar->getName()));
2807 }else {
2808 emitLocalVariable(FI, L);
2809 }
2810 }
2811 }
2812}
2813
2814void CodeViewDebug::emitLocalVariable(const FunctionInfo &FI,
2815const LocalVariable &Var) {
2816// LocalSym record, see SymbolRecord.h for more info.
2817MCSymbol *LocalEnd = beginSymbolRecord(SymbolKind::S_LOCAL);
2818
2819LocalSymFlagsFlags = LocalSymFlags::None;
2820if (Var.DIVar->isParameter())
2821Flags |= LocalSymFlags::IsParameter;
2822if (Var.DefRanges.empty())
2823Flags |= LocalSymFlags::IsOptimizedOut;
2824
2825 OS.AddComment("TypeIndex");
2826TypeIndex TI = Var.UseReferenceType
2827 ? getTypeIndexForReferenceTo(Var.DIVar->getType())
2828 : getCompleteTypeIndex(Var.DIVar->getType());
2829 OS.emitInt32(TI.getIndex());
2830 OS.AddComment("Flags");
2831 OS.emitInt16(static_cast<uint16_t>(Flags));
2832// Truncate the name so we won't overflow the record length field.
2833emitNullTerminatedSymbolName(OS, Var.DIVar->getName());
2834 endSymbolRecord(LocalEnd);
2835
2836// Calculate the on disk prefix of the appropriate def range record. The
2837// records and on disk formats are described in SymbolRecords.h. BytePrefix
2838// should be big enough to hold all forms without memory allocation.
2839SmallString<20> BytePrefix;
2840for (constauto &Pair : Var.DefRanges) {
2841 LocalVarDef DefRange = Pair.first;
2842constauto &Ranges = Pair.second;
2843 BytePrefix.clear();
2844if (DefRange.InMemory) {
2845intOffset = DefRange.DataOffset;
2846unsignedReg = DefRange.CVRegister;
2847
2848// 32-bit x86 call sequences often use PUSH instructions, which disrupt
2849// ESP-relative offsets. Use the virtual frame pointer, VFRAME or $T0,
2850// instead. In frames without stack realignment, $T0 will be the CFA.
2851if (RegisterId(Reg) == RegisterId::ESP) {
2852Reg =unsigned(RegisterId::VFRAME);
2853Offset += FI.OffsetAdjustment;
2854 }
2855
2856// If we can use the chosen frame pointer for the frame and this isn't a
2857// sliced aggregate, use the smaller S_DEFRANGE_FRAMEPOINTER_REL record.
2858// Otherwise, use S_DEFRANGE_REGISTER_REL.
2859EncodedFramePtrReg EncFP =encodeFramePtrReg(RegisterId(Reg), TheCPU);
2860if (!DefRange.IsSubfield && EncFP != EncodedFramePtrReg::None &&
2861 (bool(Flags & LocalSymFlags::IsParameter)
2862 ? (EncFP == FI.EncodedParamFramePtrReg)
2863 : (EncFP == FI.EncodedLocalFramePtrReg))) {
2864DefRangeFramePointerRelHeader DRHdr;
2865 DRHdr.Offset =Offset;
2866 OS.emitCVDefRangeDirective(Ranges, DRHdr);
2867 }else {
2868uint16_t RegRelFlags = 0;
2869if (DefRange.IsSubfield) {
2870 RegRelFlags =DefRangeRegisterRelSym::IsSubfieldFlag |
2871 (DefRange.StructOffset
2872 <<DefRangeRegisterRelSym::OffsetInParentShift);
2873 }
2874DefRangeRegisterRelHeader DRHdr;
2875 DRHdr.Register =Reg;
2876 DRHdr.Flags = RegRelFlags;
2877 DRHdr.BasePointerOffset =Offset;
2878 OS.emitCVDefRangeDirective(Ranges, DRHdr);
2879 }
2880 }else {
2881assert(DefRange.DataOffset == 0 &&"unexpected offset into register");
2882if (DefRange.IsSubfield) {
2883DefRangeSubfieldRegisterHeader DRHdr;
2884 DRHdr.Register = DefRange.CVRegister;
2885 DRHdr.MayHaveNoName = 0;
2886 DRHdr.OffsetInParent = DefRange.StructOffset;
2887 OS.emitCVDefRangeDirective(Ranges, DRHdr);
2888 }else {
2889DefRangeRegisterHeader DRHdr;
2890 DRHdr.Register = DefRange.CVRegister;
2891 DRHdr.MayHaveNoName = 0;
2892 OS.emitCVDefRangeDirective(Ranges, DRHdr);
2893 }
2894 }
2895 }
2896}
2897
2898void CodeViewDebug::emitLexicalBlockList(ArrayRef<LexicalBlock *>Blocks,
2899const FunctionInfo& FI) {
2900for (LexicalBlock *Block :Blocks)
2901 emitLexicalBlock(*Block, FI);
2902}
2903
2904/// Emit an S_BLOCK32 and S_END record pair delimiting the contents of a
2905/// lexical block scope.
2906void CodeViewDebug::emitLexicalBlock(const LexicalBlock &Block,
2907const FunctionInfo& FI) {
2908MCSymbol *RecordEnd = beginSymbolRecord(SymbolKind::S_BLOCK32);
2909 OS.AddComment("PtrParent");
2910 OS.emitInt32(0);// PtrParent
2911 OS.AddComment("PtrEnd");
2912 OS.emitInt32(0);// PtrEnd
2913 OS.AddComment("Code size");
2914 OS.emitAbsoluteSymbolDiff(Block.End,Block.Begin, 4);// Code Size
2915 OS.AddComment("Function section relative address");
2916 OS.emitCOFFSecRel32(Block.Begin,/*Offset=*/0);// Func Offset
2917 OS.AddComment("Function section index");
2918 OS.emitCOFFSectionIndex(FI.Begin);// Func Symbol
2919 OS.AddComment("Lexical block name");
2920emitNullTerminatedSymbolName(OS,Block.Name);// Name
2921 endSymbolRecord(RecordEnd);
2922
2923// Emit variables local to this lexical block.
2924 emitLocalVariableList(FI,Block.Locals);
2925 emitGlobalVariableList(Block.Globals);
2926
2927// Emit lexical blocks contained within this block.
2928 emitLexicalBlockList(Block.Children, FI);
2929
2930// Close the lexical block scope.
2931 emitEndSymbolRecord(SymbolKind::S_END);
2932}
2933
2934/// Convenience routine for collecting lexical block information for a list
2935/// of lexical scopes.
2936void CodeViewDebug::collectLexicalBlockInfo(
2937SmallVectorImpl<LexicalScope *> &Scopes,
2938SmallVectorImpl<LexicalBlock *> &Blocks,
2939SmallVectorImpl<LocalVariable> &Locals,
2940SmallVectorImpl<CVGlobalVariable> &Globals) {
2941for (LexicalScope *Scope : Scopes)
2942 collectLexicalBlockInfo(*Scope,Blocks, Locals, Globals);
2943}
2944
2945/// Populate the lexical blocks and local variable lists of the parent with
2946/// information about the specified lexical scope.
2947void CodeViewDebug::collectLexicalBlockInfo(
2948LexicalScope &Scope,
2949SmallVectorImpl<LexicalBlock *> &ParentBlocks,
2950SmallVectorImpl<LocalVariable> &ParentLocals,
2951SmallVectorImpl<CVGlobalVariable> &ParentGlobals) {
2952if (Scope.isAbstractScope())
2953return;
2954
2955// Gather information about the lexical scope including local variables,
2956// global variables, and address ranges.
2957bool IgnoreScope =false;
2958auto LI = ScopeVariables.find(&Scope);
2959SmallVectorImpl<LocalVariable> *Locals =
2960 LI != ScopeVariables.end() ? &LI->second :nullptr;
2961auto GI = ScopeGlobals.find(Scope.getScopeNode());
2962SmallVectorImpl<CVGlobalVariable> *Globals =
2963 GI != ScopeGlobals.end() ? GI->second.get() :nullptr;
2964constDILexicalBlock *DILB = dyn_cast<DILexicalBlock>(Scope.getScopeNode());
2965constSmallVectorImpl<InsnRange> &Ranges =Scope.getRanges();
2966
2967// Ignore lexical scopes which do not contain variables.
2968if (!Locals && !Globals)
2969 IgnoreScope =true;
2970
2971// Ignore lexical scopes which are not lexical blocks.
2972if (!DILB)
2973 IgnoreScope =true;
2974
2975// Ignore scopes which have too many address ranges to represent in the
2976// current CodeView format or do not have a valid address range.
2977//
2978// For lexical scopes with multiple address ranges you may be tempted to
2979// construct a single range covering every instruction where the block is
2980// live and everything in between. Unfortunately, Visual Studio only
2981// displays variables from the first matching lexical block scope. If the
2982// first lexical block contains exception handling code or cold code which
2983// is moved to the bottom of the routine creating a single range covering
2984// nearly the entire routine, then it will hide all other lexical blocks
2985// and the variables they contain.
2986if (Ranges.size() != 1 || !getLabelAfterInsn(Ranges.front().second))
2987 IgnoreScope =true;
2988
2989if (IgnoreScope) {
2990// This scope can be safely ignored and eliminating it will reduce the
2991// size of the debug information. Be sure to collect any variable and scope
2992// information from the this scope or any of its children and collapse them
2993// into the parent scope.
2994if (Locals)
2995 ParentLocals.append(Locals->begin(),Locals->end());
2996if (Globals)
2997 ParentGlobals.append(Globals->begin(), Globals->end());
2998 collectLexicalBlockInfo(Scope.getChildren(),
2999 ParentBlocks,
3000 ParentLocals,
3001 ParentGlobals);
3002return;
3003 }
3004
3005// Create a new CodeView lexical block for this lexical scope. If we've
3006// seen this DILexicalBlock before then the scope tree is malformed and
3007// we can handle this gracefully by not processing it a second time.
3008auto BlockInsertion = CurFn->LexicalBlocks.insert({DILB, LexicalBlock()});
3009if (!BlockInsertion.second)
3010return;
3011
3012// Create a lexical block containing the variables and collect the
3013// lexical block information for the children.
3014constInsnRange &Range =Ranges.front();
3015assert(Range.first &&Range.second);
3016 LexicalBlock &Block = BlockInsertion.first->second;
3017Block.Begin =getLabelBeforeInsn(Range.first);
3018Block.End =getLabelAfterInsn(Range.second);
3019assert(Block.Begin &&"missing label for scope begin");
3020assert(Block.End &&"missing label for scope end");
3021Block.Name = DILB->getName();
3022if (Locals)
3023Block.Locals = std::move(*Locals);
3024if (Globals)
3025Block.Globals = std::move(*Globals);
3026 ParentBlocks.push_back(&Block);
3027 collectLexicalBlockInfo(Scope.getChildren(),
3028Block.Children,
3029Block.Locals,
3030Block.Globals);
3031}
3032
3033voidCodeViewDebug::endFunctionImpl(constMachineFunction *MF) {
3034constFunction &GV = MF->getFunction();
3035assert(FnDebugInfo.count(&GV));
3036assert(CurFn == FnDebugInfo[&GV].get());
3037
3038 collectVariableInfo(GV.getSubprogram());
3039
3040// Build the lexical block structure to emit for this routine.
3041if (LexicalScope *CFS =LScopes.getCurrentFunctionScope())
3042 collectLexicalBlockInfo(*CFS,
3043 CurFn->ChildBlocks,
3044 CurFn->Locals,
3045 CurFn->Globals);
3046
3047// Clear the scope and variable information from the map which will not be
3048// valid after we have finished processing this routine. This also prepares
3049// the map for the subsequent routine.
3050 ScopeVariables.clear();
3051
3052// Don't emit anything if we don't have any line tables.
3053// Thunks are compiler-generated and probably won't have source correlation.
3054if (!CurFn->HaveLineInfo && !GV.getSubprogram()->isThunk()) {
3055 FnDebugInfo.erase(&GV);
3056 CurFn =nullptr;
3057return;
3058 }
3059
3060// Find heap alloc sites and add to list.
3061for (constauto &MBB : *MF) {
3062for (constauto &MI :MBB) {
3063if (MDNode *MD =MI.getHeapAllocMarker()) {
3064 CurFn->HeapAllocSites.push_back(std::make_tuple(getLabelBeforeInsn(&MI),
3065getLabelAfterInsn(&MI),
3066 dyn_cast<DIType>(MD)));
3067 }
3068 }
3069 }
3070
3071boolisThumb =Triple(MMI->getModule()->getTargetTriple()).getArch() ==
3072llvm::Triple::ArchType::thumb;
3073 collectDebugInfoForJumpTables(MF,isThumb);
3074
3075 CurFn->Annotations = MF->getCodeViewAnnotations();
3076
3077 CurFn->End =Asm->getFunctionEnd();
3078
3079 CurFn =nullptr;
3080}
3081
3082// Usable locations are valid with non-zero line numbers. A line number of zero
3083// corresponds to optimized code that doesn't have a distinct source location.
3084// In this case, we try to use the previous or next source location depending on
3085// the context.
3086staticboolisUsableDebugLoc(DebugLocDL) {
3087returnDL &&DL.getLine() != 0;
3088}
3089
3090voidCodeViewDebug::beginInstruction(constMachineInstr *MI) {
3091DebugHandlerBase::beginInstruction(MI);
3092
3093// Ignore DBG_VALUE and DBG_LABEL locations and function prologue.
3094if (!Asm || !CurFn ||MI->isDebugInstr() ||
3095MI->getFlag(MachineInstr::FrameSetup))
3096return;
3097
3098// If the first instruction of a new MBB has no location, find the first
3099// instruction with a location and use that.
3100DebugLocDL =MI->getDebugLoc();
3101if (!isUsableDebugLoc(DL) &&MI->getParent() !=PrevInstBB) {
3102for (constauto &NextMI : *MI->getParent()) {
3103if (NextMI.isDebugInstr())
3104continue;
3105DL = NextMI.getDebugLoc();
3106if (isUsableDebugLoc(DL))
3107break;
3108 }
3109// FIXME: Handle the case where the BB has no valid locations. This would
3110// probably require doing a real dataflow analysis.
3111 }
3112PrevInstBB =MI->getParent();
3113
3114// If we still don't have a debug location, don't record a location.
3115if (!isUsableDebugLoc(DL))
3116return;
3117
3118 maybeRecordLocation(DL,Asm->MF);
3119}
3120
3121MCSymbol *CodeViewDebug::beginCVSubsection(DebugSubsectionKind Kind) {
3122MCSymbol *BeginLabel =MMI->getContext().createTempSymbol(),
3123 *EndLabel =MMI->getContext().createTempSymbol();
3124 OS.emitInt32(unsigned(Kind));
3125 OS.AddComment("Subsection size");
3126 OS.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 4);
3127 OS.emitLabel(BeginLabel);
3128return EndLabel;
3129}
3130
3131void CodeViewDebug::endCVSubsection(MCSymbol *EndLabel) {
3132 OS.emitLabel(EndLabel);
3133// Every subsection must be aligned to a 4-byte boundary.
3134 OS.emitValueToAlignment(Align(4));
3135}
3136
3137staticStringRefgetSymbolName(SymbolKind SymKind) {
3138for (constEnumEntry<SymbolKind> &EE :getSymbolTypeNames())
3139if (EE.Value == SymKind)
3140return EE.Name;
3141return"";
3142}
3143
3144MCSymbol *CodeViewDebug::beginSymbolRecord(SymbolKind SymKind) {
3145MCSymbol *BeginLabel =MMI->getContext().createTempSymbol(),
3146 *EndLabel =MMI->getContext().createTempSymbol();
3147 OS.AddComment("Record length");
3148 OS.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 2);
3149 OS.emitLabel(BeginLabel);
3150if (OS.isVerboseAsm())
3151 OS.AddComment("Record kind: " +getSymbolName(SymKind));
3152 OS.emitInt16(unsigned(SymKind));
3153return EndLabel;
3154}
3155
3156void CodeViewDebug::endSymbolRecord(MCSymbol *SymEnd) {
3157// MSVC does not pad out symbol records to four bytes, but LLVM does to avoid
3158// an extra copy of every symbol record in LLD. This increases object file
3159// size by less than 1% in the clang build, and is compatible with the Visual
3160// C++ linker.
3161 OS.emitValueToAlignment(Align(4));
3162 OS.emitLabel(SymEnd);
3163}
3164
3165void CodeViewDebug::emitEndSymbolRecord(SymbolKind EndKind) {
3166 OS.AddComment("Record length");
3167 OS.emitInt16(2);
3168if (OS.isVerboseAsm())
3169 OS.AddComment("Record kind: " +getSymbolName(EndKind));
3170 OS.emitInt16(uint16_t(EndKind));// Record Kind
3171}
3172
3173void CodeViewDebug::emitDebugInfoForUDTs(
3174const std::vector<std::pair<std::string, const DIType *>> &UDTs) {
3175#ifndef NDEBUG
3176size_t OriginalSize = UDTs.size();
3177#endif
3178for (constauto &UDT : UDTs) {
3179constDIType *T =UDT.second;
3180assert(shouldEmitUdt(T));
3181MCSymbol *UDTRecordEnd = beginSymbolRecord(SymbolKind::S_UDT);
3182 OS.AddComment("Type");
3183 OS.emitInt32(getCompleteTypeIndex(T).getIndex());
3184assert(OriginalSize == UDTs.size() &&
3185"getCompleteTypeIndex found new UDTs!");
3186emitNullTerminatedSymbolName(OS,UDT.first);
3187 endSymbolRecord(UDTRecordEnd);
3188 }
3189}
3190
3191void CodeViewDebug::collectGlobalVariableInfo() {
3192DenseMap<const DIGlobalVariableExpression *, const GlobalVariable *>
3193 GlobalMap;
3194for (constGlobalVariable &GV :MMI->getModule()->globals()) {
3195SmallVector<DIGlobalVariableExpression *, 1> GVEs;
3196 GV.getDebugInfo(GVEs);
3197for (constauto *GVE : GVEs)
3198 GlobalMap[GVE] = &GV;
3199 }
3200
3201NamedMDNode *CUs =MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
3202for (constMDNode *Node : CUs->operands()) {
3203constauto *CU = cast<DICompileUnit>(Node);
3204for (constauto *GVE :CU->getGlobalVariables()) {
3205constDIGlobalVariable *DIGV = GVE->getVariable();
3206constDIExpression *DIE = GVE->getExpression();
3207// Don't emit string literals in CodeView, as the only useful parts are
3208// generally the filename and line number, which isn't possible to output
3209// in CodeView. String literals should be the only unnamed GlobalVariable
3210// with debug info.
3211if (DIGV->getName().empty())continue;
3212
3213if ((DIE->getNumElements() == 2) &&
3214 (DIE->getElement(0) == dwarf::DW_OP_plus_uconst))
3215// Record the constant offset for the variable.
3216//
3217// A Fortran common block uses this idiom to encode the offset
3218// of a variable from the common block's starting address.
3219 CVGlobalVariableOffsets.insert(
3220 std::make_pair(DIGV,DIE->getElement(1)));
3221
3222// Emit constant global variables in a global symbol section.
3223if (GlobalMap.count(GVE) == 0 &&DIE->isConstant()) {
3224 CVGlobalVariable CVGV = {DIGV,DIE};
3225 GlobalVariables.emplace_back(std::move(CVGV));
3226 }
3227
3228constauto *GV = GlobalMap.lookup(GVE);
3229if (!GV || GV->isDeclarationForLinker())
3230continue;
3231
3232DIScope *Scope = DIGV->getScope();
3233SmallVector<CVGlobalVariable, 1> *VariableList;
3234if (Scope && isa<DILocalScope>(Scope)) {
3235// Locate a global variable list for this scope, creating one if
3236// necessary.
3237auto Insertion = ScopeGlobals.insert(
3238 {Scope, std::unique_ptr<GlobalVariableList>()});
3239if (Insertion.second)
3240 Insertion.first->second = std::make_unique<GlobalVariableList>();
3241 VariableList = Insertion.first->second.get();
3242 }elseif (GV->hasComdat())
3243// Emit this global variable into a COMDAT section.
3244 VariableList = &ComdatVariables;
3245else
3246// Emit this global variable in a single global symbol section.
3247 VariableList = &GlobalVariables;
3248 CVGlobalVariable CVGV = {DIGV, GV};
3249 VariableList->emplace_back(std::move(CVGV));
3250 }
3251 }
3252}
3253
3254void CodeViewDebug::collectDebugInfoForGlobals() {
3255for (const CVGlobalVariable &CVGV : GlobalVariables) {
3256constDIGlobalVariable *DIGV = CVGV.DIGV;
3257constDIScope *Scope = DIGV->getScope();
3258 getCompleteTypeIndex(DIGV->getType());
3259 getFullyQualifiedName(Scope, DIGV->getName());
3260 }
3261
3262for (const CVGlobalVariable &CVGV : ComdatVariables) {
3263constDIGlobalVariable *DIGV = CVGV.DIGV;
3264constDIScope *Scope = DIGV->getScope();
3265 getCompleteTypeIndex(DIGV->getType());
3266 getFullyQualifiedName(Scope, DIGV->getName());
3267 }
3268}
3269
3270void CodeViewDebug::emitDebugInfoForGlobals() {
3271// First, emit all globals that are not in a comdat in a single symbol
3272// substream. MSVC doesn't like it if the substream is empty, so only open
3273// it if we have at least one global to emit.
3274 switchToDebugSectionForSymbol(nullptr);
3275if (!GlobalVariables.empty() || !StaticConstMembers.empty()) {
3276 OS.AddComment("Symbol subsection for globals");
3277MCSymbol *EndLabel = beginCVSubsection(DebugSubsectionKind::Symbols);
3278 emitGlobalVariableList(GlobalVariables);
3279 emitStaticConstMemberList();
3280 endCVSubsection(EndLabel);
3281 }
3282
3283// Second, emit each global that is in a comdat into its own .debug$S
3284// section along with its own symbol substream.
3285for (const CVGlobalVariable &CVGV : ComdatVariables) {
3286constGlobalVariable *GV = cast<const GlobalVariable *>(CVGV.GVInfo);
3287MCSymbol *GVSym =Asm->getSymbol(GV);
3288 OS.AddComment("Symbol subsection for " +
3289Twine(GlobalValue::dropLLVMManglingEscape(GV->getName())));
3290 switchToDebugSectionForSymbol(GVSym);
3291MCSymbol *EndLabel = beginCVSubsection(DebugSubsectionKind::Symbols);
3292// FIXME: emitDebugInfoForGlobal() doesn't handle DIExpressions.
3293 emitDebugInfoForGlobal(CVGV);
3294 endCVSubsection(EndLabel);
3295 }
3296}
3297
3298void CodeViewDebug::emitDebugInfoForRetainedTypes() {
3299NamedMDNode *CUs =MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
3300for (constMDNode *Node : CUs->operands()) {
3301for (auto *Ty : cast<DICompileUnit>(Node)->getRetainedTypes()) {
3302if (DIType *RT = dyn_cast<DIType>(Ty)) {
3303 getTypeIndex(RT);
3304// FIXME: Add to global/local DTU list.
3305 }
3306 }
3307 }
3308}
3309
3310// Emit each global variable in the specified array.
3311void CodeViewDebug::emitGlobalVariableList(ArrayRef<CVGlobalVariable> Globals) {
3312for (const CVGlobalVariable &CVGV : Globals) {
3313// FIXME: emitDebugInfoForGlobal() doesn't handle DIExpressions.
3314 emitDebugInfoForGlobal(CVGV);
3315 }
3316}
3317
3318void CodeViewDebug::emitConstantSymbolRecord(constDIType *DTy,APSInt &Value,
3319const std::string &QualifiedName) {
3320MCSymbol *SConstantEnd = beginSymbolRecord(SymbolKind::S_CONSTANT);
3321 OS.AddComment("Type");
3322 OS.emitInt32(getTypeIndex(DTy).getIndex());
3323
3324 OS.AddComment("Value");
3325
3326// Encoded integers shouldn't need more than 10 bytes.
3327uint8_tData[10];
3328BinaryStreamWriter Writer(Data,llvm::endianness::little);
3329CodeViewRecordIO IO(Writer);
3330cantFail(IO.mapEncodedInteger(Value));
3331StringRef SRef((char *)Data, Writer.getOffset());
3332 OS.emitBinaryData(SRef);
3333
3334 OS.AddComment("Name");
3335emitNullTerminatedSymbolName(OS,QualifiedName);
3336 endSymbolRecord(SConstantEnd);
3337}
3338
3339void CodeViewDebug::emitStaticConstMemberList() {
3340for (constDIDerivedType *DTy : StaticConstMembers) {
3341constDIScope *Scope = DTy->getScope();
3342
3343APSIntValue;
3344if (constConstantInt *CI =
3345 dyn_cast_or_null<ConstantInt>(DTy->getConstant()))
3346Value =APSInt(CI->getValue(),
3347DebugHandlerBase::isUnsignedDIType(DTy->getBaseType()));
3348elseif (constConstantFP *CFP =
3349 dyn_cast_or_null<ConstantFP>(DTy->getConstant()))
3350Value =APSInt(CFP->getValueAPF().bitcastToAPInt(),true);
3351else
3352llvm_unreachable("cannot emit a constant without a value");
3353
3354 emitConstantSymbolRecord(DTy->getBaseType(),Value,
3355 getFullyQualifiedName(Scope, DTy->getName()));
3356 }
3357}
3358
3359staticboolisFloatDIType(constDIType *Ty) {
3360if (isa<DICompositeType>(Ty))
3361returnfalse;
3362
3363if (auto *DTy = dyn_cast<DIDerivedType>(Ty)) {
3364dwarf::TagT = (dwarf::Tag)Ty->getTag();
3365if (T == dwarf::DW_TAG_pointer_type ||
3366T == dwarf::DW_TAG_ptr_to_member_type ||
3367T == dwarf::DW_TAG_reference_type ||
3368T == dwarf::DW_TAG_rvalue_reference_type)
3369returnfalse;
3370assert(DTy->getBaseType() &&"Expected valid base type");
3371returnisFloatDIType(DTy->getBaseType());
3372 }
3373
3374auto *BTy = cast<DIBasicType>(Ty);
3375return (BTy->getEncoding() == dwarf::DW_ATE_float);
3376}
3377
3378void CodeViewDebug::emitDebugInfoForGlobal(const CVGlobalVariable &CVGV) {
3379constDIGlobalVariable *DIGV = CVGV.DIGV;
3380
3381constDIScope *Scope = DIGV->getScope();
3382// For static data members, get the scope from the declaration.
3383if (constauto *MemberDecl = dyn_cast_or_null<DIDerivedType>(
3384 DIGV->getRawStaticDataMemberDeclaration()))
3385Scope = MemberDecl->getScope();
3386// For static local variables and Fortran, the scoping portion is elided
3387// in its name so that we can reference the variable in the command line
3388// of the VS debugger.
3389 std::stringQualifiedName =
3390 (moduleIsInFortran() || (Scope && isa<DILocalScope>(Scope)))
3391 ? std::string(DIGV->getName())
3392 : getFullyQualifiedName(Scope, DIGV->getName());
3393
3394if (constGlobalVariable *GV =
3395 dyn_cast_if_present<const GlobalVariable *>(CVGV.GVInfo)) {
3396// DataSym record, see SymbolRecord.h for more info. Thread local data
3397// happens to have the same format as global data.
3398MCSymbol *GVSym =Asm->getSymbol(GV);
3399SymbolKindDataSym = GV->isThreadLocal()
3400 ? (DIGV->isLocalToUnit() ? SymbolKind::S_LTHREAD32
3401 : SymbolKind::S_GTHREAD32)
3402 : (DIGV->isLocalToUnit() ? SymbolKind::S_LDATA32
3403 : SymbolKind::S_GDATA32);
3404MCSymbol *DataEnd = beginSymbolRecord(DataSym);
3405 OS.AddComment("Type");
3406 OS.emitInt32(getCompleteTypeIndex(DIGV->getType()).getIndex());
3407 OS.AddComment("DataOffset");
3408
3409// Use the offset seen while collecting info on globals.
3410uint64_tOffset = CVGlobalVariableOffsets.lookup(DIGV);
3411 OS.emitCOFFSecRel32(GVSym,Offset);
3412
3413 OS.AddComment("Segment");
3414 OS.emitCOFFSectionIndex(GVSym);
3415 OS.AddComment("Name");
3416constunsigned LengthOfDataRecord = 12;
3417emitNullTerminatedSymbolName(OS,QualifiedName, LengthOfDataRecord);
3418 endSymbolRecord(DataEnd);
3419 }else {
3420constDIExpression *DIE = cast<const DIExpression *>(CVGV.GVInfo);
3421assert(DIE->isConstant() &&
3422"Global constant variables must contain a constant expression.");
3423
3424// Use unsigned for floats.
3425bool isUnsigned =isFloatDIType(DIGV->getType())
3426 ?true
3427 :DebugHandlerBase::isUnsignedDIType(DIGV->getType());
3428APSIntValue(APInt(/*BitWidth=*/64,DIE->getElement(1)), isUnsigned);
3429 emitConstantSymbolRecord(DIGV->getType(),Value,QualifiedName);
3430 }
3431}
3432
3433voidforEachJumpTableBranch(
3434constMachineFunction *MF,boolisThumb,
3435const std::function<void(constMachineJumpTableInfo &,constMachineInstr &,
3436 int64_t)> &Callback) {
3437auto JTI = MF->getJumpTableInfo();
3438if (JTI && !JTI->isEmpty()) {
3439#ifndef NDEBUG
3440auto UsedJTs =llvm::SmallBitVector(JTI->getJumpTables().size());
3441#endif
3442for (constauto &MBB : *MF) {
3443// Search for indirect branches...
3444constauto LastMI =MBB.getFirstTerminator();
3445if (LastMI !=MBB.end() && LastMI->isIndirectBranch()) {
3446if (isThumb) {
3447// ... that directly use jump table operands.
3448// NOTE: ARM uses pattern matching to lower its BR_JT SDNode to
3449// machine instructions, hence inserting a JUMP_TABLE_DEBUG_INFO node
3450// interferes with this process *but* the resulting pseudo-instruction
3451// uses a Jump Table operand, so extract the jump table index directly
3452// from that.
3453for (constauto &MO : LastMI->operands()) {
3454if (MO.isJTI()) {
3455unsigned Index = MO.getIndex();
3456#ifndef NDEBUG
3457 UsedJTs.set(Index);
3458#endif
3459 Callback(*JTI, *LastMI, Index);
3460break;
3461 }
3462 }
3463 }else {
3464// ... that have jump table debug info.
3465// NOTE: The debug info is inserted as a JUMP_TABLE_DEBUG_INFO node
3466// when lowering the BR_JT SDNode to an indirect branch.
3467for (autoI =MBB.instr_rbegin(), E =MBB.instr_rend();I != E; ++I) {
3468if (I->isJumpTableDebugInfo()) {
3469unsigned Index =I->getOperand(0).getImm();
3470#ifndef NDEBUG
3471 UsedJTs.set(Index);
3472#endif
3473 Callback(*JTI, *LastMI, Index);
3474break;
3475 }
3476 }
3477 }
3478 }
3479 }
3480#ifndef NDEBUG
3481assert(UsedJTs.all() &&
3482"Some of jump tables were not used in a debug info instruction");
3483#endif
3484 }
3485}
3486
3487void CodeViewDebug::discoverJumpTableBranches(constMachineFunction *MF,
3488boolisThumb) {
3489forEachJumpTableBranch(
3490 MF,isThumb,
3491 [this](constMachineJumpTableInfo &,constMachineInstr &BranchMI,
3492 int64_t) {requestLabelBeforeInsn(&BranchMI); });
3493}
3494
3495void CodeViewDebug::collectDebugInfoForJumpTables(constMachineFunction *MF,
3496boolisThumb) {
3497forEachJumpTableBranch(
3498 MF,isThumb,
3499 [this, MF](constMachineJumpTableInfo &JTI,constMachineInstr &BranchMI,
3500 int64_t JumpTableIndex) {
3501// For label-difference jump tables, find the base expression.
3502// Otherwise the jump table uses an absolute address (so no base
3503// is required).
3504constMCSymbol *Base;
3505uint64_t BaseOffset = 0;
3506constMCSymbol *Branch =getLabelBeforeInsn(&BranchMI);
3507JumpTableEntrySize EntrySize;
3508switch (JTI.getEntryKind()) {
3509caseMachineJumpTableInfo::EK_Custom32:
3510caseMachineJumpTableInfo::EK_GPRel32BlockAddress:
3511caseMachineJumpTableInfo::EK_GPRel64BlockAddress:
3512llvm_unreachable(
3513"EK_Custom32, EK_GPRel32BlockAddress, and "
3514"EK_GPRel64BlockAddress should never be emitted for COFF");
3515caseMachineJumpTableInfo::EK_BlockAddress:
3516// Each entry is an absolute address.
3517 EntrySize = JumpTableEntrySize::Pointer;
3518Base =nullptr;
3519break;
3520caseMachineJumpTableInfo::EK_Inline:
3521caseMachineJumpTableInfo::EK_LabelDifference32:
3522caseMachineJumpTableInfo::EK_LabelDifference64:
3523// Ask the AsmPrinter.
3524 std::tie(Base, BaseOffset, Branch, EntrySize) =
3525Asm->getCodeViewJumpTableInfo(JumpTableIndex, &BranchMI, Branch);
3526break;
3527 }
3528
3529 CurFn->JumpTables.push_back(
3530 {EntrySize,Base, BaseOffset,Branch,
3531 MF->getJTISymbol(JumpTableIndex,MMI->getContext()),
3532 JTI.getJumpTables()[JumpTableIndex].MBBs.size()});
3533 });
3534}
3535
3536void CodeViewDebug::emitDebugInfoForJumpTables(const FunctionInfo &FI) {
3537for (auto JumpTable : FI.JumpTables) {
3538MCSymbol *JumpTableEnd = beginSymbolRecord(SymbolKind::S_ARMSWITCHTABLE);
3539if (JumpTable.Base) {
3540 OS.AddComment("Base offset");
3541 OS.emitCOFFSecRel32(JumpTable.Base,JumpTable.BaseOffset);
3542 OS.AddComment("Base section index");
3543 OS.emitCOFFSectionIndex(JumpTable.Base);
3544 }else {
3545 OS.AddComment("Base offset");
3546 OS.emitInt32(0);
3547 OS.AddComment("Base section index");
3548 OS.emitInt16(0);
3549 }
3550 OS.AddComment("Switch type");
3551 OS.emitInt16(static_cast<uint16_t>(JumpTable.EntrySize));
3552 OS.AddComment("Branch offset");
3553 OS.emitCOFFSecRel32(JumpTable.Branch,/*Offset=*/0);
3554 OS.AddComment("Table offset");
3555 OS.emitCOFFSecRel32(JumpTable.Table,/*Offset=*/0);
3556 OS.AddComment("Branch section index");
3557 OS.emitCOFFSectionIndex(JumpTable.Branch);
3558 OS.AddComment("Table section index");
3559 OS.emitCOFFSectionIndex(JumpTable.Table);
3560 OS.AddComment("Entries count");
3561 OS.emitInt32(JumpTable.TableSize);
3562 endSymbolRecord(JumpTableEnd);
3563 }
3564}
3565
3566void CodeViewDebug::emitInlinees(
3567constSmallSet<codeview::TypeIndex, 1> &Inlinees) {
3568// Divide the list of inlinees into chunks such that each chunk fits within
3569// one record.
3570constexprsize_t ChunkSize =
3571 (MaxRecordLength -sizeof(SymbolKind) -sizeof(uint32_t)) /
3572sizeof(uint32_t);
3573
3574SmallVector<TypeIndex> SortedInlinees{Inlinees.begin(), Inlinees.end()};
3575llvm::sort(SortedInlinees);
3576
3577size_t CurrentIndex = 0;
3578while (CurrentIndex < SortedInlinees.size()) {
3579autoSymbol = beginSymbolRecord(SymbolKind::S_INLINEES);
3580auto CurrentChunkSize =
3581 std::min(ChunkSize, SortedInlinees.size() - CurrentIndex);
3582 OS.AddComment("Count");
3583 OS.emitInt32(CurrentChunkSize);
3584
3585constsize_t CurrentChunkEnd = CurrentIndex + CurrentChunkSize;
3586for (; CurrentIndex < CurrentChunkEnd; ++CurrentIndex) {
3587 OS.AddComment("Inlinee");
3588 OS.emitInt32(SortedInlinees[CurrentIndex].getIndex());
3589 }
3590 endSymbolRecord(Symbol);
3591 }
3592}
Success
#define Success
Definition:AArch64Disassembler.cpp:220
APSInt.h
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
isThumb
static bool isThumb(const MCSubtargetInfo &STI)
Definition:ARMAsmPrinter.cpp:483
MBB
MachineBasicBlock & MBB
Definition:ARMSLSHardening.cpp:71
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition:ARMSLSHardening.cpp:73
AsmPrinter.h
true
basic Basic Alias true
Definition:BasicAliasAnalysis.cpp:1981
COFF.h
BinaryStreamWriter.h
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Info
Analysis containing CSE Info
Definition:CSEInfo.cpp:27
CVTypeVisitor.h
Casting.h
canUseReferenceType
static bool canUseReferenceType(const DbgVariableLocation &Loc)
Definition:CodeViewDebug.cpp:1305
MapDWLangToCVLang
static SourceLanguage MapDWLangToCVLang(unsigned DWLang)
Definition:CodeViewDebug.cpp:570
translateMethodKindFlags
static MethodKind translateMethodKindFlags(const DISubprogram *SP, bool Introduced)
Definition:CodeViewDebug.cpp:2142
isUsableDebugLoc
static bool isUsableDebugLoc(DebugLoc DL)
Definition:CodeViewDebug.cpp:3086
getStringIdTypeIdx
static TypeIndex getStringIdTypeIdx(GlobalTypeTableBuilder &TypeTable, StringRef S)
Definition:CodeViewDebug.cpp:890
mapArchToCVCPUType
static CPUType mapArchToCVCPUType(Triple::ArchType Type)
Definition:CodeViewDebug.cpp:114
emitNullTerminatedSymbolName
static void emitNullTerminatedSymbolName(MCStreamer &OS, StringRef S, unsigned MaxFixedRecordLength=0xF00)
Definition:CodeViewDebug.cpp:710
parseVersion
static Version parseVersion(StringRef Name)
Definition:CodeViewDebug.cpp:818
translateMethodOptionFlags
static MethodOptions translateMethodOptionFlags(const DISubprogram *SP)
Definition:CodeViewDebug.cpp:2133
isNonTrivial
static bool isNonTrivial(const DICompositeType *DCTy)
Definition:CodeViewDebug.cpp:419
formatNestedName
static std::string formatNestedName(ArrayRef< StringRef > QualifiedNameComponents, StringRef TypeName)
Definition:CodeViewDebug.cpp:299
getCommonClassOptions
static ClassOptions getCommonClassOptions(const DICompositeType *Ty)
Return ClassOptions that should be present on both the forward declaration and the defintion of a tag...
Definition:CodeViewDebug.cpp:2175
translatePtrToMemberRep
static PointerToMemberRepresentation translatePtrToMemberRep(unsigned SizeInBytes, bool IsPMF, unsigned Flags)
Definition:CodeViewDebug.cpp:1911
getFunctionOptions
static FunctionOptions getFunctionOptions(const DISubroutineType *Ty, const DICompositeType *ClassTy=nullptr, StringRef SPName=StringRef(""))
Definition:CodeViewDebug.cpp:424
removeTemplateArgs
static StringRef removeTemplateArgs(StringRef Name)
Definition:CodeViewDebug.cpp:367
getRecordKind
static TypeRecordKind getRecordKind(const DICompositeType *Ty)
Definition:CodeViewDebug.cpp:2162
forEachJumpTableBranch
void forEachJumpTableBranch(const MachineFunction *MF, bool isThumb, const std::function< void(const MachineJumpTableInfo &, const MachineInstr &, int64_t)> &Callback)
Definition:CodeViewDebug.cpp:3433
dwarfCCToCodeView
static CallingConvention dwarfCCToCodeView(unsigned DwarfCC)
Given a DWARF calling convention, get the CodeView equivalent.
Definition:CodeViewDebug.cpp:1965
isFloatDIType
static bool isFloatDIType(const DIType *Ty)
Definition:CodeViewDebug.cpp:3359
addLocIfNotPresent
static void addLocIfNotPresent(SmallVectorImpl< const DILocation * > &Locs, const DILocation *Loc)
Definition:CodeViewDebug.cpp:502
shouldEmitUdt
static bool shouldEmitUdt(const DIType *T)
Definition:CodeViewDebug.cpp:1568
getPrettyScopeName
static StringRef getPrettyScopeName(const DIScope *Scope)
Definition:CodeViewDebug.cpp:260
shouldAlwaysEmitCompleteClassType
static bool shouldAlwaysEmitCompleteClassType(const DICompositeType *Ty)
Definition:CodeViewDebug.cpp:2390
needsReferenceType
static bool needsReferenceType(const DbgVariableLocation &Loc)
Definition:CodeViewDebug.cpp:1309
translateAccessFlags
static MemberAccess translateAccessFlags(unsigned RecordTag, unsigned Flags)
Definition:CodeViewDebug.cpp:2120
CodeViewDebug.h
CodeViewRecordIO.h
EnumTables.h
Constants.h
This file contains the declarations for the subclasses of Constant, which represent the different fla...
ContinuationRecordBuilder.h
Access
DXIL Resource Access
Definition:DXILResourceAccess.cpp:296
DataLayout.h
DebugInfoMetadata.h
DebugInlineeLinesSubsection.h
Dwarf.h
This file contains constants used for implementing Dwarf debug support.
Name
std::string Name
Definition:ELFObjHandler.cpp:77
Size
uint64_t Size
Definition:ELFObjHandler.cpp:81
End
bool End
Definition:ELF_riscv.cpp:480
Blocks
DenseMap< Block *, BlockRelaxAux > Blocks
Definition:ELF_riscv.cpp:507
FormatVariadic.h
GlobalValue.h
GlobalVariable.h
MI
IRTranslator LLVM IR MI
Definition:IRTranslator.cpp:112
Function.h
Module.h
Module.h This file contains the declarations for the Module class.
Options
static LVOptions Options
Definition:LVOptions.cpp:25
LexicalScopes.h
Line.h
MCAsmInfo.h
MCContext.h
MCSectionCOFF.h
MCStreamer.h
MCSymbol.h
F
#define F(x, y, z)
Definition:MD5.cpp:55
I
#define I(x, y, z)
Definition:MD5.cpp:58
MachineFrameInfo.h
MachineFunction.h
MachineInstr.h
MachineModuleInfo.h
TRI
unsigned const TargetRegisterInfo * TRI
Definition:MachineSink.cpp:2029
Metadata.h
This file contains the declarations for metadata subclasses.
Range
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
P
#define P(N)
Path.h
FuncId
Profile::FuncID FuncId
Definition:Profile.cpp:321
getName
static StringRef getName(Value *V)
Definition:ProvenanceAnalysisEvaluator.cpp:20
CC
auto CC
Definition:RISCVRedundantCopyElimination.cpp:79
Allocator
Basic Register Allocator
Definition:RegAllocBasic.cpp:146
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SMLoc.h
STLExtras.h
This file contains some templates that are useful if you are working with the STL at all.
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
ScopedPrinter.h
SmallBitVector.h
This file implements the SmallBitVector class.
SmallString.h
This file defines the SmallString class.
StringRef.h
SymbolRecord.h
getType
static SymbolRef::Type getType(const Symbol *Sym)
Definition:TapiFile.cpp:39
TargetFrameLowering.h
TargetLoweringObjectFile.h
TargetLowering.h
This file describes how to lower LLVM code to machine code.
TargetRegisterInfo.h
TargetSubtargetInfo.h
TinyPtrVector.h
Triple.h
Twine.h
TypeRecord.h
TypeTableCollection.h
TypeVisitorCallbackPipeline.h
IV
static const uint32_t IV[8]
Definition:blake3_impl.h:78
BaseTy
Node
Definition:ItaniumDemangle.h:163
QualifiedName
Definition:ItaniumDemangle.h:1153
T
llvm::APInt
Class for arbitrary precision integers.
Definition:APInt.h:78
llvm::APSInt
An arbitrary precision integer that knows its signedness.
Definition:APSInt.h:23
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::ArrayRef::drop_front
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition:ArrayRef.h:207
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition:ArrayRef.h:168
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition:AsmPrinter.h:87
llvm::AsmPrinter::getObjFileLowering
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition:AsmPrinter.cpp:408
llvm::AsmPrinter::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition:AsmPrinter.cpp:697
llvm::AsmPrinter::TM
TargetMachine & TM
Target machine description.
Definition:AsmPrinter.h:90
llvm::AsmPrinter::getFunctionBegin
MCSymbol * getFunctionBegin() const
Definition:AsmPrinter.h:269
llvm::AsmPrinter::MAI
const MCAsmInfo * MAI
Target Asm Printer information.
Definition:AsmPrinter.h:93
llvm::AsmPrinter::MF
MachineFunction * MF
The current machine function.
Definition:AsmPrinter.h:105
llvm::AsmPrinter::hasDebugInfo
bool hasDebugInfo() const
Returns true if valid debug info is present.
Definition:AsmPrinter.h:440
llvm::AsmPrinter::getFunctionEnd
MCSymbol * getFunctionEnd() const
Definition:AsmPrinter.h:270
llvm::AsmPrinter::getCodeViewJumpTableInfo
virtual std::tuple< const MCSymbol *, uint64_t, const MCSymbol *, codeview::JumpTableEntrySize > getCodeViewJumpTableInfo(int JTI, const MachineInstr *BranchInstr, const MCSymbol *BranchLabel) const
Gets information required to create a CodeView debug symbol for a jump table.
Definition:AsmPrinter.cpp:4631
llvm::BinaryStreamWriter
Provides write only access to a subclass of WritableBinaryStream.
Definition:BinaryStreamWriter.h:30
llvm::CodeViewDebug
Collects and handles line tables information in a CodeView format.
Definition:CodeViewDebug.h:55
llvm::CodeViewDebug::CodeViewDebug
CodeViewDebug(AsmPrinter *AP)
Definition:CodeViewDebug.cpp:133
llvm::CodeViewDebug::beginModule
void beginModule(Module *M) override
Definition:CodeViewDebug.cpp:613
llvm::CodeViewDebug::moduleIsInFortran
bool moduleIsInFortran()
Check if the current module is in Fortran.
Definition:CodeViewDebug.h:511
llvm::CodeViewDebug::endFunctionImpl
void endFunctionImpl(const MachineFunction *) override
Gather post-function debug information.
Definition:CodeViewDebug.cpp:3033
llvm::CodeViewDebug::endModule
void endModule() override
Emit the COFF section that holds the line table information.
Definition:CodeViewDebug.cpp:638
llvm::CodeViewDebug::beginInstruction
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
Definition:CodeViewDebug.cpp:3090
llvm::CodeViewDebug::beginFunctionImpl
void beginFunctionImpl(const MachineFunction *MF) override
Gather pre-function debug information.
Definition:CodeViewDebug.cpp:1442
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition:Constants.h:271
llvm::ConstantInt
This is the shared class of boolean and integer constants.
Definition:Constants.h:83
llvm::ConstantInt::isZero
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Definition:Constants.h:208
llvm::DIBasicType
Basic type, like 'int' or 'float'.
Definition:DebugInfoMetadata.h:823
llvm::DIBasicType::getEncoding
unsigned getEncoding() const
Definition:DebugInfoMetadata.h:891
llvm::DICompositeType
Composite types.
Definition:DebugInfoMetadata.h:1174
llvm::DICompositeType::getIdentifier
StringRef getIdentifier() const
Definition:DebugInfoMetadata.h:1328
llvm::DICompositeType::getElements
DINodeArray getElements() const
Definition:DebugInfoMetadata.h:1319
llvm::DICompositeType::getBaseType
DIType * getBaseType() const
Definition:DebugInfoMetadata.h:1318
llvm::DIDerivedType
Derived types.
Definition:DebugInfoMetadata.h:997
llvm::DIDerivedType::getClassType
DIType * getClassType() const
Get casted version of extra data.
Definition:DebugInfoMetadata.cpp:707
llvm::DIDerivedType::getConstant
Constant * getConstant() const
Definition:DebugInfoMetadata.cpp:725
llvm::DIE
A structured debug information entry.
Definition:DIE.h:819
llvm::DIExpression
DWARF expression.
Definition:DebugInfoMetadata.h:2763
llvm::DIFile
File.
Definition:DebugInfoMetadata.h:573
llvm::DIFile::CSK_SHA1
@ CSK_SHA1
Definition:DebugInfoMetadata.h:588
llvm::DIFile::CSK_MD5
@ CSK_MD5
Definition:DebugInfoMetadata.h:587
llvm::DIFile::CSK_SHA256
@ CSK_SHA256
Definition:DebugInfoMetadata.h:589
llvm::DIGlobalVariable
Global variables.
Definition:DebugInfoMetadata.h:3315
llvm::DIGlobalVariable::isLocalToUnit
bool isLocalToUnit() const
Definition:DebugInfoMetadata.h:3378
llvm::DIGlobalVariable::getRawStaticDataMemberDeclaration
Metadata * getRawStaticDataMemberDeclaration() const
Definition:DebugInfoMetadata.h:3390
llvm::DILexicalBlock
Debug lexical block.
Definition:DebugInfoMetadata.h:2283
llvm::DILocalVariable
Local variable.
Definition:DebugInfoMetadata.h:3460
llvm::DILocalVariable::getScope
DILocalScope * getScope() const
Get the local scope for this variable.
Definition:DebugInfoMetadata.h:3518
llvm::DILocation
Debug location.
Definition:DebugInfoMetadata.h:1988
llvm::DINode
Tagged DWARF-like metadata node.
Definition:DebugInfoMetadata.h:135
llvm::DINode::getTag
dwarf::Tag getTag() const
Definition:DebugInfoMetadata.cpp:288
llvm::DINode::FlagPtrToMemberRep
@ FlagPtrToMemberRep
Definition:DebugInfoMetadata.h:179
llvm::DINode::FlagAccessibility
@ FlagAccessibility
Definition:DebugInfoMetadata.h:178
llvm::DIScope
Base class for scope-like contexts.
Definition:DebugInfoMetadata.h:519
llvm::DIScope::getFilename
StringRef getFilename() const
Definition:DebugInfoMetadata.h:685
llvm::DIScope::getName
StringRef getName() const
Definition:DebugInfoMetadata.cpp:368
llvm::DIScope::getFile
DIFile * getFile() const
Definition:DebugInfoMetadata.h:527
llvm::DIScope::getDirectory
StringRef getDirectory() const
Definition:DebugInfoMetadata.h:691
llvm::DIScope::getScope
DIScope * getScope() const
Definition:DebugInfoMetadata.cpp:344
llvm::DIStringType
String type, Fortran CHARACTER(n)
Definition:DebugInfoMetadata.h:905
llvm::DISubprogram
Subprogram description.
Definition:DebugInfoMetadata.h:1710
llvm::DISubrange
Array subrange.
Definition:DebugInfoMetadata.h:348
llvm::DISubroutineType
Type array for a subprogram.
Definition:DebugInfoMetadata.h:1412
llvm::DISubroutineType::getCC
uint8_t getCC() const
Definition:DebugInfoMetadata.h:1455
llvm::DISubroutineType::getTypeArray
DITypeRefArray getTypeArray() const
Definition:DebugInfoMetadata.h:1457
llvm::DITypeRefArray
Definition:DebugInfoMetadata.h:73
llvm::DITypeRefArray::size
unsigned size() const
Definition:DebugInfoMetadata.h:88
llvm::DIType
Base class for types.
Definition:DebugInfoMetadata.h:710
llvm::DIType::getOffsetInBits
uint64_t getOffsetInBits() const
Definition:DebugInfoMetadata.h:758
llvm::DIType::isObjectPointer
bool isObjectPointer() const
Definition:DebugInfoMetadata.h:788
llvm::DIType::getFlags
DIFlags getFlags() const
Definition:DebugInfoMetadata.h:760
llvm::DIType::getName
StringRef getName() const
Definition:DebugInfoMetadata.h:763
llvm::DIType::isForwardDecl
bool isForwardDecl() const
Definition:DebugInfoMetadata.h:784
llvm::DIType::getSizeInBits
uint64_t getSizeInBits() const
Definition:DebugInfoMetadata.h:755
llvm::DIType::getLine
unsigned getLine() const
Definition:DebugInfoMetadata.h:754
llvm::DIType::getScope
DIScope * getScope() const
Definition:DebugInfoMetadata.h:762
llvm::DIVariable::getScope
DIScope * getScope() const
Definition:DebugInfoMetadata.h:2708
llvm::DIVariable::getType
DIType * getType() const
Definition:DebugInfoMetadata.h:2711
llvm::DIVariable::getName
StringRef getName() const
Definition:DebugInfoMetadata.h:2709
llvm::DWARFExpression::Operation
This class represents an Operation in the Expression.
Definition:DWARFExpression.h:32
llvm::DataLayout::getPointerSizeInBits
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
Definition:DataLayout.h:364
llvm::DbgValueHistoryMap::NoEntry
static const EntryIndex NoEntry
Special value to indicate that an entry is valid until the end of the function.
Definition:DbgEntityHistoryCalculator.h:53
llvm::DebugHandlerBase
Base class for debug information backends.
Definition:DebugHandlerBase.h:53
llvm::DebugHandlerBase::isUnsignedDIType
static bool isUnsignedDIType(const DIType *Ty)
Return true if type encoding is unsigned.
Definition:DebugHandlerBase.cpp:179
llvm::DebugHandlerBase::Asm
AsmPrinter * Asm
Target of debug info emission.
Definition:DebugHandlerBase.h:58
llvm::DebugHandlerBase::getLabelBeforeInsn
MCSymbol * getLabelBeforeInsn(const MachineInstr *MI)
Return Label preceding the instruction.
Definition:DebugHandlerBase.cpp:137
llvm::DebugHandlerBase::MMI
MachineModuleInfo * MMI
Collected machine module information.
Definition:DebugHandlerBase.h:61
llvm::DebugHandlerBase::PrevInstLoc
DebugLoc PrevInstLoc
Previous instruction's location information.
Definition:DebugHandlerBase.h:67
llvm::DebugHandlerBase::getLabelAfterInsn
MCSymbol * getLabelAfterInsn(const MachineInstr *MI)
Return Label immediately following the instruction.
Definition:DebugHandlerBase.cpp:144
llvm::DebugHandlerBase::beginInstruction
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
Definition:DebugHandlerBase.cpp:353
llvm::DebugHandlerBase::PrevInstBB
const MachineBasicBlock * PrevInstBB
Definition:DebugHandlerBase.h:69
llvm::DebugHandlerBase::requestLabelAfterInsn
void requestLabelAfterInsn(const MachineInstr *MI)
Ensure that a label will be emitted after MI.
Definition:DebugHandlerBase.h:108
llvm::DebugHandlerBase::DbgValues
DbgValueHistoryMap DbgValues
History of DBG_VALUE and clobber instructions for each user variable.
Definition:DebugHandlerBase.h:85
llvm::DebugHandlerBase::requestLabelBeforeInsn
void requestLabelBeforeInsn(const MachineInstr *MI)
Ensure that a label will be emitted before MI.
Definition:DebugHandlerBase.h:103
llvm::DebugHandlerBase::LScopes
LexicalScopes LScopes
Definition:DebugHandlerBase.h:81
llvm::DebugHandlerBase::PrologEndLoc
const MachineInstr * PrologEndLoc
This location indicates end of function prologue and beginning of function body.
Definition:DebugHandlerBase.h:73
llvm::DebugHandlerBase::getBaseTypeSize
static uint64_t getBaseTypeSize(const DIType *Ty)
If this type is derived from a base type then return base type size.
Definition:DebugHandlerBase.cpp:149
llvm::DebugLoc
A debug info location.
Definition:DebugLoc.h:33
llvm::DebugLoc::get
DILocation * get() const
Get the underlying DILocation.
Definition:DebugLoc.cpp:20
llvm::DenseMapBase::lookup
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition:DenseMap.h:194
llvm::DenseMapBase::size
unsigned size() const
Definition:DenseMap.h:99
llvm::DenseMapBase::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition:DenseMap.h:152
llvm::DenseMapBase::insert
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition:DenseMap.h:211
llvm::DenseMapBase::clear
void clear()
Definition:DenseMap.h:110
llvm::DenseMap
Definition:DenseMap.h:727
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition:DenseSet.h:278
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Function
Definition:Function.h:63
llvm::Function::hasOptSize
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
Definition:Function.h:707
llvm::Function::hasStackProtectorFnAttr
bool hasStackProtectorFnAttr() const
Returns true if the function has ssp, sspstrong, or sspreq fn attrs.
Definition:Function.cpp:852
llvm::Function::getSubprogram
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition:Metadata.cpp:1874
llvm::Function::hasPersonalityFn
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition:Function.h:905
llvm::Function::getPersonalityFn
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition:Function.cpp:1048
llvm::Function::hasProfileData
bool hasProfileData(bool IncludeSynthetic=false) const
Return true if the function is annotated with profile data.
Definition:Function.h:329
llvm::Function::hasOptNone
bool hasOptNone() const
Do not optimize this function (-O0).
Definition:Function.h:701
llvm::Function::hasFnAttribute
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition:Function.cpp:731
llvm::GlobalObject::hasComdat
bool hasComdat() const
Definition:GlobalObject.h:127
llvm::GlobalValue::isThreadLocal
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
Definition:GlobalValue.h:264
llvm::GlobalValue::hasLocalLinkage
bool hasLocalLinkage() const
Definition:GlobalValue.h:529
llvm::GlobalValue::dropLLVMManglingEscape
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Definition:GlobalValue.h:568
llvm::GlobalValue::isDeclarationForLinker
bool isDeclarationForLinker() const
Definition:GlobalValue.h:619
llvm::GlobalVariable
Definition:GlobalVariable.h:39
llvm::LexicalScope
LexicalScope - This class is used to track scope information.
Definition:LexicalScopes.h:44
llvm::LexicalScopes::findLexicalScope
LexicalScope * findLexicalScope(const DILocation *DL)
findLexicalScope - Find lexical scope, either regular or inlined, for the given DebugLoc.
Definition:LexicalScopes.cpp:124
llvm::LexicalScopes::findInlinedScope
LexicalScope * findInlinedScope(const DILocalScope *N, const DILocation *IA)
findInlinedScope - Find an inlined scope for the given scope/inlined-at.
Definition:LexicalScopes.h:186
llvm::LexicalScopes::getCurrentFunctionScope
LexicalScope * getCurrentFunctionScope() const
getCurrentFunctionScope - Return lexical scope for the current function.
Definition:LexicalScopes.h:156
llvm::MCAsmInfo::getCodePointerSize
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition:MCAsmInfo.h:449
llvm::MCContext::allocate
void * allocate(unsigned Size, unsigned Align=8)
Definition:MCContext.h:816
llvm::MCContext::createTempSymbol
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition:MCContext.cpp:345
llvm::MCContext::getAssociativeCOFFSection
MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym, unsigned UniqueID=GenericSectionID)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym.
Definition:MCContext.cpp:733
llvm::MCObjectFileInfo::getCOFFDebugSymbolsSection
MCSection * getCOFFDebugSymbolsSection() const
Definition:MCObjectFileInfo.h:345
llvm::MCObjectFileInfo::getCOFFDebugTypesSection
MCSection * getCOFFDebugTypesSection() const
Definition:MCObjectFileInfo.h:348
llvm::MCObjectFileInfo::getCOFFGlobalTypeHashesSection
MCSection * getCOFFGlobalTypeHashesSection() const
Definition:MCObjectFileInfo.h:351
llvm::MCSectionCOFF
This represents a section on Windows.
Definition:MCSectionCOFF.h:27
llvm::MCSectionCOFF::getCOMDATSymbol
MCSymbol * getCOMDATSymbol() const
Definition:MCSectionCOFF.h:70
llvm::MCStreamer
Streaming machine code generation interface.
Definition:MCStreamer.h:213
llvm::MCStreamer::addBlankLine
virtual void addBlankLine()
Emit a blank line to a .s file to pretty it up.
Definition:MCStreamer.h:387
llvm::MCStreamer::emitCVFuncIdDirective
virtual bool emitCVFuncIdDirective(unsigned FunctionId)
Introduces a function id for use with .cv_loc.
Definition:MCStreamer.cpp:307
llvm::MCStreamer::emitBinaryData
virtual void emitBinaryData(StringRef Data)
Functionally identical to EmitBytes.
Definition:MCStreamer.cpp:1267
llvm::MCStreamer::emitCVFileDirective
virtual bool emitCVFileDirective(unsigned FileNo, StringRef Filename, ArrayRef< uint8_t > Checksum, unsigned ChecksumKind)
Associate a filename with a specified logical file number, and also specify that file's checksum info...
Definition:MCStreamer.cpp:300
llvm::MCStreamer::emitCVStringTableDirective
virtual void emitCVStringTableDirective()
This implements the CodeView '.cv_stringtable' assembler directive.
Definition:MCStreamer.h:986
llvm::MCStreamer::isVerboseAsm
virtual bool isVerboseAsm() const
Return true if this streamer supports verbose assembly and if it is enabled.
Definition:MCStreamer.h:343
llvm::MCStreamer::emitCVFileChecksumOffsetDirective
virtual void emitCVFileChecksumOffsetDirective(unsigned FileNo)
This implements the CodeView '.cv_filechecksumoffset' assembler directive.
Definition:MCStreamer.h:993
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition:MCStreamer.h:300
llvm::MCStreamer::AddComment
virtual void AddComment(const Twine &T, bool EOL=true)
Add a textual comment.
Definition:MCStreamer.h:366
llvm::MCStreamer::emitCVFPOData
virtual void emitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc={})
This implements the CodeView '.cv_fpo_data' assembler directive.
Definition:MCStreamer.h:996
llvm::MCStreamer::emitCOFFSecRel32
virtual void emitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset)
Emits a COFF section relative relocation.
Definition:MCStreamer.cpp:1022
llvm::MCStreamer::emitCVFileChecksumsDirective
virtual void emitCVFileChecksumsDirective()
This implements the CodeView '.cv_filechecksums' assembler directive.
Definition:MCStreamer.h:989
llvm::MCStreamer::emitAbsoluteSymbolDiff
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
Definition:MCStreamer.cpp:1172
llvm::MCStreamer::emitLabel
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition:MCStreamer.cpp:420
llvm::MCStreamer::emitCOFFSectionIndex
virtual void emitCOFFSectionIndex(MCSymbol const *Symbol)
Emits a COFF section index.
Definition:MCStreamer.cpp:1020
llvm::MCStreamer::emitCVLinetableDirective
virtual void emitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart, const MCSymbol *FnEnd)
This implements the CodeView '.cv_linetable' assembler directive.
Definition:MCStreamer.cpp:352
llvm::MCStreamer::emitValueToAlignment
virtual void emitValueToAlignment(Align Alignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
Definition:MCStreamer.cpp:1276
llvm::MCStreamer::emitIntValue
virtual void emitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
Definition:MCStreamer.cpp:133
llvm::MCStreamer::emitInt16
void emitInt16(uint64_t Value)
Definition:MCStreamer.h:728
llvm::MCStreamer::switchSection
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
Definition:MCStreamer.cpp:1303
llvm::MCStreamer::emitCVDefRangeDirective
virtual void emitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol * > > Ranges, StringRef FixedSizePortion)
This implements the CodeView '.cv_def_range' assembler directive.
Definition:MCStreamer.cpp:374
llvm::MCStreamer::emitInt32
void emitInt32(uint64_t Value)
Definition:MCStreamer.h:729
llvm::MCStreamer::emitCVLocDirective
virtual void emitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt, StringRef FileName, SMLoc Loc)
This implements the CodeView '.cv_loc' assembler directive.
Definition:MCStreamer.cpp:325
llvm::MCStreamer::emitCVInlineSiteIdDirective
virtual bool emitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc, unsigned IAFile, unsigned IALine, unsigned IACol, SMLoc Loc)
Introduces an inline call site id for use with .cv_loc.
Definition:MCStreamer.cpp:311
llvm::MCStreamer::emitInt8
void emitInt8(uint64_t Value)
Definition:MCStreamer.h:727
llvm::MCStreamer::emitCVInlineLinetableDirective
virtual void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
This implements the CodeView '.cv_inline_linetable' assembler directive.
Definition:MCStreamer.cpp:356
llvm::MCStreamer::emitBytes
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition:MCStreamer.cpp:1266
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition:MCSymbol.h:41
llvm::MCSymbol::getSection
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition:MCSymbol.h:269
llvm::MCTargetOptions::CommandlineArgs
std::string CommandlineArgs
Definition:MCTargetOptions.h:102
llvm::MCTargetOptions::Argv0
std::string Argv0
Definition:MCTargetOptions.h:101
llvm::MDNode
Metadata node.
Definition:Metadata.h:1073
llvm::MDNode::operands
ArrayRef< MDOperand > operands() const
Definition:Metadata.h:1432
llvm::MDNode::getNumOperands
unsigned getNumOperands() const
Return number of MDNode operands.
Definition:Metadata.h:1440
llvm::MDTuple
Tuple of metadata.
Definition:Metadata.h:1479
llvm::MachineBasicBlock::instr_rbegin
reverse_instr_iterator instr_rbegin()
Definition:MachineBasicBlock.h:343
llvm::MachineBasicBlock::getFirstTerminator
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
Definition:MachineBasicBlock.cpp:244
llvm::MachineBasicBlock::instr_rend
reverse_instr_iterator instr_rend()
Definition:MachineBasicBlock.h:345
llvm::MachineBasicBlock::end
iterator end()
Definition:MachineBasicBlock.h:357
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition:MachineFrameInfo.h:106
llvm::MachineFrameInfo::hasVarSizedObjects
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
Definition:MachineFrameInfo.h:357
llvm::MachineFrameInfo::getStackSize
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
Definition:MachineFrameInfo.h:587
llvm::MachineFrameInfo::getOffsetAdjustment
int64_t getOffsetAdjustment() const
Return the correction for frame offsets.
Definition:MachineFrameInfo.h:596
llvm::MachineFrameInfo::getCVBytesOfCalleeSavedRegisters
unsigned getCVBytesOfCalleeSavedRegisters() const
Returns how many bytes of callee-saved registers the target pushed in the prologue.
Definition:MachineFrameInfo.h:680
llvm::MachineFrameInfo::hasStackProtectorIndex
bool hasStackProtectorIndex() const
Definition:MachineFrameInfo.h:362
llvm::MachineFunction::VariableDbgInfo
Description of the location of a variable whose Address is valid and unchanging during function execu...
Definition:MachineFunction.h:427
llvm::MachineFunction
Definition:MachineFunction.h:267
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition:MachineFunction.h:733
llvm::MachineFunction::hasInlineAsm
bool hasInlineAsm() const
Returns true if the function contains any inline assembly.
Definition:MachineFunction.h:806
llvm::MachineFunction::exposesReturnsTwice
bool exposesReturnsTwice() const
exposesReturnsTwice - Returns true if the function calls setjmp or any other similar functions with a...
Definition:MachineFunction.h:795
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition:MachineFunction.h:749
llvm::MachineFunction::getJTISymbol
MCSymbol * getJTISymbol(unsigned JTI, MCContext &Ctx, bool isLinkerPrivate=false) const
getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
Definition:MachineFunction.cpp:787
llvm::MachineFunction::getInStackSlotVariableDbgInfo
auto getInStackSlotVariableDbgInfo()
Returns the collection of variables for which we have debug info and that have been assigned a stack ...
Definition:MachineFunction.h:1374
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition:MachineFunction.h:704
llvm::MachineFunction::getJumpTableInfo
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
Definition:MachineFunction.h:756
llvm::MachineFunction::getCodeViewAnnotations
ArrayRef< std::pair< MCSymbol *, MDNode * > > getCodeViewAnnotations() const
Definition:MachineFunction.h:1336
llvm::MachineInstr
Representation of each machine instruction.
Definition:MachineInstr.h:71
llvm::MachineInstr::FrameSetup
@ FrameSetup
Definition:MachineInstr.h:87
llvm::MachineInstr::isDebugValue
bool isDebugValue() const
Definition:MachineInstr.h:1362
llvm::MachineInstr::getDebugOperand
MachineOperand & getDebugOperand(unsigned Index)
Definition:MachineInstr.h:596
llvm::MachineJumpTableInfo
Definition:MachineJumpTableInfo.h:46
llvm::MachineJumpTableInfo::EK_GPRel32BlockAddress
@ EK_GPRel32BlockAddress
EK_GPRel32BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
Definition:MachineJumpTableInfo.h:63
llvm::MachineJumpTableInfo::EK_Inline
@ EK_Inline
EK_Inline - Jump table entries are emitted inline at their point of use.
Definition:MachineJumpTableInfo.h:82
llvm::MachineJumpTableInfo::EK_LabelDifference32
@ EK_LabelDifference32
EK_LabelDifference32 - Each entry is the address of the block minus the address of the jump table.
Definition:MachineJumpTableInfo.h:72
llvm::MachineJumpTableInfo::EK_Custom32
@ EK_Custom32
EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the TargetLowering::LowerCustomJ...
Definition:MachineJumpTableInfo.h:86
llvm::MachineJumpTableInfo::EK_LabelDifference64
@ EK_LabelDifference64
EK_LabelDifference64 - Each entry is the address of the block minus the address of the jump table.
Definition:MachineJumpTableInfo.h:78
llvm::MachineJumpTableInfo::EK_BlockAddress
@ EK_BlockAddress
EK_BlockAddress - Each entry is a plain address of block, e.g.: .word LBB123.
Definition:MachineJumpTableInfo.h:53
llvm::MachineJumpTableInfo::EK_GPRel64BlockAddress
@ EK_GPRel64BlockAddress
EK_GPRel64BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
Definition:MachineJumpTableInfo.h:58
llvm::MachineJumpTableInfo::getEntryKind
JTEntryKind getEntryKind() const
Definition:MachineJumpTableInfo.h:95
llvm::MachineJumpTableInfo::getJumpTables
const std::vector< MachineJumpTableEntry > & getJumpTables() const
Definition:MachineJumpTableInfo.h:110
llvm::MachineModuleInfo::getContext
const MCContext & getContext() const
Definition:MachineModuleInfo.h:125
llvm::MachineModuleInfo::getModule
const Module * getModule() const
Definition:MachineModuleInfo.h:132
llvm::MapVector< MDString *, MethodsList >
llvm::Metadata
Root of the metadata hierarchy.
Definition:Metadata.h:62
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition:Module.h:65
llvm::Module::getNamedMetadata
NamedMDNode * getNamedMetadata(StringRef Name) const
Return the first NamedMDNode in the module with the specified name.
Definition:Module.cpp:297
llvm::Module::getTargetTriple
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
Definition:Module.h:298
llvm::Module::globals
iterator_range< global_iterator > globals()
Definition:Module.h:702
llvm::Module::getDataLayout
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition:Module.h:294
llvm::Module::getProfileSummary
Metadata * getProfileSummary(bool IsCS) const
Returns profile summary metadata.
Definition:Module.cpp:689
llvm::NamedMDNode
A tuple of MDNodes.
Definition:Metadata.h:1737
llvm::NamedMDNode::operands
iterator_range< op_iterator > operands()
Definition:Metadata.h:1833
llvm::Record
Definition:Record.h:1596
llvm::Record::getType
const RecordRecTy * getType() const
Definition:Record.cpp:2876
llvm::Register
Wrapper class representing virtual and physical registers.
Definition:Register.h:19
llvm::SMLoc
Represents a location in source code.
Definition:SMLoc.h:23
llvm::SmallBitVector
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
Definition:SmallBitVector.h:35
llvm::SmallSet
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition:SmallSet.h:132
llvm::SmallSet::begin
const_iterator begin() const
Definition:SmallSet.h:209
llvm::SmallSet::end
const_iterator end() const
Definition:SmallSet.h:215
llvm::SmallString
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition:SmallString.h:26
llvm::SmallVectorBase::empty
bool empty() const
Definition:SmallVector.h:81
llvm::SmallVectorBase::size
size_t size() const
Definition:SmallVector.h:78
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition:SmallVector.h:573
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition:SmallVector.h:937
llvm::SmallVectorImpl::append
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
Definition:SmallVector.h:683
llvm::SmallVectorImpl::clear
void clear()
Definition:SmallVector.h:610
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVectorTemplateCommon::end
iterator end()
Definition:SmallVector.h:269
llvm::SmallVectorTemplateCommon::begin
iterator begin()
Definition:SmallVector.h:267
llvm::SmallVectorTemplateCommon::back
reference back()
Definition:SmallVector.h:308
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StackOffset
StackOffset holds a fixed and a scalable offset in bytes.
Definition:TypeSize.h:33
llvm::StackOffset::getScalable
static StackOffset getScalable(int64_t Scalable)
Definition:TypeSize.h:43
llvm::StackOffset::getFixed
static StackOffset getFixed(int64_t Fixed)
Definition:TypeSize.h:42
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::starts_with
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition:StringRef.h:265
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition:StringRef.h:147
llvm::StringRef::back
char back() const
back - Get the last character in the string.
Definition:StringRef.h:159
llvm::StringRef::take_front
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
Definition:StringRef.h:580
llvm::TargetFrameLowering
Information about stack frame layout on the target.
Definition:TargetFrameLowering.h:45
llvm::TargetFrameLowering::hasFP
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
Definition:TargetFrameLowering.h:285
llvm::TargetFrameLowering::getFrameIndexReference
virtual StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
Definition:TargetFrameLoweringImpl.cpp:48
llvm::TargetMachine::getOptLevel
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Definition:TargetMachine.h:257
llvm::TargetMachine::Options
TargetOptions Options
Definition:TargetMachine.h:118
llvm::TargetOptions::MCOptions
MCTargetOptions MCOptions
Machine level options.
Definition:TargetOptions.h:463
llvm::TargetOptions::ObjectFilenameForDebug
std::string ObjectFilenameForDebug
Stores the filename/path of the final .o/.obj file, to be written in the debug information.
Definition:TargetOptions.h:468
llvm::TargetOptions::Hotpatch
unsigned Hotpatch
Emit the hotpatch flag in CodeView debug.
Definition:TargetOptions.h:363
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition:TargetRegisterInfo.h:235
llvm::TargetSubtargetInfo
TargetSubtargetInfo - Generic base class for all target subtargets.
Definition:TargetSubtargetInfo.h:63
llvm::TargetSubtargetInfo::getRegisterInfo
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
Definition:TargetSubtargetInfo.h:129
llvm::TargetSubtargetInfo::getFrameLowering
virtual const TargetFrameLowering * getFrameLowering() const
Definition:TargetSubtargetInfo.h:98
llvm::TinyPtrVector
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
Definition:TinyPtrVector.h:29
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition:Triple.h:44
llvm::Triple::ArchType
ArchType
Definition:Triple.h:46
llvm::Triple::x86
@ x86
Definition:Triple.h:85
llvm::Triple::thumb
@ thumb
Definition:Triple.h:83
llvm::Triple::getArch
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition:Triple.h:395
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition:Twine.h:81
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition:Value.cpp:309
llvm::codeview::ArgListRecord
Definition:TypeRecord.h:236
llvm::codeview::ArrayRecord
Definition:TypeRecord.h:396
llvm::codeview::BaseClassRecord
Definition:TypeRecord.h:863
llvm::codeview::BitFieldRecord
Definition:TypeRecord.h:535
llvm::codeview::BuildInfoRecord
Definition:TypeRecord.h:667
llvm::codeview::BuildInfoRecord::CurrentDirectory
@ CurrentDirectory
Absolute CWD path.
Definition:TypeRecord.h:678
llvm::codeview::BuildInfoRecord::SourceFile
@ SourceFile
Path to main source file, relative or absolute.
Definition:TypeRecord.h:680
llvm::codeview::BuildInfoRecord::BuildTool
@ BuildTool
Absolute compiler path.
Definition:TypeRecord.h:679
llvm::codeview::BuildInfoRecord::MaxArgs
@ MaxArgs
Definition:TypeRecord.h:683
llvm::codeview::BuildInfoRecord::CommandLine
@ CommandLine
Full canonical command line (maybe -cc1)
Definition:TypeRecord.h:682
llvm::codeview::BuildInfoRecord::TypeServerPDB
@ TypeServerPDB
Absolute path of type server PDB (/Fd)
Definition:TypeRecord.h:681
llvm::codeview::CVRecord< TypeLeafKind >
llvm::codeview::ClassRecord
Definition:TypeRecord.h:465
llvm::codeview::CodeViewRecordIO
Definition:CodeViewRecordIO.h:43
llvm::codeview::CodeViewRecordStreamer
Definition:CodeViewRecordIO.h:31
llvm::codeview::CodeViewRecordStreamer::emitBytes
virtual void emitBytes(StringRef Data)=0
llvm::codeview::CodeViewRecordStreamer::isVerboseAsm
virtual bool isVerboseAsm()=0
llvm::codeview::CodeViewRecordStreamer::AddComment
virtual void AddComment(const Twine &T)=0
llvm::codeview::CodeViewRecordStreamer::emitIntValue
virtual void emitIntValue(uint64_t Value, unsigned Size)=0
llvm::codeview::CodeViewRecordStreamer::emitBinaryData
virtual void emitBinaryData(StringRef Data)=0
llvm::codeview::CodeViewRecordStreamer::AddRawComment
virtual void AddRawComment(const Twine &T)=0
llvm::codeview::ColumnInfo
Definition:Line.h:62
llvm::codeview::ContinuationRecordBuilder
Definition:ContinuationRecordBuilder.h:26
llvm::codeview::ContinuationRecordBuilder::begin
void begin(ContinuationRecordKind RecordKind)
Definition:ContinuationRecordBuilder.cpp:51
llvm::codeview::ContinuationRecordBuilder::writeMemberType
void writeMemberType(RecordType &Record)
Definition:ContinuationRecordBuilder.cpp:78
llvm::codeview::DataMemberRecord
Definition:TypeRecord.h:783
llvm::codeview::DataSym
Definition:SymbolRecord.h:956
llvm::codeview::DefRangeRegisterRelSym::OffsetInParentShift
@ OffsetInParentShift
Definition:SymbolRecord.h:591
llvm::codeview::DefRangeRegisterRelSym::IsSubfieldFlag
@ IsSubfieldFlag
Definition:SymbolRecord.h:590
llvm::codeview::EnumRecord
Definition:TypeRecord.h:519
llvm::codeview::EnumeratorRecord
Definition:TypeRecord.h:829
llvm::codeview::FuncIdRecord
Definition:TypeRecord.h:610
llvm::codeview::GlobalTypeTableBuilder
Definition:GlobalTypeTableBuilder.h:29
llvm::codeview::GlobalTypeTableBuilder::records
ArrayRef< ArrayRef< uint8_t > > records() const
Definition:GlobalTypeTableBuilder.cpp:66
llvm::codeview::GlobalTypeTableBuilder::insertRecord
TypeIndex insertRecord(ContinuationRecordBuilder &Builder)
Definition:GlobalTypeTableBuilder.cpp:98
llvm::codeview::GlobalTypeTableBuilder::hashes
ArrayRef< GloballyHashedType > hashes() const
Definition:GlobalTypeTableBuilder.cpp:70
llvm::codeview::GlobalTypeTableBuilder::writeLeafType
TypeIndex writeLeafType(T &Record)
Definition:GlobalTypeTableBuilder.h:110
llvm::codeview::LineInfo
Definition:Line.h:20
llvm::codeview::MemberFuncIdRecord
Definition:TypeRecord.h:217
llvm::codeview::MemberFunctionRecord
Definition:TypeRecord.h:171
llvm::codeview::MemberPointerInfo
Definition:TypeRecord.h:100
llvm::codeview::MethodOverloadListRecord
Definition:TypeRecord.h:751
llvm::codeview::ModifierRecord
Definition:TypeRecord.h:130
llvm::codeview::NestedTypeRecord
Definition:TypeRecord.h:370
llvm::codeview::OneMethodRecord
Definition:TypeRecord.h:719
llvm::codeview::OverloadedMethodRecord
For method overload sets. LF_METHOD.
Definition:TypeRecord.h:764
llvm::codeview::PointerRecord
Definition:TypeRecord.h:264
llvm::codeview::ProcedureRecord
Definition:TypeRecord.h:146
llvm::codeview::StaticDataMemberRecord
Definition:TypeRecord.h:808
llvm::codeview::StringIdRecord
Definition:TypeRecord.h:595
llvm::codeview::TypeCollection
Definition:TypeCollection.h:18
llvm::codeview::TypeCollection::empty
bool empty()
Definition:TypeCollection.h:22
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition:TypeIndex.h:96
llvm::codeview::TypeIndex::getSimpleKind
SimpleTypeKind getSimpleKind() const
Definition:TypeIndex.h:136
llvm::codeview::TypeIndex::None
static TypeIndex None()
Definition:TypeIndex.h:148
llvm::codeview::TypeIndex::isSimple
bool isSimple() const
Definition:TypeIndex.h:113
llvm::codeview::TypeIndex::getSimpleMode
SimpleTypeMode getSimpleMode() const
Definition:TypeIndex.h:141
llvm::codeview::TypeIndex::FirstNonSimpleIndex
static const uint32_t FirstNonSimpleIndex
Definition:TypeIndex.h:98
llvm::codeview::TypeIndex::simpleTypeName
static StringRef simpleTypeName(TypeIndex TI)
Definition:TypeIndex.cpp:71
llvm::codeview::TypeIndex::Void
static TypeIndex Void()
Definition:TypeIndex.h:149
llvm::codeview::TypeIndex::getIndex
uint32_t getIndex() const
Definition:TypeIndex.h:111
llvm::codeview::TypeIndex::isNoneType
bool isNoneType() const
Definition:TypeIndex.h:116
llvm::codeview::TypeIndex::NullptrT
static TypeIndex NullptrT()
Definition:TypeIndex.h:157
llvm::codeview::TypeIndex::Int32
static TypeIndex Int32()
Definition:TypeIndex.h:182
llvm::codeview::TypeRecordMapping
Definition:TypeRecordMapping.h:26
llvm::codeview::TypeTableCollection
Definition:TypeTableCollection.h:20
llvm::codeview::TypeVisitorCallbackPipeline
Definition:TypeVisitorCallbackPipeline.h:21
llvm::codeview::TypeVisitorCallbackPipeline::addCallbackToPipeline
void addCallbackToPipeline(TypeVisitorCallbacks &Callbacks)
Definition:TypeVisitorCallbackPipeline.h:81
llvm::codeview::UdtSourceLineRecord
Definition:TypeRecord.h:628
llvm::codeview::VFPtrRecord
Definition:TypeRecord.h:850
llvm::codeview::VFTableShapeRecord
Definition:TypeRecord.h:553
llvm::codeview::VirtualBaseClassRecord
Definition:TypeRecord.h:884
llvm::detail::DenseSetImpl::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition:DenseSet.h:213
llvm::detail::DenseSetImpl::count
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition:DenseSet.h:95
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition:raw_ostream.h:691
uint16_t
uint32_t
uint64_t
uint8_t
unsigned
ErrorHandling.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
Error.h
TargetMachine.h
CU
Definition:AArch64AsmBackend.cpp:549
llvm::AArch64CC::LS
@ LS
Definition:AArch64BaseInfo.h:264
llvm::AMDGPU::HSAMD::Kernel::Arg::Key::TypeName
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
Definition:AMDGPUMetadata.h:176
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition:ARMBuildAttributes.h:83
llvm::COFF::DEBUG_HASHES_SECTION_MAGIC
@ DEBUG_HASHES_SECTION_MAGIC
Definition:COFF.h:822
llvm::COFF::DEBUG_SECTION_MAGIC
@ DEBUG_SECTION_MAGIC
Definition:COFF.h:821
llvm::COFF::Entry
@ Entry
Definition:COFF.h:844
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::ISD::JumpTable
@ JumpTable
Definition:ISDOpcodes.h:81
llvm::M68k::MemAddrModeKind::L
@ L
llvm::MCID::Branch
@ Branch
Definition:MCInstrDesc.h:159
llvm::RISCVFenceField::R
@ R
Definition:RISCVBaseInfo.h:373
llvm::SIEncodingFamily::VI
@ VI
Definition:SIDefines.h:37
llvm::TailPredication::Mode
Mode
Definition:ARMTargetTransformInfo.h:43
llvm::X86Disassembler::Reg
Reg
All possible values of the reg field in the ModR/M byte.
Definition:X86DisassemblerDecoder.h:621
llvm::codeview
Definition:AppendingTypeTableBuilder.h:22
llvm::codeview::DebugSubsectionKind
DebugSubsectionKind
Definition:CodeView.h:322
llvm::codeview::PointerMode
PointerMode
Equivalent to CV_ptrmode_e.
Definition:CodeView.h:363
llvm::codeview::ProcSymFlags
ProcSymFlags
Corresponds to the CV_PROCFLAGS bitfield.
Definition:CodeView.h:443
llvm::codeview::PointerOptions
PointerOptions
Equivalent to misc lfPointerAttr bitfields.
Definition:CodeView.h:372
llvm::codeview::LocalSymFlags
LocalSymFlags
Corresponds to CV_LVARFLAGS bitfield.
Definition:CodeView.h:416
llvm::codeview::MethodKind
MethodKind
Part of member attribute flags. (CV_methodprop_e)
Definition:CodeView.h:280
llvm::codeview::RegisterId
RegisterId
Definition:CodeView.h:529
llvm::codeview::MaxRecordLength
@ MaxRecordLength
Definition:RecordSerialization.h:30
llvm::codeview::PointerKind
PointerKind
Equivalent to CV_ptrtype_e.
Definition:CodeView.h:346
llvm::codeview::CPUType
CPUType
These values correspond to the CV_CPU_TYPE_e enumeration, and are documented here: https://msdn....
Definition:CodeView.h:76
llvm::codeview::ClassOptions
ClassOptions
Definition:CodeView.h:213
llvm::codeview::ClassOptions::Nested
@ Nested
llvm::codeview::ClassOptions::ContainsNestedClass
@ ContainsNestedClass
llvm::codeview::PointerToMemberRepresentation
PointerToMemberRepresentation
Equivalent to CV_pmtype_e.
Definition:CodeView.h:386
llvm::codeview::CallingConvention
CallingConvention
These values correspond to the CV_call_e enumeration, and are documented at the following locations: ...
Definition:CodeView.h:184
llvm::codeview::MethodOptions
MethodOptions
Equivalent to CV_fldattr_t bitfield.
Definition:CodeView.h:291
llvm::codeview::JumpTableEntrySize
JumpTableEntrySize
Definition:CodeView.h:636
llvm::codeview::getSymbolTypeNames
ArrayRef< EnumEntry< SymbolKind > > getSymbolTypeNames()
Definition:EnumTables.cpp:458
llvm::codeview::FunctionOptions
FunctionOptions
Definition:CodeView.h:256
llvm::codeview::MemberAccess
MemberAccess
Source-level access specifier. (CV_access_e)
Definition:CodeView.h:272
llvm::codeview::SimpleTypeMode
SimpleTypeMode
Definition:TypeIndex.h:82
llvm::codeview::SimpleTypeKind
SimpleTypeKind
Definition:TypeIndex.h:26
llvm::codeview::SimpleTypeKind::UInt32Long
@ UInt32Long
llvm::codeview::ThunkOrdinal
ThunkOrdinal
These values correspond to the THUNK_ORDINAL enumeration.
Definition:CodeView.h:563
llvm::codeview::EncodedFramePtrReg
EncodedFramePtrReg
Two-bit value indicating which register is the designated frame pointer register.
Definition:CodeView.h:551
llvm::codeview::TypeRecordKind
TypeRecordKind
Distinguishes individual records in .debug$T or .debug$P section or PDB type stream.
Definition:CodeView.h:27
llvm::codeview::SymbolKind
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
Definition:CodeView.h:48
llvm::codeview::FileChecksumKind
FileChecksumKind
Definition:CodeView.h:576
llvm::codeview::ModifierOptions
ModifierOptions
Equivalent to CV_modifier_t.
Definition:CodeView.h:311
llvm::codeview::FrameProcedureOptions
FrameProcedureOptions
Definition:CodeView.h:230
llvm::codeview::getSymbolName
StringRef getSymbolName(CVSymbol Sym)
Definition:RecordName.cpp:323
llvm::codeview::encodeFramePtrReg
EncodedFramePtrReg encodeFramePtrReg(RegisterId Reg, CPUType CPU)
Definition:SymbolRecordMapping.cpp:533
llvm::codeview::visitTypeRecord
Error visitTypeRecord(CVType &Record, TypeIndex Index, TypeVisitorCallbacks &Callbacks, VisitorDataSource Source=VDS_BytesPresent)
Definition:CVTypeVisitor.cpp:219
llvm::codeview::SourceLanguage
SourceLanguage
These values correspond to the CV_CFL_LANG enumeration in the Microsoft Debug Interface Access SDK,...
Definition:CodeView.h:146
llvm::dwarf::TypeKind
TypeKind
Definition:Dwarf.h:157
llvm::dwarf::Index
Index
Definition:Dwarf.h:882
llvm::dwarf::Tag
Tag
Definition:Dwarf.h:103
llvm::dxil::ElementType
ElementType
The element type of an SRV or UAV resource.
Definition:DXILABI.h:58
llvm::jitlink::Scope
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
Definition:JITLink.h:412
llvm::lltok::Kind
Kind
Definition:LLToken.h:18
llvm::logicalview::LVTypeKind::IsModifier
@ IsModifier
llvm::logicalview::LVWarningKind::Ranges
@ Ranges
llvm::logicalview::LVPrintKind::Elements
@ Elements
llvm::logicalview::LVAttributeKind::Subrange
@ Subrange
llvm::logicalview::LVAttributeKind::Location
@ Location
llvm::objcopy::DiscardType::Locals
@ Locals
llvm::omp::RTLDependInfoFields::Flags
@ Flags
llvm::pdb::PDB_SymType::UDT
@ UDT
llvm::pdb::PDB_SymType::Label
@ Label
llvm::pdb::PDB_SymType::Inlinee
@ Inlinee
llvm::pdb::PDB_DataKind::Member
@ Member
llvm::pdb::PDB_ColorItem::Comment
@ Comment
llvm::sampleprof::Base
@ Base
Definition:Discriminator.h:58
llvm::sys::path::Style::posix
@ posix
llvm::sys::path::is_absolute
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
Definition:Path.cpp:671
llvm::tgtok::Class
@ Class
Definition:TGLexer.h:94
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::logAllUnhandledErrors
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
Definition:Error.cpp:65
llvm::PseudoProbeType::Block
@ Block
llvm::InlineSite
std::tuple< uint64_t, uint32_t > InlineSite
Definition:MCPseudoProbe.h:101
llvm::formatv
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
Definition:FormatVariadic.h:252
llvm::reverse
auto reverse(ContainerTy &&C)
Definition:STLExtras.h:420
llvm::get
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
Definition:PointerIntPair.h:270
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition:STLExtras.h:1664
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition:Error.cpp:167
llvm::classifyEHPersonality
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Definition:EHPersonalities.cpp:23
llvm::CodeGenOptLevel::None
@ None
-O0
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition:raw_ostream.cpp:907
llvm::getTypeName
StringRef getTypeName()
We provide a function which tries to compute the (demangled) name of a type statically.
Definition:TypeName.h:63
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition:Error.h:756
llvm::isAsynchronousEHPersonality
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
Definition:EHPersonalities.h:50
llvm::HighlightColor::Enumerator
@ Enumerator
llvm::is_contained
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition:STLExtras.h:1903
llvm::endianness::little
@ little
llvm::Data
@ Data
Definition:SIMachineScheduler.h:55
llvm::InsnRange
std::pair< const MachineInstr *, const MachineInstr * > InsnRange
InsnRange - This is used to track range of instructions with identical lexical scope.
Definition:LexicalScopes.h:39
llvm::Version
@ Version
Definition:PGOCtxProfWriter.h:22
std::swap
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition:BitVector.h:860
N
#define N
llvm::CodeViewDebug::TypeLoweringScope
Definition:CodeViewDebug.cpp:311
llvm::CodeViewDebug::TypeLoweringScope::CVD
CodeViewDebug & CVD
Definition:CodeViewDebug.cpp:320
llvm::CodeViewDebug::TypeLoweringScope::~TypeLoweringScope
~TypeLoweringScope()
Definition:CodeViewDebug.cpp:313
llvm::CodeViewDebug::TypeLoweringScope::TypeLoweringScope
TypeLoweringScope(CodeViewDebug &CVD)
Definition:CodeViewDebug.cpp:312
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition:Alignment.h:39
llvm::ClassInfo::MemberInfo
Definition:CodeViewDebug.cpp:2272
llvm::ClassInfo::MemberInfo::BaseOffset
uint64_t BaseOffset
Definition:CodeViewDebug.cpp:2274
llvm::ClassInfo::MemberInfo::MemberTypeNode
const DIDerivedType * MemberTypeNode
Definition:CodeViewDebug.cpp:2273
llvm::ClassInfo
Definition:CodeViewDebug.cpp:2271
llvm::ClassInfo::MemberList
std::vector< MemberInfo > MemberList
Definition:CodeViewDebug.cpp:2277
llvm::ClassInfo::Members
MemberList Members
Direct members.
Definition:CodeViewDebug.cpp:2287
llvm::ClassInfo::NestedTypes
std::vector< const DIType * > NestedTypes
Definition:CodeViewDebug.cpp:2293
llvm::ClassInfo::Inheritance
std::vector< const DIDerivedType * > Inheritance
Base classes.
Definition:CodeViewDebug.cpp:2284
llvm::ClassInfo::VShapeTI
TypeIndex VShapeTI
Definition:CodeViewDebug.cpp:2291
llvm::ClassInfo::Methods
MethodsMap Methods
Definition:CodeViewDebug.cpp:2289
llvm::CodeViewDebug::LocalVarDef
Definition:CodeViewDebug.h:57
llvm::CodeViewDebug::LocalVarDef::InMemory
int InMemory
Indicates that variable data is stored in memory relative to the specified register.
Definition:CodeViewDebug.h:60
llvm::DbgVariableLocation
Represents the location at which a variable is stored.
Definition:DebugHandlerBase.h:31
llvm::DbgVariableLocation::extractFromMachineInstruction
static std::optional< DbgVariableLocation > extractFromMachineInstruction(const MachineInstr &Instruction)
Extract a VariableLocation from a MachineInstr.
Definition:DebugHandlerBase.cpp:34
llvm::DbgVariableLocation::LoadChain
SmallVector< int64_t, 1 > LoadChain
Chain of offsetted loads necessary to load the value if it lives in memory.
Definition:DebugHandlerBase.h:37
llvm::EnumEntry
Definition:ScopedPrinter.h:24
llvm::codeview::DefRangeFramePointerRelHeader
Definition:SymbolRecord.h:545
llvm::codeview::DefRangeFramePointerRelHeader::Offset
little32_t Offset
Definition:SymbolRecord.h:546
llvm::codeview::DefRangeRegisterHeader
Definition:SymbolRecord.h:499
llvm::codeview::DefRangeRegisterHeader::Register
ulittle16_t Register
Definition:SymbolRecord.h:500
llvm::codeview::DefRangeRegisterHeader::MayHaveNoName
ulittle16_t MayHaveNoName
Definition:SymbolRecord.h:501
llvm::codeview::DefRangeRegisterRelHeader
Definition:SymbolRecord.h:571
llvm::codeview::DefRangeRegisterRelHeader::Flags
ulittle16_t Flags
Definition:SymbolRecord.h:573
llvm::codeview::DefRangeRegisterRelHeader::Register
ulittle16_t Register
Definition:SymbolRecord.h:572
llvm::codeview::DefRangeRegisterRelHeader::BasePointerOffset
little32_t BasePointerOffset
Definition:SymbolRecord.h:574
llvm::codeview::DefRangeSubfieldRegisterHeader
Definition:SymbolRecord.h:521
llvm::codeview::DefRangeSubfieldRegisterHeader::MayHaveNoName
ulittle16_t MayHaveNoName
Definition:SymbolRecord.h:523
llvm::codeview::DefRangeSubfieldRegisterHeader::Register
ulittle16_t Register
Definition:SymbolRecord.h:522
llvm::codeview::DefRangeSubfieldRegisterHeader::OffsetInParent
ulittle32_t OffsetInParent
Definition:SymbolRecord.h:524
llvm::codeview::UnionRecord
Definition:TypeRecord.h:498

Generated on Fri Jul 18 2025 10:27:24 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp