LLVM 19.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 {
37 };
38
40 virtual ~Stream(); // anchor
41
44
45 /// Get the stream Kind used for representing streams of a given Type.
47
48 /// Create an empty stream of the given Type.
49 static std::unique_ptr<Stream> create(minidump::StreamType Type);
50
51 /// Create a stream from the given stream directory entry.
53 create(const minidump::Directory &StreamDesc,
54 const object::MinidumpFile &File);
55};
56
57namespace detail {
58/// A stream representing a list of abstract entries in a minidump stream. Its
59/// instantiations can be used to represent the ModuleList stream and other
60/// streams with a similar structure.
61template <typename EntryT> struct ListStream : public Stream {
62 using entry_type = EntryT;
63
64 std::vector<entry_type> Entries;
65
66 explicit ListStream(std::vector<entry_type> Entries = {})
67 : Stream(EntryT::Kind, EntryT::Type), Entries(std::move(Entries)) {}
68
69 static bool classof(const Stream *S) { return S->Kind == EntryT::Kind; }
70};
71
72/// A structure containing all data belonging to a single minidump module.
75 static constexpr minidump::StreamType Type = minidump::StreamType::ModuleList;
76
78 std::string Name;
81};
82
83/// A structure containing all data belonging to a single minidump thread.
86 static constexpr minidump::StreamType Type = minidump::StreamType::ThreadList;
87
91};
92
93/// A structure containing all data describing a single memory region.
96 static constexpr minidump::StreamType Type = minidump::StreamType::MemoryList;
97
100};
101} // namespace detail
102
106
107/// ExceptionStream minidump stream.
108struct ExceptionStream : public Stream {
111
113 : Stream(StreamKind::Exception, minidump::StreamType::Exception),
114 MDExceptionStream({}) {}
115
118 : Stream(StreamKind::Exception, minidump::StreamType::Exception),
120
121 static bool classof(const Stream *S) {
122 return S->Kind == StreamKind::Exception;
123 }
124};
125
126/// A structure containing the list of MemoryInfo entries comprising a
127/// MemoryInfoList stream.
129 std::vector<minidump::MemoryInfo> Infos;
130
133 minidump::StreamType::MemoryInfoList) {}
134
138 minidump::StreamType::MemoryInfoList),
139 Infos(Range.begin(), Range.end()) {}
140
141 static bool classof(const Stream *S) {
142 return S->Kind == StreamKind::MemoryInfoList;
143 }
144};
145
146/// A minidump stream represented as a sequence of hex bytes. This is used as a
147/// fallback when no other stream kind is suitable.
148struct RawContentStream : public Stream {
150 yaml::Hex32 Size;
151
154 Size(Content.size()) {}
155
156 static bool classof(const Stream *S) {
157 return S->Kind == StreamKind::RawContent;
158 }
159};
160
161/// SystemInfo minidump stream.
162struct SystemInfoStream : public Stream {
164 std::string CSDVersion;
165
167 : Stream(StreamKind::SystemInfo, minidump::StreamType::SystemInfo) {
168 memset(&Info, 0, sizeof(Info));
169 }
170
172 std::string CSDVersion)
173 : Stream(StreamKind::SystemInfo, minidump::StreamType::SystemInfo),
175
176 static bool classof(const Stream *S) {
177 return S->Kind == StreamKind::SystemInfo;
178 }
179};
180
181/// A StringRef, which is printed using YAML block notation.
182LLVM_YAML_STRONG_TYPEDEF(StringRef, BlockStringRef)
183
184/// A minidump stream containing textual data (typically, the contents of a
185/// /proc/<pid> file on linux).
186struct TextContentStream : public Stream {
187 BlockStringRef Text;
188
190 : Stream(StreamKind::TextContent, Type), Text(Text) {}
191
192 static bool classof(const Stream *S) {
193 return S->Kind == StreamKind::TextContent;
194 }
195};
196
197/// The top level structure representing a minidump object, consisting of a
198/// minidump header, and zero or more streams. To construct an Object from a
199/// minidump file, use the static create function. To serialize to/from yaml,
200/// use the appropriate streaming operator on a yaml stream.
201struct Object {
202 Object() = default;
203 Object(const Object &) = delete;
204 Object &operator=(const Object &) = delete;
205 Object(Object &&) = default;
206 Object &operator=(Object &&) = default;
207
209 std::vector<std::unique_ptr<Stream>> Streams)
211
212 /// The minidump header.
214
215 /// The list of streams in this minidump object.
216 std::vector<std::unique_ptr<Stream>> Streams;
217
218 static Expected<Object> create(const object::MinidumpFile &File);
219};
220
221} // namespace MinidumpYAML
222
223namespace yaml {
224template <> struct BlockScalarTraits<MinidumpYAML::BlockStringRef> {
225 static void output(const MinidumpYAML::BlockStringRef &Text, void *,
226 raw_ostream &OS) {
227 OS << Text;
228 }
229
230 static StringRef input(StringRef Scalar, void *,
231 MinidumpYAML::BlockStringRef &Text) {
232 Text = Scalar;
233 return "";
234 }
235};
236
237template <> struct MappingTraits<std::unique_ptr<MinidumpYAML::Stream>> {
238 static void mapping(IO &IO, std::unique_ptr<MinidumpYAML::Stream> &S);
239 static std::string validate(IO &IO, std::unique_ptr<MinidumpYAML::Stream> &S);
240};
241
242template <> struct MappingContextTraits<minidump::MemoryDescriptor, BinaryRef> {
245};
246
247} // namespace yaml
248
249} // namespace llvm
250
254
258
265
272
273LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::MinidumpYAML::Stream>)
278
280
281#endif // LLVM_OBJECTYAML_MINIDUMPYAML_H
T Content
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:474
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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:23
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:52
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:128
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:135
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:1858
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
ExceptionStream minidump stream.
Definition: MinidumpYAML.h:108
ExceptionStream(const minidump::ExceptionStream &MDExceptionStream, ArrayRef< uint8_t > ThreadContext)
Definition: MinidumpYAML.h:116
minidump::ExceptionStream MDExceptionStream
Definition: MinidumpYAML.h:109
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:121
A structure containing the list of MemoryInfo entries comprising a MemoryInfoList stream.
Definition: MinidumpYAML.h:128
MemoryInfoListStream(iterator_range< object::MinidumpFile::MemoryInfoIterator > Range)
Definition: MinidumpYAML.h:135
std::vector< minidump::MemoryInfo > Infos
Definition: MinidumpYAML.h:129
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:141
The top level structure representing a minidump object, consisting of a minidump header,...
Definition: MinidumpYAML.h:201
Object & operator=(Object &&)=default
std::vector< std::unique_ptr< Stream > > Streams
The list of streams in this minidump object.
Definition: MinidumpYAML.h:216
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:208
minidump::Header Header
The minidump header.
Definition: MinidumpYAML.h:213
Object & operator=(const Object &)=delete
Object(Object &&)=default
A minidump stream represented as a sequence of hex bytes.
Definition: MinidumpYAML.h:148
RawContentStream(minidump::StreamType Type, ArrayRef< uint8_t > Content={})
Definition: MinidumpYAML.h:152
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:156
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:42
Stream(StreamKind Kind, minidump::StreamType Type)
Definition: MinidumpYAML.h:39
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:43
SystemInfo minidump stream.
Definition: MinidumpYAML.h:162
SystemInfoStream(const minidump::SystemInfo &Info, std::string CSDVersion)
Definition: MinidumpYAML.h:171
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:176
A StringRef, which is printed using YAML block notation.
Definition: MinidumpYAML.h:186
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:192
TextContentStream(minidump::StreamType Type, StringRef Text={})
Definition: MinidumpYAML.h:189
A stream representing a list of abstract entries in a minidump stream.
Definition: MinidumpYAML.h:61
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:69
ListStream(std::vector< entry_type > Entries={})
Definition: MinidumpYAML.h:66
std::vector< entry_type > Entries
Definition: MinidumpYAML.h:64
A structure containing all data describing a single memory region.
Definition: MinidumpYAML.h:94
static constexpr Stream::StreamKind Kind
Definition: MinidumpYAML.h:95
A structure containing all data belonging to a single minidump module.
Definition: MinidumpYAML.h:73
static constexpr Stream::StreamKind Kind
Definition: MinidumpYAML.h:74
A structure containing all data belonging to a single minidump thread.
Definition: MinidumpYAML.h:84
static constexpr Stream::StreamKind Kind
Definition: MinidumpYAML.h:85
Specifies the location and type of a single stream in the minidump file.
Definition: Minidump.h:120
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:161
Describes a single thread in the minidump file.
Definition: Minidump.h:219
static StringRef input(StringRef Scalar, void *, MinidumpYAML::BlockStringRef &Text)
Definition: MinidumpYAML.h:230
static void output(const MinidumpYAML::BlockStringRef &Text, void *, raw_ostream &OS)
Definition: MinidumpYAML.h:225
static void mapping(IO &IO, minidump::MemoryDescriptor &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)