LLVM  14.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 
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 
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 = {})
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 
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.
128 struct MemoryInfoListStream : public Stream {
129  std::vector<minidump::MemoryInfo> Infos;
130 
132  : Stream(StreamKind::MemoryInfoList,
133  minidump::StreamType::MemoryInfoList) {}
134 
137  : Stream(StreamKind::MemoryInfoList,
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 
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 
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.
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 
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 std::string 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 
254 
258 
265 
272 
273 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<llvm::MinidumpYAML::Stream>)
278 
280 
281 #endif // LLVM_OBJECTYAML_MINIDUMPYAML_H
llvm::minidump::MemoryDescriptor
Describes a single memory range (both its VM address and where to find it in the file) of the process...
Definition: Minidump.h:67
llvm::MinidumpYAML::Stream::StreamKind::Exception
@ Exception
LLVM_YAML_DECLARE_MAPPING_TRAITS
#define LLVM_YAML_DECLARE_MAPPING_TRAITS(Type)
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
Minidump.h
llvm::MinidumpYAML::TextContentStream::Text
BlockStringRef Text
Definition: MinidumpYAML.h:187
llvm::minidump::CPUInfo::ArmInfo
Definition: Minidump.h:149
LLVM_YAML_DECLARE_ENUM_TRAITS
#define LLVM_YAML_DECLARE_ENUM_TRAITS(Type)
llvm::MinidumpYAML::Object::Object
Object()=default
llvm::MinidumpYAML::MemoryInfoListStream::MemoryInfoListStream
MemoryInfoListStream()
Definition: MinidumpYAML.h:131
llvm::yaml::BlockScalarTraits< MinidumpYAML::BlockStringRef >::input
static StringRef input(StringRef Scalar, void *, MinidumpYAML::BlockStringRef &Text)
Definition: MinidumpYAML.h:230
llvm::MinidumpYAML::Object
The top level structure representing a minidump object, consisting of a minidump header,...
Definition: MinidumpYAML.h:201
llvm::minidump::ProcessorArchitecture
ProcessorArchitecture
The processor architecture of the system that generated this minidump.
Definition: Minidump.h:128
llvm::MinidumpYAML::ExceptionStream::MDExceptionStream
minidump::ExceptionStream MDExceptionStream
Definition: MinidumpYAML.h:109
llvm::minidump::ExceptionStream
Definition: Minidump.h:243
Content
T Content
Definition: ELFObjHandler.cpp:90
LLVM_YAML_IS_SEQUENCE_VECTOR
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
llvm::yaml::BlockScalarTraits< MinidumpYAML::BlockStringRef >::output
static void output(const MinidumpYAML::BlockStringRef &Text, void *, raw_ostream &OS)
Definition: MinidumpYAML.h:225
llvm::MinidumpYAML::Stream::create
static std::unique_ptr< Stream > create(minidump::StreamType Type)
Create an empty stream of the given Type.
Definition: MinidumpYAML.cpp:97
llvm::minidump::MemoryInfo
Definition: Minidump.h:104
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::MinidumpYAML::RawContentStream::RawContentStream
RawContentStream(minidump::StreamType Type, ArrayRef< uint8_t > Content={})
Definition: MinidumpYAML.h:152
llvm::sys::path::end
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
llvm::MinidumpYAML::detail::ListStream::Entries
std::vector< entry_type > Entries
Definition: MinidumpYAML.h:64
llvm::MinidumpYAML::Stream::Type
const minidump::StreamType Type
Definition: MinidumpYAML.h:43
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::yaml::MappingTraits
Definition: ModuleSummaryIndex.h:52
llvm::RISCVFeatures::validate
void validate(const Triple &TT, const FeatureBitset &FeatureBits)
Definition: RISCVBaseInfo.cpp:90
llvm::minidump::MemoryType
MemoryType
Definition: Minidump.h:98
llvm::MinidumpYAML::detail::ParsedThread::Kind
static constexpr Stream::StreamKind Kind
Definition: MinidumpYAML.h:85
llvm::MinidumpYAML::SystemInfoStream::SystemInfoStream
SystemInfoStream(const minidump::SystemInfo &Info, std::string CSDVersion)
Definition: MinidumpYAML.h:171
llvm::MinidumpYAML::RawContentStream::Content
yaml::BinaryRef Content
Definition: MinidumpYAML.h:149
llvm::minidump::SystemInfo
The SystemInfo stream, containing various information about the system where this minidump was genera...
Definition: Minidump.h:161
llvm::minidump::VSFixedFileInfo
Definition: Minidump.h:182
llvm::MinidumpYAML::detail::ListStream
A stream representing a list of abstract entries in a minidump stream.
Definition: MinidumpYAML.h:61
llvm::MinidumpYAML::Stream::StreamKind
StreamKind
Definition: MinidumpYAML.h:28
llvm::MinidumpYAML::ExceptionStream::ExceptionStream
ExceptionStream()
Definition: MinidumpYAML.h:112
llvm::MinidumpYAML::Stream::getKind
static StreamKind getKind(minidump::StreamType Type)
Get the stream Kind used for representing streams of a given Type.
Definition: MinidumpYAML.cpp:70
llvm::MinidumpYAML::Object::operator=
Object & operator=(const Object &)=delete
llvm::minidump::Header
The minidump header is the first part of a minidump file.
Definition: Minidump.h:32
llvm::MinidumpYAML::SystemInfoStream::classof
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:176
llvm::MinidumpYAML::Object::Header
minidump::Header Header
The minidump header.
Definition: MinidumpYAML.h:213
llvm::MinidumpYAML::Object::Streams
std::vector< std::unique_ptr< Stream > > Streams
The list of streams in this minidump object.
Definition: MinidumpYAML.h:216
llvm::MinidumpYAML::Stream::StreamKind::MemoryList
@ MemoryList
YAML.h
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MinidumpYAML::ExceptionStream::ThreadContext
yaml::BinaryRef ThreadContext
Definition: MinidumpYAML.h:110
llvm::MinidumpYAML::detail::ParsedMemoryDescriptor::Kind
static constexpr Stream::StreamKind Kind
Definition: MinidumpYAML.h:95
llvm::minidump::MemoryProtection
MemoryProtection
Definition: Minidump.h:86
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::MinidumpYAML::SystemInfoStream::CSDVersion
std::string CSDVersion
Definition: MinidumpYAML.h:164
llvm::MinidumpYAML::Stream::StreamKind::MemoryInfoList
@ MemoryInfoList
llvm::MinidumpYAML::detail::ParsedMemoryDescriptor
A structure containing all data describing a single memory region.
Definition: MinidumpYAML.h:94
llvm::minidump::StreamType
StreamType
The type of a minidump stream identifies its contents.
Definition: Minidump.h:50
llvm::MinidumpYAML::MemoryInfoListStream::classof
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:141
llvm::minidump::MemoryState
MemoryState
Definition: Minidump.h:92
llvm::MinidumpYAML::ExceptionStream::ExceptionStream
ExceptionStream(const minidump::ExceptionStream &MDExceptionStream, ArrayRef< uint8_t > ThreadContext)
Definition: MinidumpYAML.h:116
LLVM_YAML_STRONG_TYPEDEF
#define LLVM_YAML_STRONG_TYPEDEF(_base, _type)
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::MinidumpYAML::Stream::StreamKind::TextContent
@ TextContent
llvm::MinidumpYAML::RawContentStream::Size
yaml::Hex32 Size
Definition: MinidumpYAML.h:150
llvm::MinidumpYAML::SystemInfoStream::SystemInfoStream
SystemInfoStream()
Definition: MinidumpYAML.h:166
LLVM_YAML_DECLARE_BITSET_TRAITS
#define LLVM_YAML_DECLARE_BITSET_TRAITS(Type)
llvm::MinidumpYAML::detail::ParsedModule
A structure containing all data belonging to a single minidump module.
Definition: MinidumpYAML.h:73
llvm::minidump::OSPlatform
OSPlatform
The OS Platform of the system that generated this minidump.
Definition: Minidump.h:135
llvm::MinidumpYAML::ExceptionStream::classof
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:121
llvm::move
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:1605
llvm::MinidumpYAML::MemoryInfoListStream::MemoryInfoListStream
MemoryInfoListStream(iterator_range< object::MinidumpFile::MemoryInfoIterator > Range)
Definition: MinidumpYAML.h:135
llvm::MinidumpYAML::Stream
The base class for all minidump streams.
Definition: MinidumpYAML.h:27
llvm::MinidumpYAML::SystemInfoStream
SystemInfo minidump stream.
Definition: MinidumpYAML.h:162
llvm::MinidumpYAML::TextContentStream
A StringRef, which is printed using YAML block notation.
Definition: MinidumpYAML.h:186
llvm::MinidumpYAML::Object::Object
Object(const minidump::Header &Header, std::vector< std::unique_ptr< Stream >> Streams)
Definition: MinidumpYAML.h:208
YAMLTraits.h
llvm::ArrayRef< uint8_t >
llvm::MinidumpYAML::detail::ListStream::ListStream
ListStream(std::vector< entry_type > Entries={})
Definition: MinidumpYAML.h:66
llvm::MinidumpYAML::MemoryInfoListStream::Infos
std::vector< minidump::MemoryInfo > Infos
Definition: MinidumpYAML.h:129
llvm::sys::Memory
This class provides various memory handling functions that manipulate MemoryBlock instances.
Definition: Memory.h:52
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::minidump::Exception
Definition: Minidump.h:230
llvm::yaml::BinaryRef
Specialized YAMLIO scalar type for representing a binary blob.
Definition: YAML.h:63
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MinidumpYAML::detail::ParsedModule::MiscRecord
yaml::BinaryRef MiscRecord
Definition: MinidumpYAML.h:80
llvm::MinidumpYAML::Stream::Kind
const StreamKind Kind
Definition: MinidumpYAML.h:42
llvm::MinidumpYAML::detail::ParsedMemoryDescriptor::Content
yaml::BinaryRef Content
Definition: MinidumpYAML.h:99
llvm::MinidumpYAML::RawContentStream::classof
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:156
llvm::MinidumpYAML::TextContentStream::TextContentStream
TextContentStream(minidump::StreamType Type, StringRef Text={})
Definition: MinidumpYAML.h:189
std
Definition: BitVector.h:838
llvm::minidump::Directory
Specifies the location and type of a single stream in the minidump file.
Definition: Minidump.h:120
llvm::MinidumpYAML::detail::ParsedModule::Entry
minidump::Module Entry
Definition: MinidumpYAML.h:77
llvm::MinidumpYAML::detail::ListStream::classof
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:69
llvm::MinidumpYAML::Stream::StreamKind::SystemInfo
@ SystemInfo
llvm::MinidumpYAML::detail::ParsedThread::Context
yaml::BinaryRef Context
Definition: MinidumpYAML.h:90
llvm::MinidumpYAML::SystemInfoStream::Info
minidump::SystemInfo Info
Definition: MinidumpYAML.h:163
llvm::MinidumpYAML::Object::create
static Expected< Object > create(const object::MinidumpFile &File)
Definition: MinidumpYAML.cpp:553
llvm::MinidumpYAML::ExceptionStream
ExceptionStream minidump stream.
Definition: MinidumpYAML.h:108
Minidump.h
llvm::MinidumpYAML::RawContentStream
A minidump stream represented as a sequence of hex bytes.
Definition: MinidumpYAML.h:148
llvm::object::MinidumpFile
A class providing access to the contents of a minidump file.
Definition: Minidump.h:23
llvm::minidump::Thread
Describes a single thread in the minidump file.
Definition: Minidump.h:219
llvm::MinidumpYAML::Stream::StreamKind::ThreadList
@ ThreadList
llvm::MinidumpYAML::Stream::StreamKind::ModuleList
@ ModuleList
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::minidump::CPUInfo::OtherInfo
Definition: Minidump.h:153
llvm::msgpack::Type
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:49
llvm::minidump::Module
Definition: Minidump.h:203
llvm::MinidumpYAML::detail::ParsedThread
A structure containing all data belonging to a single minidump thread.
Definition: MinidumpYAML.h:84
llvm::MinidumpYAML::detail::ParsedThread::Stack
yaml::BinaryRef Stack
Definition: MinidumpYAML.h:89
llvm::MinidumpYAML::detail::ParsedModule::CvRecord
yaml::BinaryRef CvRecord
Definition: MinidumpYAML.h:79
llvm::MinidumpYAML::Stream::Stream
Stream(StreamKind Kind, minidump::StreamType Type)
Definition: MinidumpYAML.h:39
llvm::MinidumpYAML::detail::ParsedModule::Name
std::string Name
Definition: MinidumpYAML.h:78
llvm::MinidumpYAML::Stream::StreamKind::RawContent
@ RawContent
llvm::MinidumpYAML::detail::ParsedModule::Kind
static constexpr Stream::StreamKind Kind
Definition: MinidumpYAML.h:74
llvm::minidump::CPUInfo::X86Info
Definition: Minidump.h:143
llvm::MinidumpYAML::TextContentStream::classof
static bool classof(const Stream *S)
Definition: MinidumpYAML.h:192
File
Instrumentation for Order File
Definition: InstrOrderFile.cpp:205
llvm::MinidumpYAML::detail::ParsedThread::Entry
minidump::Thread Entry
Definition: MinidumpYAML.h:88
llvm::MinidumpYAML::detail::ParsedMemoryDescriptor::Entry
minidump::MemoryDescriptor Entry
Definition: MinidumpYAML.h:98
llvm::MinidumpYAML::Stream::~Stream
virtual ~Stream()
llvm::MinidumpYAML::MemoryInfoListStream
A structure containing the list of MemoryInfo entries comprising a MemoryInfoList stream.
Definition: MinidumpYAML.h:128
llvm::MinidumpYAML::detail::ListStream::entry_type
EntryT entry_type
Definition: MinidumpYAML.h:62