1 //===- CodeView.h -----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Defines constants and basic types describing CodeView debug information.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_DEBUGINFO_CODEVIEW_CODEVIEW_H
15 #define LLVM_DEBUGINFO_CODEVIEW_CODEVIEW_H
18 #include <type_traits>
20 #include "llvm/Support/Endian.h"
25 /// Distinguishes individual records in .debug$T section or PDB type stream. The
26 /// documentation and headers talk about this as the "leaf" type.
27 enum class TypeRecordKind : uint16_t {
28 #define TYPE_RECORD(lf_ename, value, name) name = value,
29 #include "CodeViewTypes.def"
32 /// Duplicate copy of the above enum, but using the official CV names. Useful
33 /// for reference purposes and when dealing with unknown record types.
34 enum TypeLeafKind : uint16_t {
35 #define CV_TYPE(name, val) name = val,
36 #include "CodeViewTypes.def"
39 /// Distinguishes individual records in the Symbols subsection of a .debug$S
40 /// section. Equivalent to SYM_ENUM_e in cvinfo.h.
41 enum class SymbolRecordKind : uint16_t {
42 #define SYMBOL_RECORD(lf_ename, value, name) name = value,
43 #include "CodeViewSymbols.def"
46 /// Duplicate copy of the above enum, but using the official CV names. Useful
47 /// for reference purposes and when dealing with unknown record types.
48 enum SymbolKind : uint16_t {
49 #define CV_SYMBOL(name, val) name = val,
50 #include "CodeViewSymbols.def"
53 #define CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(Class) \
54 inline Class operator|(Class a, Class b) { \
55 return static_cast<Class>( \
56 static_cast<std::underlying_type<Class>::type>(a) | \
57 static_cast<std::underlying_type<Class>::type>(b)); \
59 inline Class operator&(Class a, Class b) { \
60 return static_cast<Class>( \
61 static_cast<std::underlying_type<Class>::type>(a) & \
62 static_cast<std::underlying_type<Class>::type>(b)); \
64 inline Class operator~(Class a) { \
65 return static_cast<Class>( \
66 ~static_cast<std::underlying_type<Class>::type>(a)); \
68 inline Class &operator|=(Class &a, Class b) { \
72 inline Class &operator&=(Class &a, Class b) { \
77 /// These values correspond to the CV_CPU_TYPE_e enumeration, and are documented
78 /// here: https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx
79 enum class CPUType : uint16_t {
138 D3D11_Shader = 0x100,
141 /// These values correspond to the CV_CFL_LANG enumeration, and are documented
142 /// here: https://msdn.microsoft.com/en-us/library/bw3aekw6.aspx
143 enum SourceLanguage : uint8_t {
163 /// These values correspond to the CV_call_e enumeration, and are documented
164 /// at the following locations:
165 /// https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx
166 /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680207(v=vs.85).aspx
168 enum class CallingConvention : uint8_t {
169 NearC = 0x00, // near right to left push, caller pops stack
170 FarC = 0x01, // far right to left push, caller pops stack
171 NearPascal = 0x02, // near left to right push, callee pops stack
172 FarPascal = 0x03, // far left to right push, callee pops stack
173 NearFast = 0x04, // near left to right push with regs, callee pops stack
174 FarFast = 0x05, // far left to right push with regs, callee pops stack
175 NearStdCall = 0x07, // near standard call
176 FarStdCall = 0x08, // far standard call
177 NearSysCall = 0x09, // near sys call
178 FarSysCall = 0x0a, // far sys call
179 ThisCall = 0x0b, // this call (this passed in register)
180 MipsCall = 0x0c, // Mips call
181 Generic = 0x0d, // Generic call sequence
182 AlphaCall = 0x0e, // Alpha call
183 PpcCall = 0x0f, // PPC call
184 SHCall = 0x10, // Hitachi SuperH call
185 ArmCall = 0x11, // ARM call
186 AM33Call = 0x12, // AM33 call
187 TriCall = 0x13, // TriCore Call
188 SH5Call = 0x14, // Hitachi SuperH-5 call
189 M32RCall = 0x15, // M32R Call
190 ClrCall = 0x16, // clr call
192 0x17, // Marker for routines always inlined and thus lacking a convention
193 NearVector = 0x18 // near left to right push with regs, callee pops stack
196 enum class ClassOptions : uint16_t {
199 HasConstructorOrDestructor = 0x0002,
200 HasOverloadedOperator = 0x0004,
202 ContainsNestedClass = 0x0010,
203 HasOverloadedAssignmentOperator = 0x0020,
204 HasConversionOperator = 0x0040,
205 ForwardReference = 0x0080,
207 HasUniqueName = 0x0200,
211 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ClassOptions)
213 enum class FrameProcedureOptions : uint32_t {
215 HasAlloca = 0x00000001,
216 HasSetJmp = 0x00000002,
217 HasLongJmp = 0x00000004,
218 HasInlineAssembly = 0x00000008,
219 HasExceptionHandling = 0x00000010,
220 MarkedInline = 0x00000020,
221 HasStructuredExceptionHandling = 0x00000040,
223 SecurityChecks = 0x00000100,
224 AsynchronousExceptionHandling = 0x00000200,
225 NoStackOrderingForSecurityChecks = 0x00000400,
226 Inlined = 0x00000800,
227 StrictSecurityChecks = 0x00001000,
228 SafeBuffers = 0x00002000,
229 ProfileGuidedOptimization = 0x00040000,
230 ValidProfileCounts = 0x00080000,
231 OptimizedForSpeed = 0x00100000,
232 GuardCfg = 0x00200000,
233 GuardCfw = 0x00400000
235 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(FrameProcedureOptions)
237 enum class FunctionOptions : uint8_t {
241 ConstructorWithVirtualBases = 0x04
243 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(FunctionOptions)
245 enum class HfaKind : uint8_t {
252 /// Source-level access specifier. (CV_access_e)
253 enum class MemberAccess : uint8_t {
260 /// Part of member attribute flags. (CV_methodprop_e)
261 enum class MethodKind : uint8_t {
266 IntroducingVirtual = 0x04,
268 PureIntroducingVirtual = 0x06
271 /// Equivalent to CV_fldattr_t bitfield.
272 enum class MethodOptions : uint16_t {
275 MethodKindMask = 0x001c,
278 NoConstruct = 0x0080,
279 CompilerGenerated = 0x0100,
282 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(MethodOptions)
284 /// Equivalent to CV_LABEL_TYPE_e.
285 enum class LabelType : uint16_t {
290 /// Equivalent to CV_modifier_t.
291 /// TODO: Add flag for _Atomic modifier
292 enum class ModifierOptions : uint16_t {
298 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ModifierOptions)
300 enum class DebugSubsectionKind : uint32_t {
305 FileChecksums = 0xf4,
308 CrossScopeImports = 0xf7,
309 CrossScopeExports = 0xf8,
311 // These appear to relate to .Net assembly info.
313 FuncMDTokenMap = 0xfa,
314 TypeMDTokenMap = 0xfb,
315 MergedAssemblyInput = 0xfc,
317 CoffSymbolRVA = 0xfd,
320 /// Equivalent to CV_ptrtype_e.
321 enum class PointerKind : uint8_t {
322 Near16 = 0x00, // 16 bit pointer
323 Far16 = 0x01, // 16:16 far pointer
324 Huge16 = 0x02, // 16:16 huge pointer
325 BasedOnSegment = 0x03, // based on segment
326 BasedOnValue = 0x04, // based on value of base
327 BasedOnSegmentValue = 0x05, // based on segment value of base
328 BasedOnAddress = 0x06, // based on address of base
329 BasedOnSegmentAddress = 0x07, // based on segment address of base
330 BasedOnType = 0x08, // based on type
331 BasedOnSelf = 0x09, // based on self
332 Near32 = 0x0a, // 32 bit pointer
333 Far32 = 0x0b, // 16:32 pointer
334 Near64 = 0x0c // 64 bit pointer
337 /// Equivalent to CV_ptrmode_e.
338 enum class PointerMode : uint8_t {
339 Pointer = 0x00, // "normal" pointer
340 LValueReference = 0x01, // "old" reference
341 PointerToDataMember = 0x02, // pointer to data member
342 PointerToMemberFunction = 0x03, // pointer to member function
343 RValueReference = 0x04 // r-value reference
346 /// Equivalent to misc lfPointerAttr bitfields.
347 enum class PointerOptions : uint32_t {
350 Volatile = 0x00000200,
352 Unaligned = 0x00000800,
353 Restrict = 0x00001000,
354 WinRTSmartPointer = 0x00080000
356 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(PointerOptions)
358 /// Equivalent to CV_pmtype_e.
359 enum class PointerToMemberRepresentation : uint16_t {
360 Unknown = 0x00, // not specified (pre VC8)
361 SingleInheritanceData = 0x01, // member data, single inheritance
362 MultipleInheritanceData = 0x02, // member data, multiple inheritance
363 VirtualInheritanceData = 0x03, // member data, virtual inheritance
364 GeneralData = 0x04, // member data, most general
365 SingleInheritanceFunction = 0x05, // member function, single inheritance
366 MultipleInheritanceFunction = 0x06, // member function, multiple inheritance
367 VirtualInheritanceFunction = 0x07, // member function, virtual inheritance
368 GeneralFunction = 0x08 // member function, most general
371 enum class VFTableSlotKind : uint8_t {
381 enum class WindowsRTClassKind : uint8_t {
388 /// Corresponds to CV_LVARFLAGS bitfield.
389 enum class LocalSymFlags : uint16_t {
391 IsParameter = 1 << 0,
392 IsAddressTaken = 1 << 1,
393 IsCompilerGenerated = 1 << 2,
394 IsAggregate = 1 << 3,
395 IsAggregated = 1 << 4,
398 IsReturnValue = 1 << 7,
399 IsOptimizedOut = 1 << 8,
400 IsEnregisteredGlobal = 1 << 9,
401 IsEnregisteredStatic = 1 << 10,
403 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(LocalSymFlags)
405 /// Corresponds to the CV_PROCFLAGS bitfield.
406 enum class ProcSymFlags : uint8_t {
412 IsUnreachable = 1 << 4,
413 HasCustomCallingConv = 1 << 5,
415 HasOptimizedDebugInfo = 1 << 7,
417 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ProcSymFlags)
419 /// Corresponds to COMPILESYM2::Flags bitfield.
420 enum class CompileSym2Flags : uint32_t {
422 SourceLanguageMask = 0xFF,
426 NoDataAlign = 1 << 11,
427 ManagedPresent = 1 << 12,
428 SecurityChecks = 1 << 13,
431 MSILModule = 1 << 16,
433 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(CompileSym2Flags)
435 /// Corresponds to COMPILESYM3::Flags bitfield.
436 enum class CompileSym3Flags : uint32_t {
438 SourceLanguageMask = 0xFF,
442 NoDataAlign = 1 << 11,
443 ManagedPresent = 1 << 12,
444 SecurityChecks = 1 << 13,
447 MSILModule = 1 << 16,
452 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(CompileSym3Flags)
454 enum class ExportFlags : uint16_t {
460 HasExplicitOrdinal = 1 << 4,
463 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ExportFlags)
465 // Corresponds to BinaryAnnotationOpcode enum.
466 enum class BinaryAnnotationsOpCode : uint32_t {
469 ChangeCodeOffsetBase,
477 ChangeColumnEndDelta,
478 ChangeCodeOffsetAndLineOffset,
479 ChangeCodeLengthAndCodeOffset,
483 // Corresponds to CV_cookietype_e enum.
484 enum class FrameCookieKind : uint8_t {
491 // Corresponds to CV_HREG_e enum.
492 enum class RegisterId : uint16_t {
544 /// These values correspond to the THUNK_ORDINAL enumeration.
545 enum class ThunkOrdinal : uint8_t {
555 enum class TrampolineType : uint16_t { TrampIncremental, BranchIsland };
557 // These values correspond to the CV_SourceChksum_t enumeration.
558 enum class FileChecksumKind : uint8_t { None, MD5, SHA1, SHA256 };
560 enum LineFlags : uint16_t {
562 LF_HaveColumns = 1, // CV_LINES_HAVE_COLUMNS
565 /// Data in the the SUBSEC_FRAMEDATA subection.
567 support::ulittle32_t RvaStart;
568 support::ulittle32_t CodeSize;
569 support::ulittle32_t LocalSize;
570 support::ulittle32_t ParamsSize;
571 support::ulittle32_t MaxStackSize;
572 support::ulittle32_t FrameFunc;
573 support::ulittle16_t PrologSize;
574 support::ulittle16_t SavedRegsSize;
575 support::ulittle32_t Flags;
579 IsFunctionStart = 1 << 2,
583 // Corresponds to LocalIdAndGlobalIdPair structure.
584 // This structure information allows cross-referencing between PDBs. For
585 // example, when a PDB is being built during compilation it is not yet known
586 // what other modules may end up in the PDB at link time. So certain types of
587 // IDs may clash between the various compile time PDBs. For each affected
588 // module, a subsection would be put into the PDB containing a mapping from its
589 // local IDs to a single ID namespace for all items in the PDB file.
590 struct CrossModuleExport {
591 support::ulittle32_t Local;
592 support::ulittle32_t Global;
595 struct CrossModuleImport {
596 support::ulittle32_t ModuleNameOffset;
597 support::ulittle32_t Count; // Number of elements
598 // support::ulittle32_t ids[Count]; // id from referenced module
601 enum class CodeViewContainer { ObjectFile, Pdb };
603 inline uint32_t alignOf(CodeViewContainer Container) {
604 if (Container == CodeViewContainer::ObjectFile)