blob: 4fbf507a6b7ddcba9672d315b109767dd43c258b [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- CodeView.h -----------------------------------------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
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
21namespace llvm {
22namespace codeview {
23
Andrew Scullcdfcccc2018-10-05 20:58:37 +010024/// 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.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010026enum 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.
33enum 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.
40enum 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.
47enum 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
78enum 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 ARM64 = 0x69,
127 Omni = 0x70,
128 Ia64 = 0x80,
129 Ia64_2 = 0x81,
130 CEE = 0x90,
131 AM33 = 0xa0,
132 M32R = 0xb0,
133 TriCore = 0xc0,
134 X64 = 0xd0,
135 EBC = 0xe0,
136 Thumb = 0xf0,
137 ARMNT = 0xf4,
138 D3D11_Shader = 0x100,
139};
140
141/// These values correspond to the CV_CFL_LANG enumeration, and are documented
142/// here: https://msdn.microsoft.com/en-us/library/bw3aekw6.aspx
143enum SourceLanguage : uint8_t {
144 C = 0x00,
145 Cpp = 0x01,
146 Fortran = 0x02,
147 Masm = 0x03,
148 Pascal = 0x04,
149 Basic = 0x05,
150 Cobol = 0x06,
151 Link = 0x07,
152 Cvtres = 0x08,
153 Cvtpgd = 0x09,
154 CSharp = 0x0a,
155 VB = 0x0b,
156 ILAsm = 0x0c,
157 Java = 0x0d,
158 JScript = 0x0e,
159 MSIL = 0x0f,
160 HLSL = 0x10,
161
162 /// The DMD compiler emits 'D' for the CV source language. Microsoft doesn't
163 /// have an enumerator for it yet.
164 D = 'D',
165};
166
167/// These values correspond to the CV_call_e enumeration, and are documented
168/// at the following locations:
169/// https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx
170/// https://msdn.microsoft.com/en-us/library/windows/desktop/ms680207(v=vs.85).aspx
171///
172enum class CallingConvention : uint8_t {
173 NearC = 0x00, // near right to left push, caller pops stack
174 FarC = 0x01, // far right to left push, caller pops stack
175 NearPascal = 0x02, // near left to right push, callee pops stack
176 FarPascal = 0x03, // far left to right push, callee pops stack
177 NearFast = 0x04, // near left to right push with regs, callee pops stack
178 FarFast = 0x05, // far left to right push with regs, callee pops stack
179 NearStdCall = 0x07, // near standard call
180 FarStdCall = 0x08, // far standard call
181 NearSysCall = 0x09, // near sys call
182 FarSysCall = 0x0a, // far sys call
183 ThisCall = 0x0b, // this call (this passed in register)
184 MipsCall = 0x0c, // Mips call
185 Generic = 0x0d, // Generic call sequence
186 AlphaCall = 0x0e, // Alpha call
187 PpcCall = 0x0f, // PPC call
188 SHCall = 0x10, // Hitachi SuperH call
189 ArmCall = 0x11, // ARM call
190 AM33Call = 0x12, // AM33 call
191 TriCall = 0x13, // TriCore Call
192 SH5Call = 0x14, // Hitachi SuperH-5 call
193 M32RCall = 0x15, // M32R Call
194 ClrCall = 0x16, // clr call
195 Inline =
196 0x17, // Marker for routines always inlined and thus lacking a convention
197 NearVector = 0x18 // near left to right push with regs, callee pops stack
198};
199
200enum class ClassOptions : uint16_t {
201 None = 0x0000,
202 Packed = 0x0001,
203 HasConstructorOrDestructor = 0x0002,
204 HasOverloadedOperator = 0x0004,
205 Nested = 0x0008,
206 ContainsNestedClass = 0x0010,
207 HasOverloadedAssignmentOperator = 0x0020,
208 HasConversionOperator = 0x0040,
209 ForwardReference = 0x0080,
210 Scoped = 0x0100,
211 HasUniqueName = 0x0200,
212 Sealed = 0x0400,
213 Intrinsic = 0x2000
214};
215CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ClassOptions)
216
217enum class FrameProcedureOptions : uint32_t {
218 None = 0x00000000,
219 HasAlloca = 0x00000001,
220 HasSetJmp = 0x00000002,
221 HasLongJmp = 0x00000004,
222 HasInlineAssembly = 0x00000008,
223 HasExceptionHandling = 0x00000010,
224 MarkedInline = 0x00000020,
225 HasStructuredExceptionHandling = 0x00000040,
226 Naked = 0x00000080,
227 SecurityChecks = 0x00000100,
228 AsynchronousExceptionHandling = 0x00000200,
229 NoStackOrderingForSecurityChecks = 0x00000400,
230 Inlined = 0x00000800,
231 StrictSecurityChecks = 0x00001000,
232 SafeBuffers = 0x00002000,
Andrew Scull0372a572018-11-16 15:47:06 +0000233 EncodedLocalBasePointerMask = 0x0000C000,
234 EncodedParamBasePointerMask = 0x00030000,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100235 ProfileGuidedOptimization = 0x00040000,
236 ValidProfileCounts = 0x00080000,
237 OptimizedForSpeed = 0x00100000,
238 GuardCfg = 0x00200000,
239 GuardCfw = 0x00400000
240};
241CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(FrameProcedureOptions)
242
243enum class FunctionOptions : uint8_t {
244 None = 0x00,
245 CxxReturnUdt = 0x01,
246 Constructor = 0x02,
247 ConstructorWithVirtualBases = 0x04
248};
249CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(FunctionOptions)
250
251enum class HfaKind : uint8_t {
252 None = 0x00,
253 Float = 0x01,
254 Double = 0x02,
255 Other = 0x03
256};
257
258/// Source-level access specifier. (CV_access_e)
259enum class MemberAccess : uint8_t {
260 None = 0,
261 Private = 1,
262 Protected = 2,
263 Public = 3
264};
265
266/// Part of member attribute flags. (CV_methodprop_e)
267enum class MethodKind : uint8_t {
268 Vanilla = 0x00,
269 Virtual = 0x01,
270 Static = 0x02,
271 Friend = 0x03,
272 IntroducingVirtual = 0x04,
273 PureVirtual = 0x05,
274 PureIntroducingVirtual = 0x06
275};
276
277/// Equivalent to CV_fldattr_t bitfield.
278enum class MethodOptions : uint16_t {
279 None = 0x0000,
280 AccessMask = 0x0003,
281 MethodKindMask = 0x001c,
282 Pseudo = 0x0020,
283 NoInherit = 0x0040,
284 NoConstruct = 0x0080,
285 CompilerGenerated = 0x0100,
286 Sealed = 0x0200
287};
288CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(MethodOptions)
289
290/// Equivalent to CV_LABEL_TYPE_e.
291enum class LabelType : uint16_t {
292 Near = 0x0,
293 Far = 0x4,
294};
295
296/// Equivalent to CV_modifier_t.
297/// TODO: Add flag for _Atomic modifier
298enum class ModifierOptions : uint16_t {
299 None = 0x0000,
300 Const = 0x0001,
301 Volatile = 0x0002,
302 Unaligned = 0x0004
303};
304CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ModifierOptions)
305
306enum class DebugSubsectionKind : uint32_t {
307 None = 0,
308 Symbols = 0xf1,
309 Lines = 0xf2,
310 StringTable = 0xf3,
311 FileChecksums = 0xf4,
312 FrameData = 0xf5,
313 InlineeLines = 0xf6,
314 CrossScopeImports = 0xf7,
315 CrossScopeExports = 0xf8,
316
317 // These appear to relate to .Net assembly info.
318 ILLines = 0xf9,
319 FuncMDTokenMap = 0xfa,
320 TypeMDTokenMap = 0xfb,
321 MergedAssemblyInput = 0xfc,
322
323 CoffSymbolRVA = 0xfd,
324};
325
326/// Equivalent to CV_ptrtype_e.
327enum class PointerKind : uint8_t {
328 Near16 = 0x00, // 16 bit pointer
329 Far16 = 0x01, // 16:16 far pointer
330 Huge16 = 0x02, // 16:16 huge pointer
331 BasedOnSegment = 0x03, // based on segment
332 BasedOnValue = 0x04, // based on value of base
333 BasedOnSegmentValue = 0x05, // based on segment value of base
334 BasedOnAddress = 0x06, // based on address of base
335 BasedOnSegmentAddress = 0x07, // based on segment address of base
336 BasedOnType = 0x08, // based on type
337 BasedOnSelf = 0x09, // based on self
338 Near32 = 0x0a, // 32 bit pointer
339 Far32 = 0x0b, // 16:32 pointer
340 Near64 = 0x0c // 64 bit pointer
341};
342
343/// Equivalent to CV_ptrmode_e.
344enum class PointerMode : uint8_t {
345 Pointer = 0x00, // "normal" pointer
346 LValueReference = 0x01, // "old" reference
347 PointerToDataMember = 0x02, // pointer to data member
348 PointerToMemberFunction = 0x03, // pointer to member function
349 RValueReference = 0x04 // r-value reference
350};
351
352/// Equivalent to misc lfPointerAttr bitfields.
353enum class PointerOptions : uint32_t {
354 None = 0x00000000,
355 Flat32 = 0x00000100,
356 Volatile = 0x00000200,
357 Const = 0x00000400,
358 Unaligned = 0x00000800,
359 Restrict = 0x00001000,
Andrew Walbran16937d02019-10-22 13:54:20 +0100360 WinRTSmartPointer = 0x00080000,
361 LValueRefThisPointer = 0x00100000,
362 RValueRefThisPointer = 0x00200000
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100363};
364CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(PointerOptions)
365
366/// Equivalent to CV_pmtype_e.
367enum class PointerToMemberRepresentation : uint16_t {
368 Unknown = 0x00, // not specified (pre VC8)
369 SingleInheritanceData = 0x01, // member data, single inheritance
370 MultipleInheritanceData = 0x02, // member data, multiple inheritance
371 VirtualInheritanceData = 0x03, // member data, virtual inheritance
372 GeneralData = 0x04, // member data, most general
373 SingleInheritanceFunction = 0x05, // member function, single inheritance
374 MultipleInheritanceFunction = 0x06, // member function, multiple inheritance
375 VirtualInheritanceFunction = 0x07, // member function, virtual inheritance
376 GeneralFunction = 0x08 // member function, most general
377};
378
379enum class VFTableSlotKind : uint8_t {
380 Near16 = 0x00,
381 Far16 = 0x01,
382 This = 0x02,
383 Outer = 0x03,
384 Meta = 0x04,
385 Near = 0x05,
386 Far = 0x06
387};
388
389enum class WindowsRTClassKind : uint8_t {
390 None = 0x00,
391 RefClass = 0x01,
392 ValueClass = 0x02,
393 Interface = 0x03
394};
395
396/// Corresponds to CV_LVARFLAGS bitfield.
397enum class LocalSymFlags : uint16_t {
398 None = 0,
399 IsParameter = 1 << 0,
400 IsAddressTaken = 1 << 1,
401 IsCompilerGenerated = 1 << 2,
402 IsAggregate = 1 << 3,
403 IsAggregated = 1 << 4,
404 IsAliased = 1 << 5,
405 IsAlias = 1 << 6,
406 IsReturnValue = 1 << 7,
407 IsOptimizedOut = 1 << 8,
408 IsEnregisteredGlobal = 1 << 9,
409 IsEnregisteredStatic = 1 << 10,
410};
411CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(LocalSymFlags)
412
413/// Corresponds to the CV_PUBSYMFLAGS bitfield.
414enum class PublicSymFlags : uint32_t {
415 None = 0,
416 Code = 1 << 0,
417 Function = 1 << 1,
418 Managed = 1 << 2,
419 MSIL = 1 << 3,
420};
421CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(PublicSymFlags)
422
423/// Corresponds to the CV_PROCFLAGS bitfield.
424enum class ProcSymFlags : uint8_t {
425 None = 0,
426 HasFP = 1 << 0,
427 HasIRET = 1 << 1,
428 HasFRET = 1 << 2,
429 IsNoReturn = 1 << 3,
430 IsUnreachable = 1 << 4,
431 HasCustomCallingConv = 1 << 5,
432 IsNoInline = 1 << 6,
433 HasOptimizedDebugInfo = 1 << 7,
434};
435CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ProcSymFlags)
436
437/// Corresponds to COMPILESYM2::Flags bitfield.
438enum class CompileSym2Flags : uint32_t {
439 None = 0,
440 SourceLanguageMask = 0xFF,
441 EC = 1 << 8,
442 NoDbgInfo = 1 << 9,
443 LTCG = 1 << 10,
444 NoDataAlign = 1 << 11,
445 ManagedPresent = 1 << 12,
446 SecurityChecks = 1 << 13,
447 HotPatch = 1 << 14,
448 CVTCIL = 1 << 15,
449 MSILModule = 1 << 16,
450};
451CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(CompileSym2Flags)
452
453/// Corresponds to COMPILESYM3::Flags bitfield.
454enum class CompileSym3Flags : uint32_t {
455 None = 0,
456 SourceLanguageMask = 0xFF,
457 EC = 1 << 8,
458 NoDbgInfo = 1 << 9,
459 LTCG = 1 << 10,
460 NoDataAlign = 1 << 11,
461 ManagedPresent = 1 << 12,
462 SecurityChecks = 1 << 13,
463 HotPatch = 1 << 14,
464 CVTCIL = 1 << 15,
465 MSILModule = 1 << 16,
466 Sdl = 1 << 17,
467 PGO = 1 << 18,
468 Exp = 1 << 19,
469};
470CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(CompileSym3Flags)
471
472enum class ExportFlags : uint16_t {
473 None = 0,
474 IsConstant = 1 << 0,
475 IsData = 1 << 1,
476 IsPrivate = 1 << 2,
477 HasNoName = 1 << 3,
478 HasExplicitOrdinal = 1 << 4,
479 IsForwarder = 1 << 5
480};
481CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ExportFlags)
482
483// Corresponds to BinaryAnnotationOpcode enum.
484enum class BinaryAnnotationsOpCode : uint32_t {
485 Invalid,
486 CodeOffset,
487 ChangeCodeOffsetBase,
488 ChangeCodeOffset,
489 ChangeCodeLength,
490 ChangeFile,
491 ChangeLineOffset,
492 ChangeLineEndDelta,
493 ChangeRangeKind,
494 ChangeColumnStart,
495 ChangeColumnEndDelta,
496 ChangeCodeOffsetAndLineOffset,
497 ChangeCodeLengthAndCodeOffset,
498 ChangeColumnEnd,
499};
500
501// Corresponds to CV_cookietype_e enum.
502enum class FrameCookieKind : uint8_t {
503 Copy,
504 XorStackPointer,
505 XorFramePointer,
506 XorR13,
507};
508
509// Corresponds to CV_HREG_e enum.
510enum class RegisterId : uint16_t {
511#define CV_REGISTER(name, value) name = value,
512#include "CodeViewRegisters.def"
513#undef CV_REGISTER
514};
515
Andrew Scull0372a572018-11-16 15:47:06 +0000516/// Two-bit value indicating which register is the designated frame pointer
517/// register. Appears in the S_FRAMEPROC record flags.
518enum class EncodedFramePtrReg : uint8_t {
519 None = 0,
520 StackPtr = 1,
521 FramePtr = 2,
522 BasePtr = 3,
523};
524
525RegisterId decodeFramePtrReg(EncodedFramePtrReg EncodedReg, CPUType CPU);
526
527EncodedFramePtrReg encodeFramePtrReg(RegisterId Reg, CPUType CPU);
528
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100529/// These values correspond to the THUNK_ORDINAL enumeration.
530enum class ThunkOrdinal : uint8_t {
531 Standard,
532 ThisAdjustor,
533 Vcall,
534 Pcode,
535 UnknownLoad,
536 TrampIncremental,
537 BranchIsland
538};
539
540enum class TrampolineType : uint16_t { TrampIncremental, BranchIsland };
541
542// These values correspond to the CV_SourceChksum_t enumeration.
543enum class FileChecksumKind : uint8_t { None, MD5, SHA1, SHA256 };
544
545enum LineFlags : uint16_t {
546 LF_None = 0,
547 LF_HaveColumns = 1, // CV_LINES_HAVE_COLUMNS
548};
549
550/// Data in the SUBSEC_FRAMEDATA subection.
551struct FrameData {
552 support::ulittle32_t RvaStart;
553 support::ulittle32_t CodeSize;
554 support::ulittle32_t LocalSize;
555 support::ulittle32_t ParamsSize;
556 support::ulittle32_t MaxStackSize;
557 support::ulittle32_t FrameFunc;
558 support::ulittle16_t PrologSize;
559 support::ulittle16_t SavedRegsSize;
560 support::ulittle32_t Flags;
561 enum : uint32_t {
562 HasSEH = 1 << 0,
563 HasEH = 1 << 1,
564 IsFunctionStart = 1 << 2,
565 };
566};
567
568// Corresponds to LocalIdAndGlobalIdPair structure.
569// This structure information allows cross-referencing between PDBs. For
570// example, when a PDB is being built during compilation it is not yet known
571// what other modules may end up in the PDB at link time. So certain types of
572// IDs may clash between the various compile time PDBs. For each affected
573// module, a subsection would be put into the PDB containing a mapping from its
574// local IDs to a single ID namespace for all items in the PDB file.
575struct CrossModuleExport {
576 support::ulittle32_t Local;
577 support::ulittle32_t Global;
578};
579
580struct CrossModuleImport {
581 support::ulittle32_t ModuleNameOffset;
582 support::ulittle32_t Count; // Number of elements
583 // support::ulittle32_t ids[Count]; // id from referenced module
584};
585
586enum class CodeViewContainer { ObjectFile, Pdb };
587
588inline uint32_t alignOf(CodeViewContainer Container) {
589 if (Container == CodeViewContainer::ObjectFile)
590 return 1;
591 return 4;
592}
593}
594}
595
596#endif