| OLD | NEW |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "base/macros.h" | 26 #include "base/macros.h" |
| 27 #include "minidump/minidump_extensions.h" | 27 #include "minidump/minidump_extensions.h" |
| 28 #include "minidump/minidump_stream_writer.h" | 28 #include "minidump/minidump_stream_writer.h" |
| 29 #include "minidump/minidump_writable.h" | 29 #include "minidump/minidump_writable.h" |
| 30 #include "util/file/file_io.h" | 30 #include "util/file/file_io.h" |
| 31 #include "util/stdlib/pointer_container.h" | 31 #include "util/stdlib/pointer_container.h" |
| 32 | 32 |
| 33 namespace crashpad { | 33 namespace crashpad { |
| 34 | 34 |
| 35 class ProcessSnapshot; | 35 class ProcessSnapshot; |
| 36 class MinidumpUserExtensionStreamDataSource; |
| 36 | 37 |
| 37 //! \brief The root-level object in a minidump file. | 38 //! \brief The root-level object in a minidump file. |
| 38 //! | 39 //! |
| 39 //! This object writes a MINIDUMP_HEADER and list of MINIDUMP_DIRECTORY entries | 40 //! This object writes a MINIDUMP_HEADER and list of MINIDUMP_DIRECTORY entries |
| 40 //! to a minidump file. | 41 //! to a minidump file. |
| 41 class MinidumpFileWriter final : public internal::MinidumpWritable { | 42 class MinidumpFileWriter final : public internal::MinidumpWritable { |
| 42 public: | 43 public: |
| 43 MinidumpFileWriter(); | 44 MinidumpFileWriter(); |
| 44 ~MinidumpFileWriter() override; | 45 ~MinidumpFileWriter() override; |
| 45 | 46 |
| 46 //! \brief Initializes the MinidumpFileWriter and populates it with | 47 //! \brief Initializes the MinidumpFileWriter and populates it with |
| 47 //! appropriate child streams based on \a process_snapshot. | 48 //! appropriate child streams based on \a process_snapshot. |
| 48 //! | 49 //! |
| 49 //! This method will add additional streams to the minidump file as children | 50 //! This method will add additional streams to the minidump file as children |
| 50 //! of the MinidumpFileWriter object and as pointees of the top-level | 51 //! of the MinidumpFileWriter object and as pointees of the top-level |
| 51 //! MINIDUMP_DIRECTORY. To do so, it will obtain other snapshot information | 52 //! MINIDUMP_DIRECTORY. To do so, it will obtain other snapshot information |
| 52 //! from \a process_snapshot, such as a SystemSnapshot, lists of | 53 //! from \a process_snapshot, such as a SystemSnapshot, lists of |
| 53 //! ThreadSnapshot and ModuleSnapshot objects, and, if available, an | 54 //! ThreadSnapshot and ModuleSnapshot objects, and, if available, an |
| 54 //! ExceptionSnapshot. | 55 //! ExceptionSnapshot. |
| 55 //! | 56 //! |
| 56 //! The streams are added in the order that they are expected to be most | 57 //! The streams are added in the order that they are expected to be most |
| 57 //! useful to minidump readers, to improve data locality and minimize seeking. | 58 //! useful to minidump readers, to improve data locality and minimize seeking. |
| 58 //! The streams are added in this order: | 59 //! The streams are added in this order: |
| 59 //! - kMinidumpStreamTypeSystemInfo | 60 //! - kMinidumpStreamTypeSystemInfo |
| 60 //! - kMinidumpStreamTypeMiscInfo | 61 //! - kMinidumpStreamTypeMiscInfo |
| 61 //! - kMinidumpStreamTypeThreadList | 62 //! - kMinidumpStreamTypeThreadList |
| 62 //! - kMinidumpStreamTypeException (if present) | 63 //! - kMinidumpStreamTypeException (if present) |
| 63 //! - kMinidumpStreamTypeModuleList | 64 //! - kMinidumpStreamTypeModuleList |
| 65 //! - kMinidumpStreamTypeUnloadedModuleList (if present) |
| 64 //! - kMinidumpStreamTypeCrashpadInfo (if present) | 66 //! - kMinidumpStreamTypeCrashpadInfo (if present) |
| 67 //! - kMinidumpStreamTypeMemoryInfoList (if present) |
| 68 //! - kMinidumpStreamTypeHandleData (if present) |
| 69 //! - User streams (if present) |
| 65 //! - kMinidumpStreamTypeMemoryList | 70 //! - kMinidumpStreamTypeMemoryList |
| 66 //! | 71 //! |
| 67 //! \param[in] process_snapshot The process snapshot to use as source data. | 72 //! \param[in] process_snapshot The process snapshot to use as source data. |
| 68 //! | 73 //! |
| 69 //! \note Valid in #kStateMutable. No mutator methods may be called before | 74 //! \note Valid in #kStateMutable. No mutator methods may be called before |
| 70 //! this method, and it is not normally necessary to call any mutator | 75 //! this method, and it is not normally necessary to call any mutator |
| 71 //! methods after this method. | 76 //! methods after this method. |
| 72 void InitializeFromSnapshot(const ProcessSnapshot* process_snapshot); | 77 void InitializeFromSnapshot(const ProcessSnapshot* process_snapshot); |
| 73 | 78 |
| 74 //! \brief Sets MINIDUMP_HEADER::Timestamp. | 79 //! \brief Sets MINIDUMP_HEADER::Timestamp. |
| 75 //! | 80 //! |
| 76 //! \note Valid in #kStateMutable. | 81 //! \note Valid in #kStateMutable. |
| 77 void SetTimestamp(time_t timestamp); | 82 void SetTimestamp(time_t timestamp); |
| 78 | 83 |
| 79 //! \brief Adds a stream to the minidump file and arranges for a | 84 //! \brief Adds a stream to the minidump file and arranges for a |
| 80 //! MINIDUMP_DIRECTORY entry to point to it. | 85 //! MINIDUMP_DIRECTORY entry to point to it. |
| 81 //! | 86 //! |
| 82 //! This object takes ownership of \a stream and becomes its parent in the | 87 //! This object takes ownership of \a stream and becomes its parent in the |
| 83 //! overall tree of internal::MinidumpWritable objects. | 88 //! overall tree of internal::MinidumpWritable objects. |
| 84 //! | 89 //! |
| 85 //! At most one object of each stream type (as obtained from | 90 //! At most one object of each stream type (as obtained from |
| 86 //! internal::MinidumpStreamWriter::StreamType()) may be added to a | 91 //! internal::MinidumpStreamWriter::StreamType()) may be added to a |
| 87 //! MinidumpFileWriter object. It is an error to attempt to add multiple | 92 //! MinidumpFileWriter object. If an attempt is made to add a stream whose |
| 88 //! streams with the same stream type. | 93 //! type matches an existing stream’s type, this method discards the new |
| 94 //! stream. |
| 89 //! | 95 //! |
| 90 //! \note Valid in #kStateMutable. | 96 //! \note Valid in #kStateMutable. |
| 91 void AddStream(std::unique_ptr<internal::MinidumpStreamWriter> stream); | 97 //! |
| 98 //! \return `true` on success. `false` on failure, as occurs when an attempt |
| 99 //! is made to add a stream whose type matches an existing stream’s type, |
| 100 //! with a message logged. |
| 101 bool AddStream(std::unique_ptr<internal::MinidumpStreamWriter> stream); |
| 102 |
| 103 //! \brief Adds a user extension stream to the minidump file and arranges for |
| 104 //! a MINIDUMP_DIRECTORY entry to point to it. |
| 105 //! |
| 106 //! This object takes ownership of \a user_extension_stream_data. |
| 107 //! |
| 108 //! At most one object of each stream type (as obtained from |
| 109 //! internal::MinidumpStreamWriter::StreamType()) may be added to a |
| 110 //! MinidumpFileWriter object. If an attempt is made to add a stream whose |
| 111 //! type matches an existing stream’s type, this method discards the new |
| 112 //! stream. |
| 113 //! |
| 114 //! \param[in] user_extension_stream_data The stream data to add to the |
| 115 //! minidump file. Note that the buffer this object points to must be valid |
| 116 //! through WriteEverything(). |
| 117 //! |
| 118 //! \note Valid in #kStateMutable. |
| 119 //! |
| 120 //! \return `true` on success. `false` on failure, as occurs when an attempt |
| 121 //! is made to add a stream whose type matches an existing stream’s type, |
| 122 //! with a message logged. |
| 123 bool AddUserExtensionStream( |
| 124 std::unique_ptr<MinidumpUserExtensionStreamDataSource> |
| 125 user_extension_stream_data); |
| 92 | 126 |
| 93 // MinidumpWritable: | 127 // MinidumpWritable: |
| 94 | 128 |
| 95 //! \copydoc internal::MinidumpWritable::WriteEverything() | 129 //! \copydoc internal::MinidumpWritable::WriteEverything() |
| 96 //! | 130 //! |
| 97 //! This method does not initially write the final value for | 131 //! This method does not initially write the final value for |
| 98 //! MINIDUMP_HEADER::Signature. After all child objects have been written, it | 132 //! MINIDUMP_HEADER::Signature. After all child objects have been written, it |
| 99 //! rewinds to the beginning of the file and writes the correct value for this | 133 //! rewinds to the beginning of the file and writes the correct value for this |
| 100 //! field. This prevents incompletely-written minidump files from being | 134 //! field. This prevents incompletely-written minidump files from being |
| 101 //! mistaken for valid ones. | 135 //! mistaken for valid ones. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 115 | 149 |
| 116 // Protects against multiple streams with the same ID being added. | 150 // Protects against multiple streams with the same ID being added. |
| 117 std::set<MinidumpStreamType> stream_types_; | 151 std::set<MinidumpStreamType> stream_types_; |
| 118 | 152 |
| 119 DISALLOW_COPY_AND_ASSIGN(MinidumpFileWriter); | 153 DISALLOW_COPY_AND_ASSIGN(MinidumpFileWriter); |
| 120 }; | 154 }; |
| 121 | 155 |
| 122 } // namespace crashpad | 156 } // namespace crashpad |
| 123 | 157 |
| 124 #endif // CRASHPAD_MINIDUMP_MINIDUMP_WRITER_H_ | 158 #endif // CRASHPAD_MINIDUMP_MINIDUMP_WRITER_H_ |
| OLD | NEW |