LLVM 20.0.0git
MinidumpYAML.h
Go to the documentation of this file.
1//===- MinidumpYAML.h - Minidump YAMLIO implementation ----------*- 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#ifndef LLVM_OBJECTYAML_MINIDUMPYAML_H
10#define LLVM_OBJECTYAML_MINIDUMPYAML_H
11
16
17namespace llvm {
18namespace MinidumpYAML {
19
20/// The base class for all minidump streams. The "Type" of the stream
21/// corresponds to the Stream Type field in the minidump file. The "Kind" field
22/// specifies how are we going to treat it. For highly specialized streams (e.g.
23/// SystemInfo), there is a 1:1 mapping between Types and Kinds, but in general
24/// one stream Kind can be used to represent multiple stream Types (e.g. any
25/// unrecognised stream Type will be handled via RawContentStream). The mapping
26/// from Types to Kinds is fixed and given by the static getKind function.
27struct Stream {
28 enum class StreamKind {
38 };
39
41 virtual ~Stream(); // anchor
42
45
46 /// Get the stream Kind used for representing streams of a given Type.
48
49 /// Create an empty stream of the given Type.
50 static std::unique_ptr<Stream> create(minidump::StreamType Type);
51
52 /// Create a stream from the given stream directory entry.
54 create(const minidump::Directory &StreamDesc,
55 const object::MinidumpFile &File);
56};
57
58namespace detail {
59/// A stream representing a list of abstract entries in a minidump stream. Its
60/// instantiations can be used to represent the ModuleList stream and other
61/// streams with a similar structure.
62template <typename EntryT> struct ListStream : public Stream {
63 using entry_type = EntryT;
64
65 std::vector<entry_type> Entries;
66
67 explicit ListStream(std::vector<entry_type> Entries = {})
68 : Stream(EntryT::Kind, EntryT::Type), Entries(std::move(Entries)) {}
69
70 static bool classof(const Stream *S) { return S->Kind == EntryT::Kind; }
71};
72
73/// A structure containing all data belonging to a single minidump module.
76 static constexpr minidump::StreamType Type = minidump::StreamType::ModuleList;
77
79 std::string Name;
82};
83
84/// A structure containing all data belonging to a single minidump thread.
87 static constexpr minidump::StreamType Type = minidump::StreamType::ThreadList;
88
92};
93
94/// A structure containing all data describing a single memory region.
97 static constexpr minidump::StreamType Type = minidump::StreamType::MemoryList;
98
101};
102
105 static constexpr minidump::StreamType Type =
106 minidump::StreamType::Memory64List;
107
110};
111} // namespace detail
112
116
118 : public detail::ListStream<detail::ParsedMemory64Descriptor> {
120
122 std::vector<detail::ParsedMemory64Descriptor> Entries = {})
123 : ListStream(Entries) {}
124};
125
126/// ExceptionStream minidump stream.
127struct ExceptionStream : public Stream {
130
132 : Stream(StreamKind::Exception, minidump::StreamType::Exception),
133 MDExceptionStream({}) {}
134
137 : Stream(StreamKind::Exception, minidump::StreamType::Exception),
139
140 static bool classof(const Stream *S) {
141 return S->Kind == StreamKind::Exception;
142 }
143};
144
145/// A structure containing the list of MemoryInfo entries comprising a
146/// MemoryInfoList stream.
148 std::vector<minidump::MemoryInfo> Infos;
149
152 minidump::StreamType::MemoryInfoList) {}
153
157 minidump::StreamType::MemoryInfoList),
158 Infos(Range.begin(), Range.end()) {}
159
160 static bool classof(const Stream *S) {
161 return S->Kind == StreamKind::MemoryInfoList;
162 }
163};
164
165/// A minidump stream represented as a sequence of hex bytes. This is used as a
166/// fallback when no other stream kind is suitable.
167struct RawContentStream : public Stream {
169 yaml::Hex32 Size;
170
173 Size(Content.size()) {}
174
175 static bool classof(const Stream *S) {
176 return S->Kind == StreamKind::RawContent;
177 }
178};
179
180/// SystemInfo minidump stream.
181struct SystemInfoStream : public Stream {
183 std::string CSDVersion;
184
186 : Stream(StreamKind::SystemInfo, minidump::StreamType::SystemInfo) {
187 memset(&Info, 0, sizeof(Info));
188 }
189
191 std::string CSDVersion)
192 : Stream(StreamKind::SystemInfo, minidump::StreamType::SystemInfo),
194
195 static bool classof(const Stream *S) {
196 return S->Kind == StreamKind::SystemInfo;
197 }
198};
199
200/// A StringRef, which is printed using YAML block notation.
201LLVM_YAML_STRONG_TYPEDEF(StringRef, BlockStringRef)
202
203/// A minidump stream containing textual data (typically, the contents of a
204/// /proc/<pid> file on linux).
205struct TextContentStream : public Stream {
206 BlockStringRef Text;
207
209 : Stream(StreamKind::TextContent, Type), Text(Text) {}
210
211 static bool classof(const Stream *S) {
212 return S->Kind == StreamKind::TextContent;
213 }
214};
215
216/// The top level structure representing a minidump object, consisting of a
217/// minidump header, and zero or more streams. To construct an Object from a
218/// minidump file, use the static create function. To serialize to/from yaml,
219/// use the appropriate streaming operator on a yaml stream.
220struct Object {
221 Object() = default;
222 Object(const Object &) = delete;
223 Object &operator=(const Object &) = delete;
224 Object(Object &&) = default;
225 Object &operator=(Object &&) = default;
226
228 std::vector<std::unique_ptr<Stream>> Streams)
230
231 /// The minidump header.
233
234 /// The list of streams in this minidump object.
235 std::vector<std::unique_ptr<Stream>> Streams;
236
237 static Expected<Object> create(const object::MinidumpFile &File);
238};
239
240} // namespace MinidumpYAML
241
242namespace yaml {
243template <> struct BlockScalarTraits<MinidumpYAML::BlockStringRef> {
244 static void output(const MinidumpYAML::BlockStringRef &Text, void *,
245 raw_ostream &OS) {
246 OS << Text;
247 }
248
249 static StringRef input(StringRef Scalar, void *,
250 MinidumpYAML::BlockStringRef &Text) {
251 Text = Scalar;
252 return "";
253 }
254};
255
256template <> struct MappingTraits<std::unique_ptr<MinidumpYAML::Stream>> {
257 static void mapping(IO &IO, std::unique_ptr<MinidumpYAML::Stream> &S);
258 static std::string validate(IO &IO, std::unique_ptr<MinidumpYAML::Stream> &S);
259};
260
261template <> struct MappingContextTraits<minidump::MemoryDescriptor, BinaryRef> {
264};
265
266template <>
267struct MappingContextTraits<minidump::MemoryDescriptor_64, BinaryRef> {
270};
271
272} // namespace yaml
273
274} // namespace llvm
275
279
283
290
299
300LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::MinidumpYAML::Stream>)
306
308
309#endif // LLVM_OBJECTYAML_MINIDUMPYAML_H
T Content
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
raw_pwrite_stream & OS
#define LLVM_YAML_DECLARE_BITSET_TRAITS(Type)
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)
#define LLVM_YAML_DECLARE_MAPPING_TRAITS(Type)
#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Tagged union holding either a T or a Error.
Definition: Error.h:481
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
A range adaptor for a pair of iterators.
A class providing access to the contents of a minidump file.
Definition: Minidump.h:24
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This class provides various memory handling functions that manipulate MemoryBlock instances.
Definition: Memory.h:53
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:63
ProcessorArchitecture
The processor architecture of the system that generated this minidump.
Definition: Minidump.h:145
StreamType
The type of a minidump stream identifies its contents.
Definition: Minidump.h:50
OSPlatform
The OS Platform of the system that generated this minidump.
Definition: Minidump.h:152
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1873
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
ExceptionStream minidump stream.
Definition: MinidumpYAML.h:127
ExceptionStream(const minidump::ExceptionStream &MDExceptionStream, ArrayRef< uint8_t > ThreadContext)
Definition: MinidumpYAML.h:135
minidump::ExceptionStream MDExceptionStream
Definition: MinidumpYAML.h:128
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:140
Memory64ListStream(std::vector< detail::ParsedMemory64Descriptor > Entries={})
Definition: MinidumpYAML.h:121
minidump::Memory64ListHeader Header
Definition: MinidumpYAML.h:119
A structure containing the list of MemoryInfo entries comprising a MemoryInfoList stream.
Definition: MinidumpYAML.h:147
MemoryInfoListStream(iterator_range< object::MinidumpFile::MemoryInfoIterator > Range)
Definition: MinidumpYAML.h:154
std::vector< minidump::MemoryInfo > Infos
Definition: MinidumpYAML.h:148
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:160
The top level structure representing a minidump object, consisting of a minidump header,...
Definition: MinidumpYAML.h:220
Object & operator=(Object &&)=default
std::vector< std::unique_ptr< Stream > > Streams
The list of streams in this minidump object.
Definition: MinidumpYAML.h:235
Object(const Object &)=delete
static Expected< Object > create(const object::MinidumpFile &File)
Object(const minidump::Header &Header, std::vector< std::unique_ptr< Stream > > Streams)
Definition: MinidumpYAML.h:227
minidump::Header Header
The minidump header.
Definition: MinidumpYAML.h:232
Object & operator=(const Object &)=delete
Object(Object &&)=default
A minidump stream represented as a sequence of hex bytes.
Definition: MinidumpYAML.h:167
RawContentStream(minidump::StreamType Type, ArrayRef< uint8_t > Content={})
Definition: MinidumpYAML.h:171
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:175
The base class for all minidump streams.
Definition: MinidumpYAML.h:27
static std::unique_ptr< Stream > create(minidump::StreamType Type)
Create an empty stream of the given Type.
const StreamKind Kind
Definition: MinidumpYAML.h:43
Stream(StreamKind Kind, minidump::StreamType Type)
Definition: MinidumpYAML.h:40
static StreamKind getKind(minidump::StreamType Type)
Get the stream Kind used for representing streams of a given Type.
const minidump::StreamType Type
Definition: MinidumpYAML.h:44
SystemInfo minidump stream.
Definition: MinidumpYAML.h:181
SystemInfoStream(const minidump::SystemInfo &Info, std::string CSDVersion)
Definition: MinidumpYAML.h:190
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:195
A StringRef, which is printed using YAML block notation.
Definition: MinidumpYAML.h:205
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:211
TextContentStream(minidump::StreamType Type, StringRef Text={})
Definition: MinidumpYAML.h:208
A stream representing a list of abstract entries in a minidump stream.
Definition: MinidumpYAML.h:62
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:70
ListStream(std::vector< entry_type > Entries={})
Definition: MinidumpYAML.h:67
std::vector< entry_type > Entries
Definition: MinidumpYAML.h:65
static constexpr Stream::StreamKind Kind
Definition: MinidumpYAML.h:104
A structure containing all data describing a single memory region.
Definition: MinidumpYAML.h:95
static constexpr Stream::StreamKind Kind
Definition: MinidumpYAML.h:96
A structure containing all data belonging to a single minidump module.
Definition: MinidumpYAML.h:74
static constexpr Stream::StreamKind Kind
Definition: MinidumpYAML.h:75
A structure containing all data belonging to a single minidump thread.
Definition: MinidumpYAML.h:85
static constexpr Stream::StreamKind Kind
Definition: MinidumpYAML.h:86
Specifies the location and type of a single stream in the minidump file.
Definition: Minidump.h:137
The minidump header is the first part of a minidump file.
Definition: Minidump.h:32
Describes a single memory range (both its VM address and where to find it in the file) of the process...
Definition: Minidump.h:67
The SystemInfo stream, containing various information about the system where this minidump was genera...
Definition: Minidump.h:178
Describes a single thread in the minidump file.
Definition: Minidump.h:236
static StringRef input(StringRef Scalar, void *, MinidumpYAML::BlockStringRef &Text)
Definition: MinidumpYAML.h:249
static void output(const MinidumpYAML::BlockStringRef &Text, void *, raw_ostream &OS)
Definition: MinidumpYAML.h:244
static void mapping(IO &IO, minidump::MemoryDescriptor &Memory, BinaryRef &Content)
static void mapping(IO &IO, minidump::MemoryDescriptor_64 &Memory, BinaryRef &Content)
static std::string validate(IO &IO, std::unique_ptr< MinidumpYAML::Stream > &S)
static void mapping(IO &IO, std::unique_ptr< MinidumpYAML::Stream > &S)