1 //===- Minidump.h - Minidump constants and structures -----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This header constants and data structures pertaining to the Windows Minidump
13 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms679293(v=vs.85).aspx
14 // https://chromium.googlesource.com/breakpad/breakpad/
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_BINARYFORMAT_MINIDUMP_H
19 #define LLVM_BINARYFORMAT_MINIDUMP_H
21 #include "llvm/ADT/DenseMapInfo.h"
22 #include "llvm/Support/Endian.h"
27 /// The minidump header is the first part of a minidump file. It identifies the
28 /// file as a minidump file, and gives the location of the stream directory.
30 static constexpr uint32_t MagicSignature
= 0x504d444d; // PMDM
31 static constexpr uint16_t MagicVersion
= 0xa793;
33 support::ulittle32_t Signature
;
34 // The high 16 bits of version field are implementation specific. The low 16
35 // bits should be MagicVersion.
36 support::ulittle32_t Version
;
37 support::ulittle32_t NumberOfStreams
;
38 support::ulittle32_t StreamDirectoryRVA
;
39 support::ulittle32_t Checksum
;
40 support::ulittle32_t TimeDateStamp
;
41 support::ulittle64_t Flags
;
43 static_assert(sizeof(Header
) == 32, "");
45 /// The type of a minidump stream identifies its contents. Streams numbers after
46 /// LastReserved are for application-defined data streams.
47 enum class StreamType
: uint32_t {
48 #define HANDLE_MDMP_STREAM_TYPE(CODE, NAME) NAME = CODE,
49 #include "llvm/BinaryFormat/MinidumpConstants.def"
51 LastReserved
= 0x0000ffff,
54 /// Specifies the location (and size) of various objects in the minidump file.
55 /// The location is relative to the start of the file.
56 struct LocationDescriptor
{
57 support::ulittle32_t DataSize
;
58 support::ulittle32_t RVA
;
60 static_assert(sizeof(LocationDescriptor
) == 8, "");
62 /// Describes a single memory range (both its VM address and where to find it in
63 /// the file) of the process from which this minidump file was generated.
64 struct MemoryDescriptor
{
65 support::ulittle64_t StartOfMemoryRange
;
66 LocationDescriptor Memory
;
68 static_assert(sizeof(MemoryDescriptor
) == 16, "");
70 /// Specifies the location and type of a single stream in the minidump file. The
71 /// minidump stream directory is an array of entries of this type, with its size
72 /// given by Header.NumberOfStreams.
74 support::little_t
<StreamType
> Type
;
75 LocationDescriptor Location
;
77 static_assert(sizeof(Directory
) == 12, "");
79 /// The processor architecture of the system that generated this minidump. Used
80 /// in the ProcessorArch field of the SystemInfo stream.
81 enum class ProcessorArchitecture
: uint16_t {
82 #define HANDLE_MDMP_ARCH(CODE, NAME) NAME = CODE,
83 #include "llvm/BinaryFormat/MinidumpConstants.def"
86 /// The OS Platform of the system that generated this minidump. Used in the
87 /// PlatformId field of the SystemInfo stream.
88 enum class OSPlatform
: uint32_t {
89 #define HANDLE_MDMP_PLATFORM(CODE, NAME) NAME = CODE,
90 #include "llvm/BinaryFormat/MinidumpConstants.def"
93 /// Detailed information about the processor of the system that generated this
94 /// minidump. Its interpretation depends on the ProcessorArchitecture enum.
97 char VendorID
[12]; // cpuid 0: ebx, edx, ecx
98 support::ulittle32_t VersionInfo
; // cpuid 1: eax
99 support::ulittle32_t FeatureInfo
; // cpuid 1: edx
100 support::ulittle32_t AMDExtendedFeatures
; // cpuid 0x80000001, ebx
103 support::ulittle32_t CPUID
;
104 support::ulittle32_t ElfHWCaps
; // linux specific, 0 otherwise
107 uint8_t ProcessorFeatures
[16];
110 static_assert(sizeof(CPUInfo
) == 24, "");
112 /// The SystemInfo stream, containing various information about the system where
113 /// this minidump was generated.
115 support::little_t
<ProcessorArchitecture
> ProcessorArch
;
116 support::ulittle16_t ProcessorLevel
;
117 support::ulittle16_t ProcessorRevision
;
119 uint8_t NumberOfProcessors
;
122 support::ulittle32_t MajorVersion
;
123 support::ulittle32_t MinorVersion
;
124 support::ulittle32_t BuildNumber
;
125 support::little_t
<OSPlatform
> PlatformId
;
126 support::ulittle32_t CSDVersionRVA
;
128 support::ulittle16_t SuiteMask
;
129 support::ulittle16_t Reserved
;
133 static_assert(sizeof(SystemInfo
) == 56, "");
135 struct VSFixedFileInfo
{
136 support::ulittle32_t Signature
;
137 support::ulittle32_t StructVersion
;
138 support::ulittle32_t FileVersionHigh
;
139 support::ulittle32_t FileVersionLow
;
140 support::ulittle32_t ProductVersionHigh
;
141 support::ulittle32_t ProductVersionLow
;
142 support::ulittle32_t FileFlagsMask
;
143 support::ulittle32_t FileFlags
;
144 support::ulittle32_t FileOS
;
145 support::ulittle32_t FileType
;
146 support::ulittle32_t FileSubtype
;
147 support::ulittle32_t FileDateHigh
;
148 support::ulittle32_t FileDateLow
;
150 static_assert(sizeof(VSFixedFileInfo
) == 52, "");
152 inline bool operator==(const VSFixedFileInfo
&LHS
, const VSFixedFileInfo
&RHS
) {
153 return memcmp(&LHS
, &RHS
, sizeof(VSFixedFileInfo
)) == 0;
157 support::ulittle64_t BaseOfImage
;
158 support::ulittle32_t SizeOfImage
;
159 support::ulittle32_t Checksum
;
160 support::ulittle32_t TimeDateStamp
;
161 support::ulittle32_t ModuleNameRVA
;
162 VSFixedFileInfo VersionInfo
;
163 LocationDescriptor CvRecord
;
164 LocationDescriptor MiscRecord
;
165 support::ulittle64_t Reserved0
;
166 support::ulittle64_t Reserved1
;
168 static_assert(sizeof(Module
) == 108, "");
170 /// Describes a single thread in the minidump file. Part of the ThreadList
173 support::ulittle32_t ThreadId
;
174 support::ulittle32_t SuspendCount
;
175 support::ulittle32_t PriorityClass
;
176 support::ulittle32_t Priority
;
177 support::ulittle64_t EnvironmentBlock
;
178 MemoryDescriptor Stack
;
179 LocationDescriptor Context
;
181 static_assert(sizeof(Thread
) == 48, "");
183 } // namespace minidump
185 template <> struct DenseMapInfo
<minidump::StreamType
> {
186 static minidump::StreamType
getEmptyKey() { return minidump::StreamType(-1); }
188 static minidump::StreamType
getTombstoneKey() {
189 return minidump::StreamType(-2);
192 static unsigned getHashValue(minidump::StreamType Val
) {
193 return DenseMapInfo
<uint32_t>::getHashValue(static_cast<uint32_t>(Val
));
196 static bool isEqual(minidump::StreamType LHS
, minidump::StreamType RHS
) {
203 #endif // LLVM_BINARYFORMAT_MINIDUMP_H