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

Side by Side Diff: minidump/minidump_crashpad_module_writer.cc

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

Powered by Google App Engine
This is Rietveld 408576698