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

Side by Side Diff: minidump/minidump_module_crashpad_info_writer.cc

Issue 683143003: minidump: Add InitializeFromSnapshot() for MinidumpModuleCrashpadInfoListWriter and downstream (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback 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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "minidump/minidump_module_crashpad_info_writer.h" 15 #include "minidump/minidump_module_crashpad_info_writer.h"
16 16
17 #include <sys/types.h> 17 #include <sys/types.h>
18 18
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "minidump/minidump_simple_string_dictionary_writer.h" 20 #include "minidump/minidump_simple_string_dictionary_writer.h"
21 #include "snapshot/module_snapshot.h"
21 #include "util/file/file_writer.h" 22 #include "util/file/file_writer.h"
22 #include "util/numeric/safe_assignment.h" 23 #include "util/numeric/safe_assignment.h"
23 24
24 namespace crashpad { 25 namespace crashpad {
25 26
26 MinidumpModuleCrashpadInfoWriter::MinidumpModuleCrashpadInfoWriter() 27 MinidumpModuleCrashpadInfoWriter::MinidumpModuleCrashpadInfoWriter()
27 : MinidumpWritable(), module_(), simple_annotations_() { 28 : MinidumpWritable(), module_(), simple_annotations_() {
28 module_.version = MinidumpModuleCrashpadInfo::kVersion; 29 module_.version = MinidumpModuleCrashpadInfo::kVersion;
29 } 30 }
30 31
31 MinidumpModuleCrashpadInfoWriter::~MinidumpModuleCrashpadInfoWriter() { 32 MinidumpModuleCrashpadInfoWriter::~MinidumpModuleCrashpadInfoWriter() {
32 } 33 }
33 34
35 void MinidumpModuleCrashpadInfoWriter::InitializeFromSnapshot(
36 const ModuleSnapshot* module_snapshot, size_t module_list_index) {
37 DCHECK_EQ(state(), kStateMutable);
38 DCHECK(!simple_annotations_);
39
40 uint32_t module_list_index_u32;
41 if (!AssignIfInRange(&module_list_index_u32, module_list_index)) {
42 LOG(ERROR) << "module_list_index " << module_list_index << " out of range";
43 return;
44 }
45 SetMinidumpModuleListIndex(module_list_index_u32);
46
47 auto simple_annotations =
48 make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter());
49 simple_annotations->InitializeFromMap(
50 module_snapshot->AnnotationsSimpleMap());
51 if (simple_annotations->IsUseful()) {
52 SetSimpleAnnotations(simple_annotations.Pass());
53 }
54 }
55
34 void MinidumpModuleCrashpadInfoWriter::SetSimpleAnnotations( 56 void MinidumpModuleCrashpadInfoWriter::SetSimpleAnnotations(
35 scoped_ptr<MinidumpSimpleStringDictionaryWriter> simple_annotations) { 57 scoped_ptr<MinidumpSimpleStringDictionaryWriter> simple_annotations) {
36 DCHECK_EQ(state(), kStateMutable); 58 DCHECK_EQ(state(), kStateMutable);
37 59
38 simple_annotations_ = simple_annotations.Pass(); 60 simple_annotations_ = simple_annotations.Pass();
39 } 61 }
40 62
63 bool MinidumpModuleCrashpadInfoWriter::IsUseful() const {
64 return simple_annotations_;
65 }
66
41 bool MinidumpModuleCrashpadInfoWriter::Freeze() { 67 bool MinidumpModuleCrashpadInfoWriter::Freeze() {
42 DCHECK_EQ(state(), kStateMutable); 68 DCHECK_EQ(state(), kStateMutable);
43 69
44 if (!MinidumpWritable::Freeze()) { 70 if (!MinidumpWritable::Freeze()) {
45 return false; 71 return false;
46 } 72 }
47 73
48 if (simple_annotations_) { 74 if (simple_annotations_) {
49 simple_annotations_->RegisterLocationDescriptor( 75 simple_annotations_->RegisterLocationDescriptor(
50 &module_.simple_annotations); 76 &module_.simple_annotations);
(...skipping 30 matching lines...) Expand all
81 MinidumpModuleCrashpadInfoListWriter::MinidumpModuleCrashpadInfoListWriter() 107 MinidumpModuleCrashpadInfoListWriter::MinidumpModuleCrashpadInfoListWriter()
82 : MinidumpWritable(), 108 : MinidumpWritable(),
83 module_list_base_(), 109 module_list_base_(),
84 modules_(), 110 modules_(),
85 module_location_descriptors_() { 111 module_location_descriptors_() {
86 } 112 }
87 113
88 MinidumpModuleCrashpadInfoListWriter::~MinidumpModuleCrashpadInfoListWriter() { 114 MinidumpModuleCrashpadInfoListWriter::~MinidumpModuleCrashpadInfoListWriter() {
89 } 115 }
90 116
117 void MinidumpModuleCrashpadInfoListWriter::InitializeFromSnapshot(
118 const std::vector<const ModuleSnapshot*>& module_snapshots) {
119 DCHECK_EQ(state(), kStateMutable);
120 DCHECK(modules_.empty());
121 DCHECK(module_location_descriptors_.empty());
122
123 size_t count = module_snapshots.size();
124 for (size_t index = 0; index < count; ++index) {
125 const ModuleSnapshot* module_snapshot = module_snapshots[index];
126
127 auto module = make_scoped_ptr(new MinidumpModuleCrashpadInfoWriter());
128 module->InitializeFromSnapshot(module_snapshot, index);
129 if (module->IsUseful()) {
130 AddModule(module.Pass());
131 }
132 }
133 }
134
91 void MinidumpModuleCrashpadInfoListWriter::AddModule( 135 void MinidumpModuleCrashpadInfoListWriter::AddModule(
92 scoped_ptr<MinidumpModuleCrashpadInfoWriter> module) { 136 scoped_ptr<MinidumpModuleCrashpadInfoWriter> module) {
93 DCHECK_EQ(state(), kStateMutable); 137 DCHECK_EQ(state(), kStateMutable);
94 138
95 modules_.push_back(module.release()); 139 modules_.push_back(module.release());
96 } 140 }
97 141
98 bool MinidumpModuleCrashpadInfoListWriter::Freeze() { 142 bool MinidumpModuleCrashpadInfoListWriter::Freeze() {
99 DCHECK_EQ(state(), kStateMutable); 143 DCHECK_EQ(state(), kStateMutable);
100 DCHECK(module_location_descriptors_.empty()); 144 DCHECK(module_location_descriptors_.empty());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 iov.iov_base = &module_location_descriptors_[0]; 195 iov.iov_base = &module_location_descriptors_[0];
152 iov.iov_len = module_location_descriptors_.size() * 196 iov.iov_len = module_location_descriptors_.size() *
153 sizeof(MINIDUMP_LOCATION_DESCRIPTOR); 197 sizeof(MINIDUMP_LOCATION_DESCRIPTOR);
154 iovecs.push_back(iov); 198 iovecs.push_back(iov);
155 } 199 }
156 200
157 return file_writer->WriteIoVec(&iovecs); 201 return file_writer->WriteIoVec(&iovecs);
158 } 202 }
159 203
160 } // namespace crashpad 204 } // namespace crashpad
OLDNEW
« no previous file with comments | « minidump/minidump_module_crashpad_info_writer.h ('k') | minidump/minidump_module_crashpad_info_writer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698