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, |
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 #include "minidump/minidump_memory_writer.h" | 15 #include "minidump/minidump_memory_writer.h" |
16 | 16 |
| 17 #include "base/auto_reset.h" |
17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "snapshot/memory_snapshot.h" |
18 #include "util/file/file_writer.h" | 20 #include "util/file/file_writer.h" |
19 #include "util/numeric/safe_assignment.h" | 21 #include "util/numeric/safe_assignment.h" |
20 | 22 |
21 namespace crashpad { | 23 namespace crashpad { |
| 24 namespace { |
| 25 |
| 26 class SnapshotMinidumpMemoryWriter final : public MinidumpMemoryWriter, |
| 27 public MemorySnapshot::Delegate { |
| 28 public: |
| 29 explicit SnapshotMinidumpMemoryWriter(const MemorySnapshot* memory_snapshot) |
| 30 : MinidumpMemoryWriter(), |
| 31 MemorySnapshot::Delegate(), |
| 32 memory_snapshot_(memory_snapshot), |
| 33 file_writer_(nullptr) { |
| 34 } |
| 35 |
| 36 ~SnapshotMinidumpMemoryWriter() override {} |
| 37 |
| 38 // MemorySnapshot::Delegate: |
| 39 |
| 40 bool MemorySnapshotDelegateRead(void* data, size_t size) override { |
| 41 DCHECK_EQ(state(), kStateWritable); |
| 42 DCHECK_EQ(size, MemoryRangeSize()); |
| 43 return file_writer_->Write(data, size); |
| 44 } |
| 45 |
| 46 protected: |
| 47 // MinidumpMemoryWriter: |
| 48 |
| 49 bool WriteObject(FileWriterInterface* file_writer) override { |
| 50 DCHECK_EQ(state(), kStateWritable); |
| 51 DCHECK(!file_writer_); |
| 52 |
| 53 base::AutoReset<FileWriterInterface*> file_writer_reset(&file_writer_, |
| 54 file_writer); |
| 55 |
| 56 // This will result in MemorySnapshotDelegateRead() being called. |
| 57 return memory_snapshot_->Read(this); |
| 58 } |
| 59 |
| 60 uint64_t MemoryRangeBaseAddress() const override { |
| 61 DCHECK_EQ(state(), kStateFrozen); |
| 62 return memory_snapshot_->Address(); |
| 63 } |
| 64 |
| 65 size_t MemoryRangeSize() const override { |
| 66 DCHECK_GE(state(), kStateFrozen); |
| 67 return memory_snapshot_->Size(); |
| 68 } |
| 69 |
| 70 private: |
| 71 const MemorySnapshot* memory_snapshot_; |
| 72 FileWriterInterface* file_writer_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(SnapshotMinidumpMemoryWriter); |
| 75 }; |
| 76 |
| 77 } // namespace |
22 | 78 |
23 MinidumpMemoryWriter::~MinidumpMemoryWriter() { | 79 MinidumpMemoryWriter::~MinidumpMemoryWriter() { |
24 } | 80 } |
25 | 81 |
| 82 scoped_ptr<MinidumpMemoryWriter> MinidumpMemoryWriter::CreateFromSnapshot( |
| 83 const MemorySnapshot* memory_snapshot) { |
| 84 return make_scoped_ptr(new SnapshotMinidumpMemoryWriter(memory_snapshot)); |
| 85 } |
| 86 |
26 const MINIDUMP_MEMORY_DESCRIPTOR* | 87 const MINIDUMP_MEMORY_DESCRIPTOR* |
27 MinidumpMemoryWriter::MinidumpMemoryDescriptor() const { | 88 MinidumpMemoryWriter::MinidumpMemoryDescriptor() const { |
28 DCHECK_EQ(state(), kStateWritable); | 89 DCHECK_EQ(state(), kStateWritable); |
29 | 90 |
30 return &memory_descriptor_; | 91 return &memory_descriptor_; |
31 } | 92 } |
32 | 93 |
33 void MinidumpMemoryWriter::RegisterMemoryDescriptor( | 94 void MinidumpMemoryWriter::RegisterMemoryDescriptor( |
34 MINIDUMP_MEMORY_DESCRIPTOR* memory_descriptor) { | 95 MINIDUMP_MEMORY_DESCRIPTOR* memory_descriptor) { |
35 DCHECK_LE(state(), kStateFrozen); | 96 DCHECK_LE(state(), kStateFrozen); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 MinidumpMemoryListWriter::MinidumpMemoryListWriter() | 163 MinidumpMemoryListWriter::MinidumpMemoryListWriter() |
103 : MinidumpStreamWriter(), | 164 : MinidumpStreamWriter(), |
104 memory_list_base_(), | 165 memory_list_base_(), |
105 memory_writers_(), | 166 memory_writers_(), |
106 children_() { | 167 children_() { |
107 } | 168 } |
108 | 169 |
109 MinidumpMemoryListWriter::~MinidumpMemoryListWriter() { | 170 MinidumpMemoryListWriter::~MinidumpMemoryListWriter() { |
110 } | 171 } |
111 | 172 |
| 173 void MinidumpMemoryListWriter::AddFromSnapshot( |
| 174 const std::vector<const MemorySnapshot*>& memory_snapshots) { |
| 175 DCHECK_EQ(state(), kStateMutable); |
| 176 |
| 177 for (const MemorySnapshot* memory_snapshot : memory_snapshots) { |
| 178 scoped_ptr<MinidumpMemoryWriter> memory = |
| 179 MinidumpMemoryWriter::CreateFromSnapshot(memory_snapshot); |
| 180 AddMemory(memory.Pass()); |
| 181 } |
| 182 } |
| 183 |
112 void MinidumpMemoryListWriter::AddMemory( | 184 void MinidumpMemoryListWriter::AddMemory( |
113 scoped_ptr<MinidumpMemoryWriter> memory_writer) { | 185 scoped_ptr<MinidumpMemoryWriter> memory_writer) { |
114 DCHECK_EQ(state(), kStateMutable); | 186 DCHECK_EQ(state(), kStateMutable); |
115 | 187 |
116 AddExtraMemory(memory_writer.get()); | 188 AddExtraMemory(memory_writer.get()); |
117 children_.push_back(memory_writer.release()); | 189 children_.push_back(memory_writer.release()); |
118 } | 190 } |
119 | 191 |
120 void MinidumpMemoryListWriter::AddExtraMemory( | 192 void MinidumpMemoryListWriter::AddExtraMemory( |
121 MinidumpMemoryWriter* memory_writer) { | 193 MinidumpMemoryWriter* memory_writer) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 251 } |
180 | 252 |
181 return file_writer->WriteIoVec(&iovecs); | 253 return file_writer->WriteIoVec(&iovecs); |
182 } | 254 } |
183 | 255 |
184 MinidumpStreamType MinidumpMemoryListWriter::StreamType() const { | 256 MinidumpStreamType MinidumpMemoryListWriter::StreamType() const { |
185 return kMinidumpStreamTypeMemoryList; | 257 return kMinidumpStreamTypeMemoryList; |
186 } | 258 } |
187 | 259 |
188 } // namespace crashpad | 260 } // namespace crashpad |
OLD | NEW |