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_writer.h" | 15 #include "minidump/minidump_module_writer.h" |
16 | 16 |
17 #include <sys/types.h> | 17 #include <sys/types.h> |
18 | 18 |
| 19 #include <limits> |
| 20 |
19 #include "base/logging.h" | 21 #include "base/logging.h" |
20 #include "minidump/minidump_string_writer.h" | 22 #include "minidump/minidump_string_writer.h" |
21 #include "minidump/minidump_writer_util.h" | 23 #include "minidump/minidump_writer_util.h" |
| 24 #include "snapshot/module_snapshot.h" |
22 #include "util/file/file_writer.h" | 25 #include "util/file/file_writer.h" |
| 26 #include "util/numeric/in_range_cast.h" |
23 #include "util/numeric/safe_assignment.h" | 27 #include "util/numeric/safe_assignment.h" |
24 | 28 |
25 namespace crashpad { | 29 namespace crashpad { |
26 | 30 |
27 MinidumpModuleCodeViewRecordWriter::~MinidumpModuleCodeViewRecordWriter() { | 31 MinidumpModuleCodeViewRecordWriter::~MinidumpModuleCodeViewRecordWriter() { |
28 } | 32 } |
29 | 33 |
30 namespace internal { | 34 namespace internal { |
31 | 35 |
32 template <typename CodeViewRecordType> | 36 template <typename CodeViewRecordType> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 codeview_record()->age = age; | 93 codeview_record()->age = age; |
90 } | 94 } |
91 | 95 |
92 template class internal::MinidumpModuleCodeViewRecordPDBLinkWriter< | 96 template class internal::MinidumpModuleCodeViewRecordPDBLinkWriter< |
93 MinidumpModuleCodeViewRecordPDB70>; | 97 MinidumpModuleCodeViewRecordPDB70>; |
94 | 98 |
95 MinidumpModuleCodeViewRecordPDB70Writer:: | 99 MinidumpModuleCodeViewRecordPDB70Writer:: |
96 ~MinidumpModuleCodeViewRecordPDB70Writer() { | 100 ~MinidumpModuleCodeViewRecordPDB70Writer() { |
97 } | 101 } |
98 | 102 |
| 103 void MinidumpModuleCodeViewRecordPDB70Writer::InitializeFromSnapshot( |
| 104 const ModuleSnapshot* module_snapshot) { |
| 105 DCHECK_EQ(state(), kStateMutable); |
| 106 |
| 107 std::string name = module_snapshot->Name(); |
| 108 std::string leaf_name; |
| 109 size_t last_slash = name.find_last_of('/'); |
| 110 if (last_slash != std::string::npos) { |
| 111 leaf_name = name.substr(last_slash + 1); |
| 112 } else { |
| 113 leaf_name = name; |
| 114 } |
| 115 SetPDBName(leaf_name); |
| 116 |
| 117 UUID uuid; |
| 118 module_snapshot->UUID(&uuid); |
| 119 SetUUIDAndAge(uuid, 0); |
| 120 } |
| 121 |
99 MinidumpModuleMiscDebugRecordWriter::MinidumpModuleMiscDebugRecordWriter() | 122 MinidumpModuleMiscDebugRecordWriter::MinidumpModuleMiscDebugRecordWriter() |
100 : internal::MinidumpWritable(), | 123 : internal::MinidumpWritable(), |
101 image_debug_misc_(), | 124 image_debug_misc_(), |
102 data_(), | 125 data_(), |
103 data_utf16_() { | 126 data_utf16_() { |
104 } | 127 } |
105 | 128 |
106 MinidumpModuleMiscDebugRecordWriter::~MinidumpModuleMiscDebugRecordWriter() { | 129 MinidumpModuleMiscDebugRecordWriter::~MinidumpModuleMiscDebugRecordWriter() { |
107 } | 130 } |
108 | 131 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 name_(), | 202 name_(), |
180 codeview_record_(nullptr), | 203 codeview_record_(nullptr), |
181 misc_debug_record_(nullptr) { | 204 misc_debug_record_(nullptr) { |
182 module_.VersionInfo.dwSignature = VS_FFI_SIGNATURE; | 205 module_.VersionInfo.dwSignature = VS_FFI_SIGNATURE; |
183 module_.VersionInfo.dwStrucVersion = VS_FFI_STRUCVERSION; | 206 module_.VersionInfo.dwStrucVersion = VS_FFI_STRUCVERSION; |
184 } | 207 } |
185 | 208 |
186 MinidumpModuleWriter::~MinidumpModuleWriter() { | 209 MinidumpModuleWriter::~MinidumpModuleWriter() { |
187 } | 210 } |
188 | 211 |
| 212 void MinidumpModuleWriter::InitializeFromSnapshot( |
| 213 const ModuleSnapshot* module_snapshot) { |
| 214 DCHECK_EQ(state(), kStateMutable); |
| 215 DCHECK(!name_); |
| 216 DCHECK(!codeview_record_); |
| 217 DCHECK(!misc_debug_record_); |
| 218 |
| 219 SetName(module_snapshot->Name()); |
| 220 |
| 221 SetImageBaseAddress(module_snapshot->Address()); |
| 222 SetImageSize(InRangeCast<uint32_t>(module_snapshot->Size(), |
| 223 std::numeric_limits<uint32_t>::max())); |
| 224 SetTimestamp(module_snapshot->Timestamp()); |
| 225 |
| 226 uint16_t v[4]; |
| 227 module_snapshot->FileVersion(&v[0], &v[1], &v[2], &v[3]); |
| 228 SetFileVersion(v[0], v[1], v[2], v[3]); |
| 229 |
| 230 module_snapshot->SourceVersion(&v[0], &v[1], &v[2], &v[3]); |
| 231 SetProductVersion(v[0], v[1], v[2], v[3]); |
| 232 |
| 233 uint32_t file_type; |
| 234 switch (module_snapshot->GetModuleType()) { |
| 235 case ModuleSnapshot::kModuleTypeExecutable: |
| 236 file_type = VFT_APP; |
| 237 break; |
| 238 case ModuleSnapshot::kModuleTypeSharedLibrary: |
| 239 case ModuleSnapshot::kModuleTypeLoadableModule: |
| 240 file_type = VFT_DLL; |
| 241 break; |
| 242 default: |
| 243 file_type = VFT_UNKNOWN; |
| 244 break; |
| 245 } |
| 246 SetFileTypeAndSubtype(file_type, VFT2_UNKNOWN); |
| 247 |
| 248 auto codeview_record = |
| 249 make_scoped_ptr(new MinidumpModuleCodeViewRecordPDB70Writer()); |
| 250 codeview_record->InitializeFromSnapshot(module_snapshot); |
| 251 SetCodeViewRecord(codeview_record.Pass()); |
| 252 } |
| 253 |
189 const MINIDUMP_MODULE* MinidumpModuleWriter::MinidumpModule() const { | 254 const MINIDUMP_MODULE* MinidumpModuleWriter::MinidumpModule() const { |
190 DCHECK_EQ(state(), kStateWritable); | 255 DCHECK_EQ(state(), kStateWritable); |
191 | 256 |
192 return &module_; | 257 return &module_; |
193 } | 258 } |
194 | 259 |
195 void MinidumpModuleWriter::SetName(const std::string& name) { | 260 void MinidumpModuleWriter::SetName(const std::string& name) { |
196 DCHECK_EQ(state(), kStateMutable); | 261 DCHECK_EQ(state(), kStateMutable); |
197 | 262 |
198 if (!name_) { | 263 if (!name_) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 return true; | 374 return true; |
310 } | 375 } |
311 | 376 |
312 MinidumpModuleListWriter::MinidumpModuleListWriter() | 377 MinidumpModuleListWriter::MinidumpModuleListWriter() |
313 : MinidumpStreamWriter(), module_list_base_(), modules_() { | 378 : MinidumpStreamWriter(), module_list_base_(), modules_() { |
314 } | 379 } |
315 | 380 |
316 MinidumpModuleListWriter::~MinidumpModuleListWriter() { | 381 MinidumpModuleListWriter::~MinidumpModuleListWriter() { |
317 } | 382 } |
318 | 383 |
| 384 void MinidumpModuleListWriter::InitializeFromSnapshot( |
| 385 const std::vector<const ModuleSnapshot*>& module_snapshots) { |
| 386 DCHECK_EQ(state(), kStateMutable); |
| 387 DCHECK(modules_.empty()); |
| 388 |
| 389 for (const ModuleSnapshot* module_snapshot : module_snapshots) { |
| 390 auto module = make_scoped_ptr(new MinidumpModuleWriter()); |
| 391 module->InitializeFromSnapshot(module_snapshot); |
| 392 AddModule(module.Pass()); |
| 393 } |
| 394 } |
| 395 |
319 void MinidumpModuleListWriter::AddModule( | 396 void MinidumpModuleListWriter::AddModule( |
320 scoped_ptr<MinidumpModuleWriter> module) { | 397 scoped_ptr<MinidumpModuleWriter> module) { |
321 DCHECK_EQ(state(), kStateMutable); | 398 DCHECK_EQ(state(), kStateMutable); |
322 | 399 |
323 modules_.push_back(module.release()); | 400 modules_.push_back(module.release()); |
324 } | 401 } |
325 | 402 |
326 bool MinidumpModuleListWriter::Freeze() { | 403 bool MinidumpModuleListWriter::Freeze() { |
327 DCHECK_EQ(state(), kStateMutable); | 404 DCHECK_EQ(state(), kStateMutable); |
328 | 405 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 } | 448 } |
372 | 449 |
373 return file_writer->WriteIoVec(&iovecs); | 450 return file_writer->WriteIoVec(&iovecs); |
374 } | 451 } |
375 | 452 |
376 MinidumpStreamType MinidumpModuleListWriter::StreamType() const { | 453 MinidumpStreamType MinidumpModuleListWriter::StreamType() const { |
377 return kMinidumpStreamTypeModuleList; | 454 return kMinidumpStreamTypeModuleList; |
378 } | 455 } |
379 | 456 |
380 } // namespace crashpad | 457 } // namespace crashpad |
OLD | NEW |