Crashpad
Public Member Functions | Protected Member Functions | List of all members
crashpad::MinidumpFileWriter Class Referencefinal

The root-level object in a minidump file. More...

#include "minidump/minidump_file_writer.h"

Inheritance diagram for crashpad::MinidumpFileWriter:
crashpad::internal::MinidumpWritable

Public Member Functions

void InitializeFromSnapshot (const ProcessSnapshot *process_snapshot)
 Initializes the MinidumpFileWriter and populates it with appropriate child streams based on process_snapshot. More...
 
void SetTimestamp (time_t timestamp)
 Sets MINIDUMP_HEADER::Timestamp. More...
 
bool AddStream (std::unique_ptr< internal::MinidumpStreamWriter > stream)
 Adds a stream to the minidump file and arranges for a MINIDUMP_DIRECTORY entry to point to it. More...
 
bool AddUserExtensionStream (std::unique_ptr< MinidumpUserExtensionStreamDataSource > user_extension_stream_data)
 Adds a user extension stream to the minidump file and arranges for a MINIDUMP_DIRECTORY entry to point to it. More...
 
bool WriteEverything (FileWriterInterface *file_writer) override
 Writes an object and all of its children to a minidump file. More...
 
bool WriteMinidump (FileWriterInterface *file_writer, bool allow_seek)
 Writes this object to a minidump file. More...
 
- Public Member Functions inherited from crashpad::internal::MinidumpWritable
void RegisterRVA (RVA *rva)
 Registers a file offset pointer as one that should point to the object on which this method is called. More...
 
void RegisterLocationDescriptor (MINIDUMP_LOCATION_DESCRIPTOR *location_descriptor)
 Registers a location descriptor as one that should point to the object on which this method is called. More...
 

Protected Member Functions

bool Freeze () override
 Transitions the object from kStateMutable to kStateFrozen. More...
 
size_t SizeOfObject () override
 Returns the amount of space that this object will consume when written to a minidump file, in bytes, not including any leading or trailing padding necessary to maintain proper alignment. More...
 
std::vector< MinidumpWritable * > Children () override
 Returns the object’s children. More...
 
bool WillWriteAtOffsetImpl (FileOffset offset) override
 Called once an object’s writable file offset is determined, as it transitions into kStateWritable. More...
 
bool WriteObject (FileWriterInterface *file_writer) override
 Writes the object’s content. More...
 
- Protected Member Functions inherited from crashpad::internal::MinidumpWritable
State state () const
 The state of the object.
 
virtual size_t Alignment ()
 Returns the object’s desired byte-boundary alignment. More...
 
virtual Phase WritePhase ()
 Returns the object’s desired write phase. More...
 
size_t WillWriteAtOffset (Phase phase, FileOffset *offset, std::vector< MinidumpWritable * > *write_sequence)
 Prepares the object to be written at a known file offset, transitioning it from kStateFrozen to kStateWritable. More...
 
bool WritePaddingAndObject (FileWriterInterface *file_writer)
 Writes the object, transitioning it from kStateWritable to kStateWritten. More...
 

Additional Inherited Members

- Protected Types inherited from crashpad::internal::MinidumpWritable
enum  State
 Identifies the state of an object. More...
 
enum  Phase
 Identifies the phase during which an object will be written to a minidump file. More...
 
- Static Protected Attributes inherited from crashpad::internal::MinidumpWritable
static constexpr size_t kInvalidSize = std::numeric_limits<size_t>::max()
 A size value used to signal failure by methods that return size_t.
 

Detailed Description

The root-level object in a minidump file.

This object writes a MINIDUMP_HEADER and list of MINIDUMP_DIRECTORY entries to a minidump file.

Member Function Documentation

◆ AddStream()

bool crashpad::MinidumpFileWriter::AddStream ( std::unique_ptr< internal::MinidumpStreamWriter stream)

Adds a stream to the minidump file and arranges for a MINIDUMP_DIRECTORY entry to point to it.

This object takes ownership of stream and becomes its parent in the overall tree of internal::MinidumpWritable objects.

At most one object of each stream type (as obtained from internal::MinidumpStreamWriter::StreamType()) may be added to a MinidumpFileWriter object. If an attempt is made to add a stream whose type matches an existing stream’s type, this method discards the new stream.

Note
Valid in kStateMutable.
Returns
true on success. false on failure, as occurs when an attempt is made to add a stream whose type matches an existing stream’s type, with a message logged.

◆ AddUserExtensionStream()

bool crashpad::MinidumpFileWriter::AddUserExtensionStream ( std::unique_ptr< MinidumpUserExtensionStreamDataSource user_extension_stream_data)

Adds a user extension stream to the minidump file and arranges for a MINIDUMP_DIRECTORY entry to point to it.

This object takes ownership of user_extension_stream_data.

At most one object of each stream type (as obtained from internal::MinidumpStreamWriter::StreamType()) may be added to a MinidumpFileWriter object. If an attempt is made to add a stream whose type matches an existing stream’s type, this method discards the new stream.

Parameters
[in]user_extension_stream_dataThe stream data to add to the minidump file. Note that the buffer this object points to must be valid through WriteEverything().
Note
Valid in kStateMutable.
Returns
true on success. false on failure, as occurs when an attempt is made to add a stream whose type matches an existing stream’s type, with a message logged.

◆ Children()

std::vector< internal::MinidumpWritable * > crashpad::MinidumpFileWriter::Children ( )
overrideprotectedvirtual

Returns the object’s children.

