LLVM  10.0.0svn
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 
13 #include "llvm/Object/Minidump.h"
14 #include "llvm/ObjectYAML/YAML.h"
16 
17 namespace llvm {
18 namespace 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.
27 struct Stream {
28  enum class StreamKind {
29  Exception,
31  MemoryList,
32  ModuleList,
33  RawContent,
34  SystemInfo,
36  ThreadList,
37  };
38 
39  Stream(StreamKind Kind, minidump::StreamType Type) : Kind(Kind), Type(Type) {}
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 
57 namespace 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.
61 template <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.
73 struct ParsedModule {
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.
84 struct ParsedThread {
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.
108 struct ExceptionStream : public Stream {
111 
114  MDExceptionStream({}) {}
115 
116  explicit ExceptionStream(const minidump::ExceptionStream &MDExceptionStream,
117  ArrayRef<uint8_t> ThreadContext)
119  MDExceptionStream(MDExceptionStream), ThreadContext(ThreadContext) {}
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.
128 struct MemoryInfoListStream : public 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.
148 struct RawContentStream : public Stream {
150  yaml::Hex32 Size;
151 
153  : Stream(StreamKind::RawContent, Type), Content(Content),
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.
162 struct SystemInfoStream : public Stream {
164  std::string CSDVersion;
165 
168  memset(&Info, 0, sizeof(Info));
169  }
170 
172  std::string CSDVersion)
174  Info(Info), CSDVersion(std::move(CSDVersion)) {}
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.
182 LLVM_YAML_STRONG_TYPEDEF(StringRef, BlockStringRef)
183 
184 /// A minidump stream containing textual data (typically, the contents of a
185 /// /proc/<pid> file on linux).
186 struct 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.
201 struct 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 
208  Object(const minidump::Header &Header,
209  std::vector<std::unique_ptr<Stream>> Streams)
210  : Header(Header), Streams(std::move(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 
219 };
220 
221 } // namespace MinidumpYAML
222 
223 namespace yaml {
224 template <> 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 
237 template <> struct MappingTraits<std::unique_ptr<MinidumpYAML::Stream>> {
238  static void mapping(IO &IO, std::unique_ptr<MinidumpYAML::Stream> &S);
239  static StringRef validate(IO &IO, std::unique_ptr<MinidumpYAML::Stream> &S);
240 };
241 
242 template <> struct MappingContextTraits<minidump::MemoryDescriptor, BinaryRef> {
243  static void mapping(IO &IO, minidump::MemoryDescriptor &Memory,
244  BinaryRef &Content);
245 };
246 
247 } // namespace yaml
248 
249 } // namespace llvm
250 
251 LLVM_YAML_DECLARE_BITSET_TRAITS(llvm::minidump::MemoryProtection)
252 LLVM_YAML_DECLARE_BITSET_TRAITS(llvm::minidump::MemoryState)
253 LLVM_YAML_DECLARE_BITSET_TRAITS(llvm::minidump::MemoryType)
254 
255 LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::minidump::ProcessorArchitecture)
256 LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::minidump::OSPlatform)
257 LLVM_YAML_DECLARE_ENUM_TRAITS(llvm::minidump::StreamType)
258 
259 LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::CPUInfo::ArmInfo)
260 LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::CPUInfo::OtherInfo)
261 LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::CPUInfo::X86Info)
262 LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::Exception)
263 LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::MemoryInfo)
264 LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::minidump::VSFixedFileInfo)
265 
266 LLVM_YAML_DECLARE_MAPPING_TRAITS(
268 LLVM_YAML_DECLARE_MAPPING_TRAITS(
270 LLVM_YAML_DECLARE_MAPPING_TRAITS(
272 
273 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::MinidumpYAML::Stream>)
274 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MinidumpYAML::MemoryListStream::entry_type)
275 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MinidumpYAML::ModuleListStream::entry_type)
276 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::MinidumpYAML::ThreadListStream::entry_type)
277 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::minidump::MemoryInfo)
278 
279 LLVM_YAML_DECLARE_MAPPING_TRAITS(llvm::MinidumpYAML::Object)
280 
281 #endif // LLVM_OBJECTYAML_MINIDUMPYAML_H
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:48
SystemInfo minidump stream.
Definition: MinidumpYAML.h:162
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This class provides various memory handling functions that manipulate MemoryBlock instances...
Definition: Memory.h:53
ProcessorArchitecture
The processor architecture of the system that generated this minidump.
Definition: Minidump.h:128
ListStream(std::vector< entry_type > Entries={})
Definition: MinidumpYAML.h:66
minidump::Header Header
The minidump header.
Definition: MinidumpYAML.h:213
OSPlatform
The OS Platform of the system that generated this minidump.
Definition: Minidump.h:135
Definition: BitVector.h:937
StreamType
The type of a minidump stream identifies its contents.
Definition: Minidump.h:50
SystemInfoStream(const minidump::SystemInfo &Info, std::string CSDVersion)
Definition: MinidumpYAML.h:171
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
The minidump header is the first part of a minidump file.
Definition: Minidump.h:32
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:176
RawContentStream(minidump::StreamType Type, ArrayRef< uint8_t > Content={})
Definition: MinidumpYAML.h:152
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:141
A structure containing all data belonging to a single minidump module.
Definition: MinidumpYAML.h:73
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:69
The top level structure representing a minidump object, consisting of a minidump header, and zero or more streams.
Definition: MinidumpYAML.h:201
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
Instrumentation for Order File
static StreamKind getKind(minidump::StreamType Type)
Get the stream Kind used for representing streams of a given Type.
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:192
Stream(StreamKind Kind, minidump::StreamType Type)
Definition: MinidumpYAML.h:39
A stream representing a list of abstract entries in a minidump stream.
Definition: MinidumpYAML.h:61
Describes a single memory range (both its VM address and where to find it in the file) of the process...
Definition: Minidump.h:67
ExceptionStream minidump stream.
Definition: MinidumpYAML.h:108
The base class for all minidump streams.
Definition: MinidumpYAML.h:27
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:121
A structure containing all data describing a single memory region.
Definition: MinidumpYAML.h:94
std::vector< std::unique_ptr< Stream > > Streams
The list of streams in this minidump object.
Definition: MinidumpYAML.h:216
Object(const minidump::Header &Header, std::vector< std::unique_ptr< Stream >> Streams)
Definition: MinidumpYAML.h:208
A minidump stream represented as a sequence of hex bytes.
Definition: MinidumpYAML.h:148
A range adaptor for a pair of iterators.
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:63
MemoryInfoListStream(iterator_range< object::MinidumpFile::MemoryInfoIterator > Range)
Definition: MinidumpYAML.h:135
A StringRef, which is printed using YAML block notation.
Definition: MinidumpYAML.h:186
Specifies the location and type of a single stream in the minidump file.
Definition: Minidump.h:120
uint32_t Size
Definition: Profile.cpp:46
std::vector< minidump::MemoryInfo > Infos
Definition: MinidumpYAML.h:129
TextContentStream(minidump::StreamType Type, StringRef Text={})
Definition: MinidumpYAML.h:189
A structure containing all data belonging to a single minidump thread.
Definition: MinidumpYAML.h:84
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:156
Describes a single thread in the minidump file.
Definition: Minidump.h:219
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
A structure containing the list of MemoryInfo entries comprising a MemoryInfoList stream...
Definition: MinidumpYAML.h:128
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
const StreamKind Kind
Definition: MinidumpYAML.h:42
static void output(const MinidumpYAML::BlockStringRef &Text, void *, raw_ostream &OS)
Definition: MinidumpYAML.h:225
static std::unique_ptr< Stream > create(minidump::StreamType Type)
Create an empty stream of the given Type.
const minidump::StreamType Type
Definition: MinidumpYAML.h:43
A class providing access to the contents of a minidump file.
Definition: Minidump.h:23
void validate(const Triple &TT, const FeatureBitset &FeatureBits)
static StringRef input(StringRef Scalar, void *, MinidumpYAML::BlockStringRef &Text)
Definition: MinidumpYAML.h:230
The SystemInfo stream, containing various information about the system where this minidump was genera...
Definition: Minidump.h:161
std::vector< entry_type > Entries
Definition: MinidumpYAML.h:64