OLD | NEW |
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 "snapshot/module_snapshot.h" |
22 #include "util/file/file_writer.h" | 22 #include "util/file/file_writer.h" |
23 #include "util/numeric/safe_assignment.h" | 23 #include "util/numeric/safe_assignment.h" |
24 | 24 |
25 namespace crashpad { | 25 namespace crashpad { |
26 | 26 |
27 MinidumpModuleCrashpadInfoWriter::MinidumpModuleCrashpadInfoWriter() | 27 MinidumpModuleCrashpadInfoWriter::MinidumpModuleCrashpadInfoWriter() |
28 : MinidumpWritable(), module_(), simple_annotations_() { | 28 : MinidumpWritable(), |
| 29 module_(), |
| 30 list_annotations_(), |
| 31 simple_annotations_() { |
29 module_.version = MinidumpModuleCrashpadInfo::kVersion; | 32 module_.version = MinidumpModuleCrashpadInfo::kVersion; |
30 } | 33 } |
31 | 34 |
32 MinidumpModuleCrashpadInfoWriter::~MinidumpModuleCrashpadInfoWriter() { | 35 MinidumpModuleCrashpadInfoWriter::~MinidumpModuleCrashpadInfoWriter() { |
33 } | 36 } |
34 | 37 |
35 void MinidumpModuleCrashpadInfoWriter::InitializeFromSnapshot( | 38 void MinidumpModuleCrashpadInfoWriter::InitializeFromSnapshot( |
36 const ModuleSnapshot* module_snapshot, size_t module_list_index) { | 39 const ModuleSnapshot* module_snapshot, size_t module_list_index) { |
37 DCHECK_EQ(state(), kStateMutable); | 40 DCHECK_EQ(state(), kStateMutable); |
| 41 DCHECK(!list_annotations_); |
38 DCHECK(!simple_annotations_); | 42 DCHECK(!simple_annotations_); |
39 | 43 |
40 uint32_t module_list_index_u32; | 44 uint32_t module_list_index_u32; |
41 if (!AssignIfInRange(&module_list_index_u32, module_list_index)) { | 45 if (!AssignIfInRange(&module_list_index_u32, module_list_index)) { |
42 LOG(ERROR) << "module_list_index " << module_list_index << " out of range"; | 46 LOG(ERROR) << "module_list_index " << module_list_index << " out of range"; |
43 return; | 47 return; |
44 } | 48 } |
45 SetMinidumpModuleListIndex(module_list_index_u32); | 49 SetMinidumpModuleListIndex(module_list_index_u32); |
46 | 50 |
| 51 auto list_annotations = |
| 52 make_scoped_ptr(new internal::MinidumpUTF8StringListWriter()); |
| 53 list_annotations->InitializeFromVector(module_snapshot->AnnotationsVector()); |
| 54 if (list_annotations->IsUseful()) { |
| 55 SetListAnnotations(list_annotations.Pass()); |
| 56 } |
| 57 |
47 auto simple_annotations = | 58 auto simple_annotations = |
48 make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter()); | 59 make_scoped_ptr(new MinidumpSimpleStringDictionaryWriter()); |
49 simple_annotations->InitializeFromMap( | 60 simple_annotations->InitializeFromMap( |
50 module_snapshot->AnnotationsSimpleMap()); | 61 module_snapshot->AnnotationsSimpleMap()); |
51 if (simple_annotations->IsUseful()) { | 62 if (simple_annotations->IsUseful()) { |
52 SetSimpleAnnotations(simple_annotations.Pass()); | 63 SetSimpleAnnotations(simple_annotations.Pass()); |
53 } | 64 } |
54 } | 65 } |
55 | 66 |
| 67 void MinidumpModuleCrashpadInfoWriter::SetListAnnotations( |
| 68 scoped_ptr<internal::MinidumpUTF8StringListWriter> list_annotations) { |
| 69 DCHECK_EQ(state(), kStateMutable); |
| 70 |
| 71 list_annotations_ = list_annotations.Pass(); |
| 72 } |
| 73 |
56 void MinidumpModuleCrashpadInfoWriter::SetSimpleAnnotations( | 74 void MinidumpModuleCrashpadInfoWriter::SetSimpleAnnotations( |
57 scoped_ptr<MinidumpSimpleStringDictionaryWriter> simple_annotations) { | 75 scoped_ptr<MinidumpSimpleStringDictionaryWriter> simple_annotations) { |
58 DCHECK_EQ(state(), kStateMutable); | 76 DCHECK_EQ(state(), kStateMutable); |
59 | 77 |
60 simple_annotations_ = simple_annotations.Pass(); | 78 simple_annotations_ = simple_annotations.Pass(); |
61 } | 79 } |
62 | 80 |
63 bool MinidumpModuleCrashpadInfoWriter::IsUseful() const { | 81 bool MinidumpModuleCrashpadInfoWriter::IsUseful() const { |
64 return simple_annotations_; | 82 return list_annotations_ || simple_annotations_; |
65 } | 83 } |
66 | 84 |
67 bool MinidumpModuleCrashpadInfoWriter::Freeze() { | 85 bool MinidumpModuleCrashpadInfoWriter::Freeze() { |
68 DCHECK_EQ(state(), kStateMutable); | 86 DCHECK_EQ(state(), kStateMutable); |
69 | 87 |
70 if (!MinidumpWritable::Freeze()) { | 88 if (!MinidumpWritable::Freeze()) { |
71 return false; | 89 return false; |
72 } | 90 } |
73 | 91 |
| 92 if (list_annotations_) { |
| 93 list_annotations_->RegisterLocationDescriptor(&module_.list_annotations); |
| 94 } |
| 95 |
74 if (simple_annotations_) { | 96 if (simple_annotations_) { |
75 simple_annotations_->RegisterLocationDescriptor( | 97 simple_annotations_->RegisterLocationDescriptor( |
76 &module_.simple_annotations); | 98 &module_.simple_annotations); |
77 } | 99 } |
78 | 100 |
79 return true; | 101 return true; |
80 } | 102 } |
81 | 103 |
82 size_t MinidumpModuleCrashpadInfoWriter::SizeOfObject() { | 104 size_t MinidumpModuleCrashpadInfoWriter::SizeOfObject() { |
83 DCHECK_GE(state(), kStateFrozen); | 105 DCHECK_GE(state(), kStateFrozen); |
84 | 106 |
85 return sizeof(module_); | 107 return sizeof(module_); |
86 } | 108 } |
87 | 109 |
88 std::vector<internal::MinidumpWritable*> | 110 std::vector<internal::MinidumpWritable*> |
89 MinidumpModuleCrashpadInfoWriter::Children() { | 111 MinidumpModuleCrashpadInfoWriter::Children() { |
90 DCHECK_GE(state(), kStateFrozen); | 112 DCHECK_GE(state(), kStateFrozen); |
91 | 113 |
92 std::vector<MinidumpWritable*> children; | 114 std::vector<MinidumpWritable*> children; |
| 115 if (list_annotations_) { |
| 116 children.push_back(list_annotations_.get()); |
| 117 } |
93 if (simple_annotations_) { | 118 if (simple_annotations_) { |
94 children.push_back(simple_annotations_.get()); | 119 children.push_back(simple_annotations_.get()); |
95 } | 120 } |
96 | 121 |
97 return children; | 122 return children; |
98 } | 123 } |
99 | 124 |
100 bool MinidumpModuleCrashpadInfoWriter::WriteObject( | 125 bool MinidumpModuleCrashpadInfoWriter::WriteObject( |
101 FileWriterInterface* file_writer) { | 126 FileWriterInterface* file_writer) { |
102 DCHECK_EQ(state(), kStateWritable); | 127 DCHECK_EQ(state(), kStateWritable); |
(...skipping 27 matching lines...) Expand all Loading... |
130 } | 155 } |
131 | 156 |
132 void MinidumpModuleCrashpadInfoListWriter::AddModule( | 157 void MinidumpModuleCrashpadInfoListWriter::AddModule( |
133 scoped_ptr<MinidumpModuleCrashpadInfoWriter> module) { | 158 scoped_ptr<MinidumpModuleCrashpadInfoWriter> module) { |
134 DCHECK_EQ(state(), kStateMutable); | 159 DCHECK_EQ(state(), kStateMutable); |
135 | 160 |
136 AddChild(module.Pass()); | 161 AddChild(module.Pass()); |
137 } | 162 } |
138 | 163 |
139 } // namespace crashpad | 164 } // namespace crashpad |
OLD | NEW |