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

Unified Diff: minidump/minidump_rva_list_writer.cc

Issue 704333002: Add MinidumpRVAListWriter and test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@minidump_location_descriptor_list
Patch Set: Rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « minidump/minidump_rva_list_writer.h ('k') | minidump/minidump_rva_list_writer_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: minidump/minidump_rva_list_writer.cc
diff --git a/minidump/minidump_rva_list_writer.cc b/minidump/minidump_rva_list_writer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..af4f5824069d69b7b480d75cb7c2b91122f1ca12
--- /dev/null
+++ b/minidump/minidump_rva_list_writer.cc
@@ -0,0 +1,97 @@
+// Copyright 2014 The Crashpad Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "minidump/minidump_rva_list_writer.h"
+
+#include "base/logging.h"
+#include "util/file/file_writer.h"
+#include "util/numeric/safe_assignment.h"
+
+namespace crashpad {
+
+MinidumpRVAListWriter::MinidumpRVAListWriter()
+ : MinidumpWritable(),
+ rva_list_base_(),
+ children_(),
+ child_rvas_() {
+}
+
+MinidumpRVAListWriter::~MinidumpRVAListWriter() {
+}
+
+void MinidumpRVAListWriter::AddChild(
+ scoped_ptr<internal::MinidumpWritable> child) {
+ DCHECK_EQ(state(), kStateMutable);
+
+ children_.push_back(child.release());
+}
+
+bool MinidumpRVAListWriter::Freeze() {
+ DCHECK_EQ(state(), kStateMutable);
+ DCHECK(child_rvas_.empty());
+
+ if (!MinidumpWritable::Freeze()) {
+ return false;
+ }
+
+ size_t child_count = children_.size();
+ if (!AssignIfInRange(&rva_list_base_.count, child_count)) {
+ LOG(ERROR) << "child_count " << child_count << " out of range";
+ return false;
+ }
+
+ child_rvas_.resize(child_count);
+ for (size_t index = 0; index < child_count; ++index) {
+ children_[index]->RegisterRVA(&child_rvas_[index]);
+ }
+
+ return true;
+}
+
+size_t MinidumpRVAListWriter::SizeOfObject() {
+ DCHECK_GE(state(), kStateFrozen);
+
+ return sizeof(rva_list_base_) + children_.size() * sizeof(RVA);
+}
+
+std::vector<internal::MinidumpWritable*> MinidumpRVAListWriter::Children() {
+ DCHECK_GE(state(), kStateFrozen);
+
+ std::vector<MinidumpWritable*> children;
+ for (MinidumpWritable* child : children_) {
+ children.push_back(child);
+ }
+
+ return children;
+}
+
+bool MinidumpRVAListWriter::WriteObject(FileWriterInterface* file_writer) {
+ DCHECK_EQ(state(), kStateWritable);
+ DCHECK_EQ(children_.size(), child_rvas_.size());
+
+ WritableIoVec iov;
+ iov.iov_base = &rva_list_base_;
+ iov.iov_len = sizeof(rva_list_base_);
+ std::vector<WritableIoVec> iovecs(1, iov);
+
+ if (!child_rvas_.empty()) {
+ iov.iov_base = &child_rvas_[0];
+ iov.iov_len = child_rvas_.size() * sizeof(RVA);
+ iovecs.push_back(iov);
+ }
+
+ return file_writer->WriteIoVec(&iovecs);
+}
+
+} // namespace crashpad
« no previous file with comments | « minidump/minidump_rva_list_writer.h ('k') | minidump/minidump_rva_list_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698