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 #include "minidump/minidump_location_descriptor_list_writer.h" |
| 16 |
| 17 #include "base/logging.h" |
| 18 #include "util/file/file_writer.h" |
| 19 #include "util/numeric/safe_assignment.h" |
| 20 |
| 21 namespace crashpad { |
| 22 |
| 23 MinidumpLocationDescriptorListWriter::MinidumpLocationDescriptorListWriter() |
| 24 : MinidumpWritable(), |
| 25 location_descriptor_list_base_(), |
| 26 children_(), |
| 27 child_location_descriptors_() { |
| 28 } |
| 29 |
| 30 MinidumpLocationDescriptorListWriter::~MinidumpLocationDescriptorListWriter() { |
| 31 } |
| 32 |
| 33 void MinidumpLocationDescriptorListWriter::AddChild( |
| 34 scoped_ptr<internal::MinidumpWritable> child) { |
| 35 DCHECK_EQ(state(), kStateMutable); |
| 36 |
| 37 children_.push_back(child.release()); |
| 38 } |
| 39 |
| 40 bool MinidumpLocationDescriptorListWriter::Freeze() { |
| 41 DCHECK_EQ(state(), kStateMutable); |
| 42 DCHECK(child_location_descriptors_.empty()); |
| 43 |
| 44 if (!MinidumpWritable::Freeze()) { |
| 45 return false; |
| 46 } |
| 47 |
| 48 size_t child_count = children_.size(); |
| 49 if (!AssignIfInRange(&location_descriptor_list_base_.count, child_count)) { |
| 50 LOG(ERROR) << "child_count " << child_count << " out of range"; |
| 51 return false; |
| 52 } |
| 53 |
| 54 child_location_descriptors_.resize(child_count); |
| 55 for (size_t index = 0; index < child_count; ++index) { |
| 56 children_[index]->RegisterLocationDescriptor( |
| 57 &child_location_descriptors_[index]); |
| 58 } |
| 59 |
| 60 return true; |
| 61 } |
| 62 |
| 63 size_t MinidumpLocationDescriptorListWriter::SizeOfObject() { |
| 64 DCHECK_GE(state(), kStateFrozen); |
| 65 |
| 66 return sizeof(location_descriptor_list_base_) + |
| 67 children_.size() * sizeof(MINIDUMP_LOCATION_DESCRIPTOR); |
| 68 } |
| 69 |
| 70 std::vector<internal::MinidumpWritable*> |
| 71 MinidumpLocationDescriptorListWriter::Children() { |
| 72 DCHECK_GE(state(), kStateFrozen); |
| 73 |
| 74 std::vector<MinidumpWritable*> children; |
| 75 for (MinidumpWritable* child : children_) { |
| 76 children.push_back(child); |
| 77 } |
| 78 |
| 79 return children; |
| 80 } |
| 81 |
| 82 bool MinidumpLocationDescriptorListWriter::WriteObject( |
| 83 FileWriterInterface* file_writer) { |
| 84 DCHECK_EQ(state(), kStateWritable); |
| 85 DCHECK_EQ(children_.size(), child_location_descriptors_.size()); |
| 86 |
| 87 WritableIoVec iov; |
| 88 iov.iov_base = &location_descriptor_list_base_; |
| 89 iov.iov_len = sizeof(location_descriptor_list_base_); |
| 90 std::vector<WritableIoVec> iovecs(1, iov); |
| 91 |
| 92 if (!child_location_descriptors_.empty()) { |
| 93 iov.iov_base = &child_location_descriptors_[0]; |
| 94 iov.iov_len = child_location_descriptors_.size() * |
| 95 sizeof(MINIDUMP_LOCATION_DESCRIPTOR); |
| 96 iovecs.push_back(iov); |
| 97 } |
| 98 |
| 99 return file_writer->WriteIoVec(&iovecs); |
| 100 } |
| 101 |
| 102 } // namespace crashpad |
OLD | NEW |