Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1402)

Side by Side Diff: minidump/minidump_module_crashpad_info_writer.cc

Issue 707543002: MinidumpLocationDescriptorListWriter (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 bool MinidumpModuleCrashpadInfoWriter::WriteObject( 100 bool MinidumpModuleCrashpadInfoWriter::WriteObject(
101 FileWriterInterface* file_writer) { 101 FileWriterInterface* file_writer) {
102 DCHECK_EQ(state(), kStateWritable); 102 DCHECK_EQ(state(), kStateWritable);
103 103
104 return file_writer->Write(&module_, sizeof(module_)); 104 return file_writer->Write(&module_, sizeof(module_));
105 } 105 }
106 106
107 MinidumpModuleCrashpadInfoListWriter::MinidumpModuleCrashpadInfoListWriter() 107 MinidumpModuleCrashpadInfoListWriter::MinidumpModuleCrashpadInfoListWriter()
108 : MinidumpWritable(), 108 : MinidumpLocationDescriptorListWriter() {
109 module_list_base_(),
110 modules_(),
111 module_location_descriptors_() {
112 } 109 }
113 110
114 MinidumpModuleCrashpadInfoListWriter::~MinidumpModuleCrashpadInfoListWriter() { 111 MinidumpModuleCrashpadInfoListWriter::~MinidumpModuleCrashpadInfoListWriter() {
115 } 112 }
116 113
117 void MinidumpModuleCrashpadInfoListWriter::InitializeFromSnapshot( 114 void MinidumpModuleCrashpadInfoListWriter::InitializeFromSnapshot(
118 const std::vector<const ModuleSnapshot*>& module_snapshots) { 115 const std::vector<const ModuleSnapshot*>& module_snapshots) {
119 DCHECK_EQ(state(), kStateMutable); 116 DCHECK_EQ(state(), kStateMutable);
120 DCHECK(modules_.empty()); 117 DCHECK(children().empty());
121 DCHECK(module_location_descriptors_.empty()); 118 DCHECK(child_location_descriptors().empty());
122 119
123 size_t count = module_snapshots.size(); 120 size_t count = module_snapshots.size();
124 for (size_t index = 0; index < count; ++index) { 121 for (size_t index = 0; index < count; ++index) {
125 const ModuleSnapshot* module_snapshot = module_snapshots[index]; 122 const ModuleSnapshot* module_snapshot = module_snapshots[index];
126 123
127 auto module = make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter()); 124 auto module = make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter());
128 module->InitializeFromSnapshot(module_snapshot, index); 125 module->InitializeFromSnapshot(module_snapshot, index);
129 if (module->IsUseful()) { 126 if (module->IsUseful()) {
130 AddModule(module.Pass()); 127 AddModule(module.Pass());
131 } 128 }
132 } 129 }
133 } 130 }
134 131
135 void MinidumpModuleCrashpadInfoListWriter::AddModule( 132 void MinidumpModuleCrashpadInfoListWriter::AddModule(
136 scoped_ptr<MinidumpModuleCrashpadInfoWriter> module) { 133 scoped_ptr<MinidumpModuleCrashpadInfoWriter> module) {
137 DCHECK_EQ(state(), kStateMutable); 134 DCHECK_EQ(state(), kStateMutable);
138 135
139 modules_.push_back(module.release()); 136 AddChild(module.Pass());
140 }
141
142 bool MinidumpModuleCrashpadInfoListWriter::Freeze() {
143 DCHECK_EQ(state(), kStateMutable);
144 DCHECK(module_location_descriptors_.empty());
145
146 if (!MinidumpWritable::Freeze()) {
147 return false;
148 }
149
150 size_t module_count = modules_.size();
151 if (!AssignIfInRange(&module_list_base_.count, module_count)) {
152 LOG(ERROR) << "module_count " << module_count << " out of range";
153 return false;
154 }
155
156 module_location_descriptors_.resize(module_count);
157 for (size_t index = 0; index < module_count; ++index) {
158 modules_[index]->RegisterLocationDescriptor(
159 &module_location_descriptors_[index]);
160 }
161
162 return true;
163 }
164
165 size_t MinidumpModuleCrashpadInfoListWriter::SizeOfObject() {
166 DCHECK_GE(state(), kStateFrozen);
167
168 return sizeof(module_list_base_) +
169 modules_.size() * sizeof(MINIDUMP_LOCATION_DESCRIPTOR);
170 }
171
172 std::vector<internal::MinidumpWritable*>
173 MinidumpModuleCrashpadInfoListWriter::Children() {
174 DCHECK_GE(state(), kStateFrozen);
175
176 std::vector<MinidumpWritable*> children;
177 for (MinidumpModuleCrashpadInfoWriter* module : modules_) {
178 children.push_back(module);
179 }
180
181 return children;
182 }
183
184 bool MinidumpModuleCrashpadInfoListWriter::WriteObject(
185 FileWriterInterface* file_writer) {
186 DCHECK_EQ(state(), kStateWritable);
187 DCHECK_EQ(modules_.size(), module_location_descriptors_.size());
188
189 WritableIoVec iov;
190 iov.iov_base = &module_list_base_;
191 iov.iov_len = sizeof(module_list_base_);
192 std::vector<WritableIoVec> iovecs(1, iov);
193
194 if (!module_location_descriptors_.empty()) {
195 iov.iov_base = &module_location_descriptors_[0];
196 iov.iov_len = module_location_descriptors_.size() *
197 sizeof(MINIDUMP_LOCATION_DESCRIPTOR);
198 iovecs.push_back(iov);
199 }
200
201 return file_writer->WriteIoVec(&iovecs);
202 } 137 }
203 138
204 } // namespace crashpad 139 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698