1 //===- CodeView.h -----------------------------------------------*- C++ -*-===//
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 // Defines constants and basic types describing CodeView debug information.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_DEBUGINFO_CODEVIEW_CODEVIEW_H
14 #define LLVM_DEBUGINFO_CODEVIEW_CODEVIEW_H
15
16 #include <cinttypes>
17 #include <type_traits>
18
19 #include "llvm/Support/Endian.h"
20
21 namespace llvm {
22 namespace codeview {
23
24 /// Distinguishes individual records in .debug$T or .debug$P section or PDB type
25 /// stream. The documentation and headers talk about this as the "leaf" type.
26 enum class TypeRecordKind : uint16_t {
27 #define TYPE_RECORD(lf_ename, value, name) name = value,
28 #include "CodeViewTypes.def"
29 };
30
31 /// Duplicate copy of the above enum, but using the official CV names. Useful
32 /// for reference purposes and when dealing with unknown record types.
33 enum TypeLeafKind : uint16_t {
34 #define CV_TYPE(name, val) name = val,
35 #include "CodeViewTypes.def"
36 };
37
38 /// Distinguishes individual records in the Symbols subsection of a .debug$S
39 /// section. Equivalent to SYM_ENUM_e in cvinfo.h.
40 enum class SymbolRecordKind : uint16_t {
41 #define SYMBOL_RECORD(lf_ename, value, name) name = value,
42 #include "CodeViewSymbols.def"
43 };
44
45 /// Duplicate copy of the above enum, but using the official CV names. Useful
46 /// for reference purposes and when dealing with unknown record types.
47 enum SymbolKind : uint16_t {
48 #define CV_SYMBOL(name, val) name = val,
49 #include "CodeViewSymbols.def"
50 };
51
52 #define CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(Class) \
53 inline Class operator|(Class a, Class b) { \
54 return static_cast<Class>( \
55 static_cast<std::underlying_type<Class>::type>(a) | \
56 static_cast<std::underlying_type<Class>::type>(b)); \
57 } \
58 inline Class operator&(Class a, Class b) { \
59 return static_cast<Class>( \
60 static_cast<std::underlying_type<Class>::type>(a) & \
61 static_cast<std::underlying_type<Class>::type>(b)); \
62 } \
63 inline Class operator~(Class a) { \
64 return static_cast<Class>( \
65 ~static_cast<std::underlying_type<Class>::type>(a)); \
66 } \
67 inline Class &operator|=(Class &a, Class b) { \
68 a = a | b; \
69 return a; \
70 } \
71 inline Class &operator&=(Class &a, Class b) { \
72 a = a & b; \
73 return a; \
74 }
75
76 /// These values correspond to the CV_CPU_TYPE_e enumeration, and are documented
77 /// here: https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx
78 enum class CPUType : uint16_t {
79 Intel8080 = 0x0,
80 Intel8086 = 0x1,
81 Intel80286 = 0x2,
82 Intel80386 = 0x3,
83 Intel80486 = 0x4,
84 Pentium = 0x5,
85 PentiumPro = 0x6,
86 Pentium3 = 0x7,
87 MIPS = 0x10,
88 MIPS16 = 0x11,
89 MIPS32 = 0x12,
90 MIPS64 = 0x13,
91 MIPSI = 0x14,
92 MIPSII = 0x15,
93 MIPSIII = 0x16,
94 MIPSIV = 0x17,
95 MIPSV = 0x18,
96 M68000 = 0x20,
97 M68010 = 0x21,
98 M68020 = 0x22,
99 M68030 = 0x23,
100 M68040 = 0x24,
101 Alpha = 0x30,
102 Alpha21164 = 0x31,
103 Alpha21164A = 0x32,
104 Alpha21264 = 0x33,
105 Alpha21364 = 0x34,
106 PPC601 = 0x40,
107 PPC603 = 0x41,
108 PPC604 = 0x42,
109 PPC620 = 0x43,
110 PPCFP = 0x44,
111 PPCBE = 0x45,
112 SH3 = 0x50,
113 SH3E = 0x51,
114 SH3DSP = 0x52,
115 SH4 = 0x53,
116 SHMedia = 0x54,
117 ARM3 = 0x60,
118 ARM4 = 0x61,
119 ARM4T = 0x62,
120 ARM5 = 0x63,
121 ARM5T = 0x64,
122 ARM6 = 0x65,
123 ARM_XMAC = 0x66,
124 ARM_WMMX = 0x67,
125 ARM7 = 0x68,
126 Omni = 0x70,
127 Ia64 = 0x80,
128 Ia64_2 = 0x81,
129 CEE = 0x90,
130 AM33 = 0xa0,
131 M32R = 0xb0,
132 TriCore = 0xc0,
133 X64 = 0xd0,
134 EBC = 0xe0,
135 Thumb = 0xf0,
136 ARMNT = 0xf4,
137 ARM64 = 0xf6,
138 HybridX86ARM64 = 0xf7,
139 ARM64EC = 0xf8,
140 ARM64X = 0xf9,
141 D3D11_Shader = 0x100,
142 };
143
144 /// These values correspond to the CV_CFL_LANG enumeration, and are documented
145 /// here: https://msdn.microsoft.com/en-us/library/bw3aekw6.aspx
146 enum SourceLanguage : uint8_t {
147 C = 0x00,
148 Cpp = 0x01,
149 Fortran = 0x02,
150 Masm = 0x03,
151 Pascal = 0x04,
152 Basic = 0x05,
153 Cobol = 0x06,
154 Link = 0x07,
155 Cvtres = 0x08,
156 Cvtpgd = 0x09,
157 CSharp = 0x0a,
158 VB = 0x0b,
159 ILAsm = 0x0c,
160 Java = 0x0d,
161 JScript = 0x0e,
162 MSIL = 0x0f,
163 HLSL = 0x10,
164
165 /// The DMD & Swift compilers emit 'D' and 'S', respectively, for the CV
166 /// source language. Microsoft does not have enumerators for them yet.
167 D = 'D',
168 Swift = 'S',
169 };
170
171 /// These values correspond to the CV_call_e enumeration, and are documented
172 /// at the following locations:
173 /// https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx
174 /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680207(v=vs.85).aspx
175 ///
176 enum class CallingConvention : uint8_t {
177 NearC = 0x00, // near right to left push, caller pops stack
178 FarC = 0x01, // far right to left push, caller pops stack
179 NearPascal = 0x02, // near left to right push, callee pops stack
180 FarPascal = 0x03, // far left to right push, callee pops stack
181 NearFast = 0x04, // near left to right push with regs, callee pops stack
182 FarFast = 0x05, // far left to right push with regs, callee pops stack
183 NearStdCall = 0x07, // near standard call
184 FarStdCall = 0x08, // far standard call
185 NearSysCall = 0x09, // near sys call
186 FarSysCall = 0x0a, // far sys call
187 ThisCall = 0x0b, // this call (this passed in register)
188 MipsCall = 0x0c, // Mips call
189 Generic = 0x0d, // Generic call sequence
190 AlphaCall = 0x0e, // Alpha call
191 PpcCall = 0x0f, // PPC call
192 SHCall = 0x10, // Hitachi SuperH call
193 ArmCall = 0x11, // ARM call
194 AM33Call = 0x12, // AM33 call
195 TriCall = 0x13, // TriCore Call
196 SH5Call = 0x14, // Hitachi SuperH-5 call
197 M32RCall = 0x15, // M32R Call
198 ClrCall = 0x16, // clr call
199 Inline =
200 0x17, // Marker for routines always inlined and thus lacking a convention
201 NearVector = 0x18 // near left to right push with regs, callee pops stack
202 };
203
204 enum class ClassOptions : uint16_t {
205 None = 0x0000,
206 Packed = 0x0001,
207 HasConstructorOrDestructor = 0x0002,
208 HasOverloadedOperator = 0x0004,
209 Nested = 0x0008,
210 ContainsNestedClass = 0x0010,
211 HasOverloadedAssignmentOperator = 0x0020,
212 HasConversionOperator = 0x0040,
213 ForwardReference = 0x0080,
214 Scoped = 0x0100,
215 HasUniqueName = 0x0200,
216 Sealed = 0x0400,
217 Intrinsic = 0x2000
218 };
219 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ClassOptions)
220
221 enum class FrameProcedureOptions : uint32_t {
222 None = 0x00000000,
223 HasAlloca = 0x00000001,
224 HasSetJmp = 0x00000002,
225 HasLongJmp = 0x00000004,
226 HasInlineAssembly = 0x00000008,
227 HasExceptionHandling = 0x00000010,
228 MarkedInline = 0x00000020,
229 HasStructuredExceptionHandling = 0x00000040,
230 Naked = 0x00000080,
231 SecurityChecks = 0x00000100,
232 AsynchronousExceptionHandling = 0x00000200,
233 NoStackOrderingForSecurityChecks = 0x00000400,
234 Inlined = 0x00000800,
235 StrictSecurityChecks = 0x00001000,
236 SafeBuffers = 0x00002000,
237 EncodedLocalBasePointerMask = 0x0000C000,
238 EncodedParamBasePointerMask = 0x00030000,
239 ProfileGuidedOptimization = 0x00040000,
240 ValidProfileCounts = 0x00080000,
241 OptimizedForSpeed = 0x00100000,
242 GuardCfg = 0x00200000,
243 GuardCfw = 0x00400000
244 };
245 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(FrameProcedureOptions)
246
247 enum class FunctionOptions : uint8_t {
248 None = 0x00,
249 CxxReturnUdt = 0x01,
250 Constructor = 0x02,
251 ConstructorWithVirtualBases = 0x04
252 };
253 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(FunctionOptions)
254
255 enum class HfaKind : uint8_t {
256 None = 0x00,
257 Float = 0x01,
258 Double = 0x02,
259 Other = 0x03
260 };
261
262 /// Source-level access specifier. (CV_access_e)
263 enum class MemberAccess : uint8_t {
264 None = 0,
265 Private = 1,
266 Protected = 2,
267 Public = 3
268 };
269
270 /// Part of member attribute flags. (CV_methodprop_e)
271 enum class MethodKind : uint8_t {
272 Vanilla = 0x00,
273 Virtual = 0x01,
274 Static = 0x02,
275 Friend = 0x03,
276 IntroducingVirtual = 0x04,
277 PureVirtual = 0x05,
278 PureIntroducingVirtual = 0x06
279 };
280
281 /// Equivalent to CV_fldattr_t bitfield.
282 enum class MethodOptions : uint16_t {
283 None = 0x0000,
284 AccessMask = 0x0003,
285 MethodKindMask = 0x001c,
286 Pseudo = 0x0020,
287 NoInherit = 0x0040,
288 NoConstruct = 0x0080,
289 CompilerGenerated = 0x0100,
290 Sealed = 0x0200
291 };
292 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(MethodOptions)
293
294 /// Equivalent to CV_LABEL_TYPE_e.
295 enum class LabelType : uint16_t {
296 Near = 0x0,
297 Far = 0x4,
298 };
299
300 /// Equivalent to CV_modifier_t.
301 /// TODO: Add flag for _Atomic modifier
302 enum class ModifierOptions : uint16_t {
303 None = 0x0000,
304 Const = 0x0001,
305 Volatile = 0x0002,
306 Unaligned = 0x0004
307 };
308 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ModifierOptions)
309
310 // If the subsection kind has this bit set, then the linker should ignore it.
311 enum : uint32_t { SubsectionIgnoreFlag = 0x80000000 };
312
313 enum class DebugSubsectionKind : uint32_t {
314 None = 0,
315 Symbols = 0xf1,
316 Lines = 0xf2,
317 StringTable = 0xf3,
318 FileChecksums = 0xf4,
319 FrameData = 0xf5,
320 InlineeLines = 0xf6,
321 CrossScopeImports = 0xf7,
322 CrossScopeExports = 0xf8,
323
324 // These appear to relate to .Net assembly info.
325 ILLines = 0xf9,
326 FuncMDTokenMap = 0xfa,
327 TypeMDTokenMap = 0xfb,
328 MergedAssemblyInput = 0xfc,
329
330 CoffSymbolRVA = 0xfd,
331 };
332
333 /// Equivalent to CV_ptrtype_e.
334 enum class PointerKind : uint8_t {
335 Near16 = 0x00, // 16 bit pointer
336 Far16 = 0x01, // 16:16 far pointer
337 Huge16 = 0x02, // 16:16 huge pointer
338 BasedOnSegment = 0x03, // based on segment
339 BasedOnValue = 0x04, // based on value of base
340 BasedOnSegmentValue = 0x05, // based on segment value of base
341 BasedOnAddress = 0x06, // based on address of base
342 BasedOnSegmentAddress = 0x07, // based on segment address of base
343 BasedOnType = 0x08, // based on type
344 BasedOnSelf = 0x09, // based on self
345 Near32 = 0x0a, // 32 bit pointer
346 Far32 = 0x0b, // 16:32 pointer
347 Near64 = 0x0c // 64 bit pointer
348 };
349
350 /// Equivalent to CV_ptrmode_e.
351 enum class PointerMode : uint8_t {
352 Pointer = 0x00, // "normal" pointer
353 LValueReference = 0x01, // "old" reference
354 PointerToDataMember = 0x02, // pointer to data member
355 PointerToMemberFunction = 0x03, // pointer to member function
356 RValueReference = 0x04 // r-value reference
357 };
358
359 /// Equivalent to misc lfPointerAttr bitfields.
360 enum class PointerOptions : uint32_t {
361 None = 0x00000000,
362 Flat32 = 0x00000100,
363 Volatile = 0x00000200,
364 Const = 0x00000400,
365 Unaligned = 0x00000800,
366 Restrict = 0x00001000,
367 WinRTSmartPointer = 0x00080000,
368 LValueRefThisPointer = 0x00100000,
369 RValueRefThisPointer = 0x00200000
370 };
371 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(PointerOptions)
372
373 /// Equivalent to CV_pmtype_e.
374 enum class PointerToMemberRepresentation : uint16_t {
375 Unknown = 0x00, // not specified (pre VC8)
376 SingleInheritanceData = 0x01, // member data, single inheritance
377 MultipleInheritanceData = 0x02, // member data, multiple inheritance
378 VirtualInheritanceData = 0x03, // member data, virtual inheritance
379 GeneralData = 0x04, // member data, most general
380 SingleInheritanceFunction = 0x05, // member function, single inheritance
381 MultipleInheritanceFunction = 0x06, // member function, multiple inheritance
382 VirtualInheritanceFunction = 0x07, // member function, virtual inheritance
383 GeneralFunction = 0x08 // member function, most general
384 };
385
386 enum class VFTableSlotKind : uint8_t {
387 Near16 = 0x00,
388 Far16 = 0x01,
389 This = 0x02,
390 Outer = 0x03,
391 Meta = 0x04,
392 Near = 0x05,
393 Far = 0x06
394 };
395
396 enum class WindowsRTClassKind : uint8_t {
397 None = 0x00,
398 RefClass = 0x01,
399 ValueClass = 0x02,
400 Interface = 0x03
401 };
402
403 /// Corresponds to CV_LVARFLAGS bitfield.
404 enum class LocalSymFlags : uint16_t {
405 None = 0,
406 IsParameter = 1 << 0,
407 IsAddressTaken = 1 << 1,
408 IsCompilerGenerated = 1 << 2,
409 IsAggregate = 1 << 3,
410 IsAggregated = 1 << 4,
411 IsAliased = 1 << 5,
412 IsAlias = 1 << 6,
413 IsReturnValue = 1 << 7,
414 IsOptimizedOut = 1 << 8,
415 IsEnregisteredGlobal = 1 << 9,
416 IsEnregisteredStatic = 1 << 10,
417 };
418 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(LocalSymFlags)
419
420 /// Corresponds to the CV_PUBSYMFLAGS bitfield.
421 enum class PublicSymFlags : uint32_t {
422 None = 0,
423 Code = 1 << 0,
424 Function = 1 << 1,
425 Managed = 1 << 2,
426 MSIL = 1 << 3,
427 };
428 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(PublicSymFlags)
429
430 /// Corresponds to the CV_PROCFLAGS bitfield.
431 enum class ProcSymFlags : uint8_t {
432 None = 0,
433 HasFP = 1 << 0,
434 HasIRET = 1 << 1,
435 HasFRET = 1 << 2,
436 IsNoReturn = 1 << 3,
437 IsUnreachable = 1 << 4,
438 HasCustomCallingConv = 1 << 5,
439 IsNoInline = 1 << 6,
440 HasOptimizedDebugInfo = 1 << 7,
441 };
442 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ProcSymFlags)
443
444 /// Corresponds to COMPILESYM2::Flags bitfield.
445 enum class CompileSym2Flags : uint32_t {
446 None = 0,
447 SourceLanguageMask = 0xFF,
448 EC = 1 << 8,
449 NoDbgInfo = 1 << 9,
450 LTCG = 1 << 10,
451 NoDataAlign = 1 << 11,
452 ManagedPresent = 1 << 12,
453 SecurityChecks = 1 << 13,
454 HotPatch = 1 << 14,
455 CVTCIL = 1 << 15,
456 MSILModule = 1 << 16,
457 };
458 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(CompileSym2Flags)
459
460 /// Corresponds to COMPILESYM3::Flags bitfield.
461 enum class CompileSym3Flags : uint32_t {
462 None = 0,
463 SourceLanguageMask = 0xFF,
464 EC = 1 << 8,
465 NoDbgInfo = 1 << 9,
466 LTCG = 1 << 10,
467 NoDataAlign = 1 << 11,
468 ManagedPresent = 1 << 12,
469 SecurityChecks = 1 << 13,
470 HotPatch = 1 << 14,
471 CVTCIL = 1 << 15,
472 MSILModule = 1 << 16,
473 Sdl = 1 << 17,
474 PGO = 1 << 18,
475 Exp = 1 << 19,
476 };
477 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(CompileSym3Flags)
478
479 enum class ExportFlags : uint16_t {
480 None = 0,
481 IsConstant = 1 << 0,
482 IsData = 1 << 1,
483 IsPrivate = 1 << 2,
484 HasNoName = 1 << 3,
485 HasExplicitOrdinal = 1 << 4,
486 IsForwarder = 1 << 5
487 };
488 CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ExportFlags)
489
490 // Corresponds to BinaryAnnotationOpcode enum.
491 enum class BinaryAnnotationsOpCode : uint32_t {
492 Invalid,
493 CodeOffset,
494 ChangeCodeOffsetBase,
495 ChangeCodeOffset,
496 ChangeCodeLength,
497 ChangeFile,
498 ChangeLineOffset,
499 ChangeLineEndDelta,
500 ChangeRangeKind,
501 ChangeColumnStart,
502 ChangeColumnEndDelta,
503 ChangeCodeOffsetAndLineOffset,
504 ChangeCodeLengthAndCodeOffset,
505 ChangeColumnEnd,
506 };
507
508 // Corresponds to CV_cookietype_e enum.
509 enum class FrameCookieKind : uint8_t {
510 Copy,
511 XorStackPointer,
512 XorFramePointer,
513 XorR13,
514 };
515
516 // Corresponds to CV_HREG_e enum.
517 enum class RegisterId : uint16_t {
518 #define CV_REGISTERS_ALL
519 #define CV_REGISTER(name, value) name = value,
520 #include "CodeViewRegisters.def"
521 #undef CV_REGISTER
522 #undef CV_REGISTERS_ALL
523 };
524
525 // Register Ids are shared between architectures in CodeView. CPUType is needed
526 // to map register Id to name.
527 struct CPURegister {
528 CPURegister() = delete;
CPURegisterCPURegister529 CPURegister(CPUType Cpu, codeview::RegisterId Reg) {
530 this->Cpu = Cpu;
531 this->Reg = Reg;
532 }
533 CPUType Cpu;
534 RegisterId Reg;
535 };
536
537 /// Two-bit value indicating which register is the designated frame pointer
538 /// register. Appears in the S_FRAMEPROC record flags.
539 enum class EncodedFramePtrReg : uint8_t {
540 None = 0,
541 StackPtr = 1,
542 FramePtr = 2,
543 BasePtr = 3,
544 };
545
546 RegisterId decodeFramePtrReg(EncodedFramePtrReg EncodedReg, CPUType CPU);
547
548 EncodedFramePtrReg encodeFramePtrReg(RegisterId Reg, CPUType CPU);
549
550 /// These values correspond to the THUNK_ORDINAL enumeration.
551 enum class ThunkOrdinal : uint8_t {
552 Standard,
553 ThisAdjustor,
554 Vcall,
555 Pcode,
556 UnknownLoad,
557 TrampIncremental,
558 BranchIsland
559 };
560
561 enum class TrampolineType : uint16_t { TrampIncremental, BranchIsland };
562
563 // These values correspond to the CV_SourceChksum_t enumeration.
564 enum class FileChecksumKind : uint8_t { None, MD5, SHA1, SHA256 };
565
566 enum LineFlags : uint16_t {
567 LF_None = 0,
568 LF_HaveColumns = 1, // CV_LINES_HAVE_COLUMNS
569 };
570
571 /// Data in the SUBSEC_FRAMEDATA subection.
572 struct FrameData {
573 support::ulittle32_t RvaStart;
574 support::ulittle32_t CodeSize;
575 support::ulittle32_t LocalSize;
576 support::ulittle32_t ParamsSize;
577 support::ulittle32_t MaxStackSize;
578 support::ulittle32_t FrameFunc;
579 support::ulittle16_t PrologSize;
580 support::ulittle16_t SavedRegsSize;
581 support::ulittle32_t Flags;
582 enum : uint32_t {
583 HasSEH = 1 << 0,
584 HasEH = 1 << 1,
585 IsFunctionStart = 1 << 2,
586 };
587 };
588
589 // Corresponds to LocalIdAndGlobalIdPair structure.
590 // This structure information allows cross-referencing between PDBs. For
591 // example, when a PDB is being built during compilation it is not yet known
592 // what other modules may end up in the PDB at link time. So certain types of
593 // IDs may clash between the various compile time PDBs. For each affected
594 // module, a subsection would be put into the PDB containing a mapping from its
595 // local IDs to a single ID namespace for all items in the PDB file.
596 struct CrossModuleExport {
597 support::ulittle32_t Local;
598 support::ulittle32_t Global;
599 };
600
601 struct CrossModuleImport {
602 support::ulittle32_t ModuleNameOffset;
603 support::ulittle32_t Count; // Number of elements
604 // support::ulittle32_t ids[Count]; // id from referenced module
605 };
606
607 enum class CodeViewContainer { ObjectFile, Pdb };
608
alignOf(CodeViewContainer Container)609 inline uint32_t alignOf(CodeViewContainer Container) {
610 if (Container == CodeViewContainer::ObjectFile)
611 return 1;
612 return 4;
613 }
614 }
615 }
616
617 #endif
618