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

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of llvm/include/llvm/DebugInfo/CodeView/CodeView.h