| 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/logging.h" | 17 #include "base/logging.h" |
| 18 #include "util/file/file_writer.h" | 18 #include "util/file/file_writer.h" |
| 19 #include "util/numeric/safe_assignment.h" | 19 #include "util/numeric/safe_assignment.h" |
| 20 | 20 |
| 21 namespace crashpad { | 21 namespace crashpad { |
| 22 | 22 |
| 23 MinidumpMemoryWriter::~MinidumpMemoryWriter() { |
| 24 } |
| 25 |
| 23 const MINIDUMP_MEMORY_DESCRIPTOR* | 26 const MINIDUMP_MEMORY_DESCRIPTOR* |
| 24 MinidumpMemoryWriter::MinidumpMemoryDescriptor() const { | 27 MinidumpMemoryWriter::MinidumpMemoryDescriptor() const { |
| 25 DCHECK_EQ(state(), kStateWritable); | 28 DCHECK_EQ(state(), kStateWritable); |
| 26 | 29 |
| 27 return &memory_descriptor_; | 30 return &memory_descriptor_; |
| 28 } | 31 } |
| 29 | 32 |
| 30 void MinidumpMemoryWriter::RegisterMemoryDescriptor( | 33 void MinidumpMemoryWriter::RegisterMemoryDescriptor( |
| 31 MINIDUMP_MEMORY_DESCRIPTOR* memory_descriptor) { | 34 MINIDUMP_MEMORY_DESCRIPTOR* memory_descriptor) { |
| 32 DCHECK_LE(state(), kStateFrozen); | 35 DCHECK_LE(state(), kStateFrozen); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 MinidumpMemoryListWriter::MinidumpMemoryListWriter() | 102 MinidumpMemoryListWriter::MinidumpMemoryListWriter() |
| 100 : MinidumpStreamWriter(), | 103 : MinidumpStreamWriter(), |
| 101 memory_list_base_(), | 104 memory_list_base_(), |
| 102 memory_writers_(), | 105 memory_writers_(), |
| 103 children_() { | 106 children_() { |
| 104 } | 107 } |
| 105 | 108 |
| 106 MinidumpMemoryListWriter::~MinidumpMemoryListWriter() { | 109 MinidumpMemoryListWriter::~MinidumpMemoryListWriter() { |
| 107 } | 110 } |
| 108 | 111 |
| 109 void MinidumpMemoryListWriter::AddMemory(MinidumpMemoryWriter* memory_writer) { | 112 void MinidumpMemoryListWriter::AddMemory( |
| 113 scoped_ptr<MinidumpMemoryWriter> memory_writer) { |
| 110 DCHECK_EQ(state(), kStateMutable); | 114 DCHECK_EQ(state(), kStateMutable); |
| 111 | 115 |
| 112 children_.push_back(memory_writer); | 116 AddExtraMemory(memory_writer.get()); |
| 113 AddExtraMemory(memory_writer); | 117 children_.push_back(memory_writer.release()); |
| 114 } | 118 } |
| 115 | 119 |
| 116 void MinidumpMemoryListWriter::AddExtraMemory( | 120 void MinidumpMemoryListWriter::AddExtraMemory( |
| 117 MinidumpMemoryWriter* memory_writer) { | 121 MinidumpMemoryWriter* memory_writer) { |
| 118 DCHECK_EQ(state(), kStateMutable); | 122 DCHECK_EQ(state(), kStateMutable); |
| 119 | 123 |
| 120 memory_writers_.push_back(memory_writer); | 124 memory_writers_.push_back(memory_writer); |
| 121 } | 125 } |
| 122 | 126 |
| 123 bool MinidumpMemoryListWriter::Freeze() { | 127 bool MinidumpMemoryListWriter::Freeze() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 145 DCHECK_LE(children_.size(), memory_writers_.size()); | 149 DCHECK_LE(children_.size(), memory_writers_.size()); |
| 146 | 150 |
| 147 return sizeof(memory_list_base_) + | 151 return sizeof(memory_list_base_) + |
| 148 memory_writers_.size() * sizeof(MINIDUMP_MEMORY_DESCRIPTOR); | 152 memory_writers_.size() * sizeof(MINIDUMP_MEMORY_DESCRIPTOR); |
| 149 } | 153 } |
| 150 | 154 |
| 151 std::vector<internal::MinidumpWritable*> MinidumpMemoryListWriter::Children() { | 155 std::vector<internal::MinidumpWritable*> MinidumpMemoryListWriter::Children() { |
| 152 DCHECK_GE(state(), kStateFrozen); | 156 DCHECK_GE(state(), kStateFrozen); |
| 153 DCHECK_LE(children_.size(), memory_writers_.size()); | 157 DCHECK_LE(children_.size(), memory_writers_.size()); |
| 154 | 158 |
| 155 return children_; | 159 std::vector<MinidumpWritable*> children; |
| 160 for (MinidumpMemoryWriter* child : children_) { |
| 161 children.push_back(child); |
| 162 } |
| 163 |
| 164 return children; |
| 156 } | 165 } |
| 157 | 166 |
| 158 bool MinidumpMemoryListWriter::WriteObject(FileWriterInterface* file_writer) { | 167 bool MinidumpMemoryListWriter::WriteObject(FileWriterInterface* file_writer) { |
| 159 DCHECK_EQ(state(), kStateWritable); | 168 DCHECK_EQ(state(), kStateWritable); |
| 160 | 169 |
| 161 WritableIoVec iov; | 170 WritableIoVec iov; |
| 162 iov.iov_base = &memory_list_base_; | 171 iov.iov_base = &memory_list_base_; |
| 163 iov.iov_len = sizeof(memory_list_base_); | 172 iov.iov_len = sizeof(memory_list_base_); |
| 164 std::vector<WritableIoVec> iovecs(1, iov); | 173 std::vector<WritableIoVec> iovecs(1, iov); |
| 165 | 174 |
| 166 for (const MinidumpMemoryWriter* memory_writer : memory_writers_) { | 175 for (const MinidumpMemoryWriter* memory_writer : memory_writers_) { |
| 167 iov.iov_base = memory_writer->MinidumpMemoryDescriptor(); | 176 iov.iov_base = memory_writer->MinidumpMemoryDescriptor(); |
| 168 iov.iov_len = sizeof(MINIDUMP_MEMORY_DESCRIPTOR); | 177 iov.iov_len = sizeof(MINIDUMP_MEMORY_DESCRIPTOR); |
| 169 iovecs.push_back(iov); | 178 iovecs.push_back(iov); |
| 170 } | 179 } |
| 171 | 180 |
| 172 return file_writer->WriteIoVec(&iovecs); | 181 return file_writer->WriteIoVec(&iovecs); |
| 173 } | 182 } |
| 174 | 183 |
| 175 MinidumpStreamType MinidumpMemoryListWriter::StreamType() const { | 184 MinidumpStreamType MinidumpMemoryListWriter::StreamType() const { |
| 176 return kMinidumpStreamTypeMemoryList; | 185 return kMinidumpStreamTypeMemoryList; |
| 177 } | 186 } |
| 178 | 187 |
| 179 } // namespace crashpad | 188 } // namespace crashpad |
| OLD | NEW |