OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (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 |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #ifndef CRASHPAD_MINIDUMP_MINIDUMP_FILE_WRITER_H_ |
| 16 #define CRASHPAD_MINIDUMP_MINIDUMP_FILE_WRITER_H_ |
| 17 |
| 18 #include <dbghelp.h> |
| 19 #include <sys/types.h> |
| 20 |
| 21 #include <set> |
| 22 #include <vector> |
| 23 |
| 24 #include "base/basictypes.h" |
| 25 #include "minidump/minidump_stream_writer.h" |
| 26 #include "minidump/minidump_writable.h" |
| 27 #include "util/file/file_writer.h" |
| 28 |
| 29 namespace crashpad { |
| 30 |
| 31 //! \brief The root-level object in a minidump file. |
| 32 //! |
| 33 //! This object writes a MINIDUMP_HEADER and list of MINIDUMP_DIRECTORY entries |
| 34 //! to a minidump file. |
| 35 class MinidumpFileWriter final : public internal::MinidumpWritable { |
| 36 public: |
| 37 MinidumpFileWriter(); |
| 38 ~MinidumpFileWriter(); |
| 39 |
| 40 //! \brief Sets MINIDUMP_HEADER::Timestamp. |
| 41 //! |
| 42 //! \note Valid in #kStateMutable. |
| 43 void SetTimestamp(time_t timestamp); |
| 44 |
| 45 //! \brief Adds a stream to the minidump file as a child of the object, and |
| 46 //! arranges for a MINIDUMP_DIRECTORY entry to point to it. |
| 47 //! |
| 48 //! At most one object of each stream type (as obtained from |
| 49 //! internal::MinidumpStreamWriter::StreamType()) may be added to a |
| 50 //! MinidumpFileWriter object. It is an error to attempt to add multiple |
| 51 //! streams with the same stream type. |
| 52 //! |
| 53 //! \note Valid in #kStateMutable. |
| 54 void AddStream(internal::MinidumpStreamWriter* stream); |
| 55 |
| 56 // MinidumpWritable: |
| 57 |
| 58 //! \copydoc internal::MinidumpWritable::WriteEverything() |
| 59 //! |
| 60 //! This method does not initially write the final value for |
| 61 //! MINIDUMP_HEADER::Signature. After all child objects have been written, it |
| 62 //! rewinds to the beginning of the file and writes the correct value for this |
| 63 //! field. This prevents incompletely-written minidump files from being |
| 64 //! mistaken for valid ones. |
| 65 virtual bool WriteEverything(FileWriterInterface* file_writer) override; |
| 66 |
| 67 protected: |
| 68 // MinidumpWritable: |
| 69 virtual bool Freeze() override; |
| 70 virtual size_t SizeOfObject() override; |
| 71 virtual std::vector<MinidumpWritable*> Children() override; |
| 72 virtual bool WillWriteAtOffsetImpl(off_t offset) override; |
| 73 virtual bool WriteObject(FileWriterInterface* file_writer) override; |
| 74 |
| 75 private: |
| 76 MINIDUMP_HEADER header_; |
| 77 std::vector<internal::MinidumpStreamWriter*> streams_; // weak |
| 78 |
| 79 // Protects against multiple streams with the same ID being added. |
| 80 std::set<MinidumpStreamType> stream_types_; |
| 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(MinidumpFileWriter); |
| 83 }; |
| 84 |
| 85 } // namespace crashpad |
| 86 |
| 87 #endif // CRASHPAD_MINIDUMP_MINIDUMP_WRITER_H_ |
OLD | NEW |