OLD | NEW |
1 // Copyright 2016 The Crashpad Authors. All rights reserved. | 1 // Copyright 2016 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, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #ifndef CRASHPAD_MINIDUMP_MINIDUMP_USER_STREAM_WRITER_H_ | 15 #ifndef CRASHPAD_MINIDUMP_MINIDUMP_USER_STREAM_WRITER_H_ |
16 #define CRASHPAD_MINIDUMP_MINIDUMP_USER_STREAM_WRITER_H_ | 16 #define CRASHPAD_MINIDUMP_MINIDUMP_USER_STREAM_WRITER_H_ |
17 | 17 |
18 #include <windows.h> | 18 #include <windows.h> |
19 #include <dbghelp.h> | 19 #include <dbghelp.h> |
20 #include <stdint.h> | 20 #include <stdint.h> |
21 | 21 |
22 #include <vector> | 22 #include <vector> |
23 | 23 |
24 #include "base/macros.h" | 24 #include "base/macros.h" |
| 25 #include "minidump/minidump_extensions.h" |
25 #include "minidump/minidump_stream_writer.h" | 26 #include "minidump/minidump_stream_writer.h" |
26 #include "minidump/minidump_writable.h" | 27 #include "minidump/minidump_writable.h" |
27 #include "snapshot/module_snapshot.h" | 28 #include "snapshot/module_snapshot.h" |
28 | 29 |
29 namespace crashpad { | 30 namespace crashpad { |
30 | 31 |
31 //! \brief The writer for a MINIDUMP_USER_STREAM in a minidump file. | 32 //! \brief The writer for a MINIDUMP_USER_STREAM in a minidump file. |
32 class MinidumpUserStreamWriter final : public internal::MinidumpStreamWriter { | 33 class MinidumpUserStreamWriter final : public internal::MinidumpStreamWriter { |
33 public: | 34 public: |
34 MinidumpUserStreamWriter(); | 35 MinidumpUserStreamWriter(); |
35 ~MinidumpUserStreamWriter() override; | 36 ~MinidumpUserStreamWriter() override; |
36 | 37 |
37 //! \brief Initializes a MINIDUMP_USER_STREAM based on \a stream. | 38 //! \brief Initializes a MINIDUMP_USER_STREAM based on \a stream. |
38 //! | 39 //! |
39 //! \param[in] stream The memory and stream type to use as source data. | 40 //! \param[in] stream The memory and stream type to use as source data. |
40 //! | 41 //! |
41 //! \note Valid in #kStateMutable. | 42 //! \note Valid in #kStateMutable. |
42 void InitializeFromSnapshot(const UserMinidumpStream* stream); | 43 void InitializeFromSnapshot(const UserMinidumpStream* stream); |
43 | 44 |
| 45 //! \brief Initializes a MINIDUMP_USER_STREAM based on \a stream_type, |
| 46 //! \a buffer and \a buffer_size. |
| 47 //! |
| 48 //! \param[in] stream_type The type of the stream. |
| 49 //! \param[in] buffer The data for the stream. |
| 50 //! \param[in] buffer_size The length of \a buffer, and the resulting stream. |
| 51 //! |
| 52 //! \note Valid in #kStateMutable. |
| 53 void InitializeFromBuffer(MinidumpStreamType stream_type, |
| 54 const void* buffer, |
| 55 size_t buffer_size); |
| 56 |
44 protected: | 57 protected: |
45 // MinidumpWritable: | 58 // MinidumpWritable: |
46 bool Freeze() override; | 59 bool Freeze() override; |
47 size_t SizeOfObject() override; | 60 size_t SizeOfObject() override; |
48 std::vector<internal::MinidumpWritable*> Children() override; | 61 std::vector<internal::MinidumpWritable*> Children() override; |
49 bool WriteObject(FileWriterInterface* file_writer) override; | 62 bool WriteObject(FileWriterInterface* file_writer) override; |
50 | 63 |
51 // MinidumpStreamWriter: | 64 // MinidumpStreamWriter: |
52 MinidumpStreamType StreamType() const override; | 65 MinidumpStreamType StreamType() const override; |
53 | 66 |
54 private: | 67 private: |
55 class MemoryReader : public MemorySnapshot::Delegate { | 68 class ContentsWriter; |
56 public: | 69 class SnapshotContentsWriter; |
57 ~MemoryReader() override; | 70 class BufferContentsWriter; |
58 bool MemorySnapshotDelegateRead(void* data, size_t size) override; | |
59 | 71 |
60 const void* data() const { | 72 std::unique_ptr<ContentsWriter> contents_writer_; |
61 return reinterpret_cast<const void*>(data_.data()); | |
62 } | |
63 size_t size() const { return data_.size(); } | |
64 | 73 |
65 private: | 74 MinidumpStreamType stream_type_; |
66 std::vector<uint8_t> data_; | |
67 }; | |
68 | |
69 uint32_t stream_type_; | |
70 MemoryReader reader_; | |
71 | 75 |
72 DISALLOW_COPY_AND_ASSIGN(MinidumpUserStreamWriter); | 76 DISALLOW_COPY_AND_ASSIGN(MinidumpUserStreamWriter); |
73 }; | 77 }; |
74 | 78 |
75 } // namespace crashpad | 79 } // namespace crashpad |
76 | 80 |
77 #endif // CRASHPAD_MINIDUMP_MINIDUMP_USER_STREAM_WRITER_H_ | 81 #endif // CRASHPAD_MINIDUMP_MINIDUMP_USER_STREAM_WRITER_H_ |
OLD | NEW |