| 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_crashpad_module_writer.h" | |
| 16 | |
| 17 #include <sys/types.h> | |
| 18 | |
| 19 #include "base/logging.h" | |
| 20 #include "minidump/minidump_simple_string_dictionary_writer.h" | |
| 21 #include "util/file/file_writer.h" | |
| 22 #include "util/numeric/safe_assignment.h" | |
| 23 | |
| 24 namespace crashpad { | |
| 25 | |
| 26 MinidumpModuleCrashpadInfoWriter::MinidumpModuleCrashpadInfoWriter() | |
| 27 : MinidumpWritable(), module_(), simple_annotations_() { | |
| 28 module_.version = MinidumpModuleCrashpadInfo::kVersion; | |
| 29 } | |
| 30 | |
| 31 MinidumpModuleCrashpadInfoWriter::~MinidumpModuleCrashpadInfoWriter() { | |
| 32 } | |
| 33 | |
| 34 void MinidumpModuleCrashpadInfoWriter::SetSimpleAnnotations( | |
| 35 MinidumpSimpleStringDictionaryWriter* simple_annotations) { | |
| 36 DCHECK_EQ(state(), kStateMutable); | |
| 37 | |
| 38 simple_annotations_ = simple_annotations; | |
| 39 } | |
| 40 | |
| 41 bool MinidumpModuleCrashpadInfoWriter::Freeze() { | |
| 42 DCHECK_EQ(state(), kStateMutable); | |
| 43 | |
| 44 if (!MinidumpWritable::Freeze()) { | |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 if (simple_annotations_) { | |
| 49 simple_annotations_->RegisterLocationDescriptor( | |
| 50 &module_.simple_annotations); | |
| 51 } | |
| 52 | |
| 53 return true; | |
| 54 } | |
| 55 | |
| 56 size_t MinidumpModuleCrashpadInfoWriter::SizeOfObject() { | |
| 57 DCHECK_GE(state(), kStateFrozen); | |
| 58 | |
| 59 return sizeof(module_); | |
| 60 } | |
| 61 | |
| 62 std::vector<internal::MinidumpWritable*> | |
| 63 MinidumpModuleCrashpadInfoWriter::Children() { | |
| 64 DCHECK_GE(state(), kStateFrozen); | |
| 65 | |
| 66 std::vector<MinidumpWritable*> children; | |
| 67 if (simple_annotations_) { | |
| 68 children.push_back(simple_annotations_); | |
| 69 } | |
| 70 | |
| 71 return children; | |
| 72 } | |
| 73 | |
| 74 bool MinidumpModuleCrashpadInfoWriter::WriteObject( | |
| 75 FileWriterInterface* file_writer) { | |
| 76 DCHECK_EQ(state(), kStateWritable); | |
| 77 | |
| 78 return file_writer->Write(&module_, sizeof(module_)); | |
| 79 } | |
| 80 | |
| 81 MinidumpModuleCrashpadInfoListWriter::MinidumpModuleCrashpadInfoListWriter() | |
| 82 : MinidumpWritable(), | |
| 83 module_list_base_(), | |
| 84 modules_(), | |
| 85 module_location_descriptors_() { | |
| 86 } | |
| 87 | |
| 88 MinidumpModuleCrashpadInfoListWriter::~MinidumpModuleCrashpadInfoListWriter() { | |
| 89 } | |
| 90 | |
| 91 void MinidumpModuleCrashpadInfoListWriter::AddModule( | |
| 92 MinidumpModuleCrashpadInfoWriter* module) { | |
| 93 DCHECK_EQ(state(), kStateMutable); | |
| 94 | |
| 95 modules_.push_back(module); | |
| 96 } | |
| 97 | |
| 98 bool MinidumpModuleCrashpadInfoListWriter::Freeze() { | |
| 99 DCHECK_EQ(state(), kStateMutable); | |
| 100 DCHECK(module_location_descriptors_.empty()); | |
| 101 | |
| 102 if (!MinidumpWritable::Freeze()) { | |
| 103 return false; | |
| 104 } | |
| 105 | |
| 106 size_t module_count = modules_.size(); | |
| 107 if (!AssignIfInRange(&module_list_base_.count, module_count)) { | |
| 108 LOG(ERROR) << "module_count " << module_count << " out of range"; | |
| 109 return false; | |
| 110 } | |
| 111 | |
| 112 module_location_descriptors_.resize(module_count); | |
| 113 for (size_t index = 0; index < module_count; ++index) { | |
| 114 modules_[index]->RegisterLocationDescriptor( | |
| 115 &module_location_descriptors_[index]); | |
| 116 } | |
| 117 | |
| 118 return true; | |
| 119 } | |
| 120 | |
| 121 size_t MinidumpModuleCrashpadInfoListWriter::SizeOfObject() { | |
| 122 DCHECK_GE(state(), kStateFrozen); | |
| 123 | |
| 124 return sizeof(module_list_base_) + | |
| 125 modules_.size() * sizeof(MINIDUMP_LOCATION_DESCRIPTOR); | |
| 126 } | |
| 127 | |
| 128 std::vector<internal::MinidumpWritable*> | |
| 129 MinidumpModuleCrashpadInfoListWriter::Children() { | |
| 130 DCHECK_GE(state(), kStateFrozen); | |
| 131 | |
| 132 std::vector<MinidumpWritable*> children; | |
| 133 for (MinidumpModuleCrashpadInfoWriter* module : modules_) { | |
| 134 children.push_back(module); | |
| 135 } | |
| 136 | |
| 137 return children; | |
| 138 } | |
| 139 | |
| 140 bool MinidumpModuleCrashpadInfoListWriter::WriteObject( | |
| 141 FileWriterInterface* file_writer) { | |
| 142 DCHECK_EQ(state(), kStateWritable); | |
| 143 DCHECK_EQ(modules_.size(), module_location_descriptors_.size()); | |
| 144 | |
| 145 WritableIoVec iov; | |
| 146 iov.iov_base = &module_list_base_; | |
| 147 iov.iov_len = sizeof(module_list_base_); | |
| 148 std::vector<WritableIoVec> iovecs(1, iov); | |
| 149 | |
| 150 if (!module_location_descriptors_.empty()) { | |
| 151 iov.iov_base = &module_location_descriptors_[0]; | |
| 152 iov.iov_len = module_location_descriptors_.size() * | |
| 153 sizeof(MINIDUMP_LOCATION_DESCRIPTOR); | |
| 154 iovecs.push_back(iov); | |
| 155 } | |
| 156 | |
| 157 return file_writer->WriteIoVec(&iovecs); | |
| 158 } | |
| 159 | |
| 160 } // namespace crashpad | |
| OLD | NEW |