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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_rva_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 MinidumpRVAListWriter::MinidumpRVAListWriter()
24 : MinidumpWritable(),
25 rva_list_base_(),
26 children_(),
27 child_rvas_() {
28 }
29
30 MinidumpRVAListWriter::~MinidumpRVAListWriter() {
31 }
32
33 void MinidumpRVAListWriter::AddChild(
34 scoped_ptr<internal::MinidumpWritable> child) {
35 DCHECK_EQ(state(), kStateMutable);
36
37 children_.push_back(child.release());
38 }
39
40 bool MinidumpRVAListWriter::Freeze() {
41 DCHECK_EQ(state(), kStateMutable);
42 DCHECK(child_rvas_.empty());
43
44 if (!MinidumpWritable::Freeze()) {
45 return false;
46 }
47
48 size_t child_count = children_.size();
49 if (!AssignIfInRange(&rva_list_base_.count, child_count)) {
50 LOG(ERROR) << "child_count " << child_count << " out of range";
51 return false;
52 }
53
54 child_rvas_.resize(child_count);
55 for (size_t index = 0; index < child_count; ++index) {
56 children_[index]->RegisterRVA(&child_rvas_[index]);
57 }
58
59 return true;
60 }
61
62 size_t MinidumpRVAListWriter::SizeOfObject() {
63 DCHECK_GE(state(), kStateFrozen);
64
65 return sizeof(rva_list_base_) + children_.size() * sizeof(RVA);
66 }
67
68 std::vector<internal::MinidumpWritable*> MinidumpRVAListWriter::Children() {
69 DCHECK_GE(state(), kStateFrozen);
70
71 std::vector<MinidumpWritable*> children;
72 for (MinidumpWritable* child : children_) {
73 children.push_back(child);
74 }
75
76 return children;
77 }
78
79 bool MinidumpRVAListWriter::WriteObject(FileWriterInterface* file_writer) {
80 DCHECK_EQ(state(), kStateWritable);
81 DCHECK_EQ(children_.size(), child_rvas_.size());
82
83 WritableIoVec iov;
84 iov.iov_base = &rva_list_base_;
85 iov.iov_len = sizeof(rva_list_base_);
86 std::vector<WritableIoVec> iovecs(1, iov);
87
88 if (!child_rvas_.empty()) {
89 iov.iov_base = &child_rvas_[0];
90 iov.iov_len = child_rvas_.size() * sizeof(RVA);
91 iovecs.push_back(iov);
92 }
93
94 return file_writer->WriteIoVec(&iovecs);
95 }
96
97 } // namespace crashpad
OLDNEW
« 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