Note
Valid in kStateFrozen or any subsequent state.

Reimplemented from crashpad::internal::MinidumpWritable.

◆ Freeze()

bool crashpad::MinidumpFileWriter::Freeze ( )
overrideprotectedvirtual

Transitions the object from kStateMutable to kStateFrozen.

The default implementation marks the object as frozen and recursively calls Freeze() on all of its children. Subclasses may override this method to perform processing that should only be done once callers have finished populating an object with data. Typically, a subclass implementation would call RegisterRVA() or RegisterLocationDescriptor() on other objects as appropriate, because at the time Freeze() runs, the in-memory locations of RVAs and location descriptors are known and will not change for the remaining duration of an object’s lifetime.

Returns
true on success. false on failure, with an appropriate message logged.

Reimplemented from crashpad::internal::MinidumpWritable.

◆ InitializeFromSnapshot()

void crashpad::MinidumpFileWriter::InitializeFromSnapshot ( const ProcessSnapshot process_snapshot)

Initializes the MinidumpFileWriter and populates it with appropriate child streams based on process_snapshot.

This method will add additional streams to the minidump file as children of the MinidumpFileWriter object and as pointees of the top-level MINIDUMP_DIRECTORY. To do so, it will obtain other snapshot information from process_snapshot, such as a SystemSnapshot, lists of ThreadSnapshot and ModuleSnapshot objects, and, if available, an ExceptionSnapshot.

The streams are added in the order that they are expected to be most useful to minidump readers, to improve data locality and minimize seeking. The streams are added in this order:

  • kMinidumpStreamTypeSystemInfo
  • kMinidumpStreamTypeMiscInfo
  • kMinidumpStreamTypeThreadList
  • kMinidumpStreamTypeException (if present)
  • kMinidumpStreamTypeModuleList
  • kMinidumpStreamTypeUnloadedModuleList (if present)
  • kMinidumpStreamTypeCrashpadInfo (if present)
  • kMinidumpStreamTypeMemoryInfoList (if present)
  • kMinidumpStreamTypeHandleData (if present)
  • User streams (if present)
  • kMinidumpStreamTypeMemoryList
Parameters
[in]process_snapshotThe process snapshot to use as source data.
Note
Valid in kStateMutable. No mutator methods may be called before this method, and it is not normally necessary to call any mutator methods after this method.

◆ SetTimestamp()

void crashpad::MinidumpFileWriter::SetTimestamp ( time_t  timestamp)

Sets MINIDUMP_HEADER::Timestamp.

Note
Valid in kStateMutable.

◆ SizeOfObject()

size_t crashpad::MinidumpFileWriter::SizeOfObject ( )
overrideprotectedvirtual

Returns the amount of space that this object will consume when written to a minidump file, in bytes, not including any leading or trailing padding necessary to maintain proper alignment.

Note
Valid in kStateFrozen or any subsequent state.

Implements crashpad::internal::MinidumpWritable.

◆ WillWriteAtOffsetImpl()

bool crashpad::MinidumpFileWriter::WillWriteAtOffsetImpl ( FileOffset  offset)
overrideprotectedvirtual

Called once an object’s writable file offset is determined, as it transitions into kStateWritable.

Subclasses can override this method if they need to provide additional processing once their writable file offset is known. Typically, this will be done by subclasses that handle certain RVAs themselves instead of using the RegisterRVA() interface.

Parameters
[in]offsetThe file offset at which the object will be written. The value passed to this method will already have been adjusted to meet alignment requirements.
Returns
true on success. false on error, indicating that the minidump file should not be written.
Note
Valid in kStateFrozen. The object will transition to kStateWritable after this method returns.

Reimplemented from crashpad::internal::MinidumpWritable.

◆ WriteEverything()

bool crashpad::MinidumpFileWriter::WriteEverything ( FileWriterInterface file_writer)
overridevirtual

Writes an object and all of its children to a minidump file.

Use this on the root object of a tree of MinidumpWritable objects, typically on a MinidumpFileWriter object.

Parameters
[in]file_writerThe file writer to receive the minidump file’s content.
Returns
true on success. false on failure, with an appropriate message logged.
Note
Valid in kStateMutable, and transitions the object and the entire tree beneath it through all states to kStateWritten.
This method should rarely be overridden.

This method does not initially write the final value for MINIDUMP_HEADER::Signature. After all child objects have been written, it rewinds to the beginning of the file and writes the correct value for this field. This prevents incompletely-written minidump files from being mistaken for valid ones.

Reimplemented from crashpad::internal::MinidumpWritable.

◆ WriteMinidump()

bool crashpad::MinidumpFileWriter::WriteMinidump ( FileWriterInterface file_writer,
bool  allow_seek 
)

Writes this object to a minidump file.

Same as WriteEverything, but give the option to disable the seek. It is typically used to write to stream backed FileWriterInterface which doesn't support seek.

Parameters
[in]file_writerThe file writer to receive the minidump file’s content.
[in]allow_seekWhether seek is allowed.
Returns
true on success. false on failure, with an appropriate message logged.

◆ WriteObject()

bool crashpad::MinidumpFileWriter::WriteObject ( FileWriterInterface file_writer)
overrideprotectedvirtual

Writes the object’s content.

Parameters
[in]file_writerThe file writer to receive the object’s content.
Returns
true on success. false on error, indicating that the content could not be written to the minidump file.
Note
Valid in kStateWritable. The object will transition to kStateWritten after this method returns.

Implements crashpad::internal::MinidumpWritable.


The documentation for this class was generated from the following files: