OLD | NEW |
1 // Copyright (c) 2014, Google Inc. | 1 // Copyright (c) 2014, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 14 matching lines...) Expand all Loading... |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 // This translation unit generates microdumps into the console (logcat on | 30 // This translation unit generates microdumps into the console (logcat on |
31 // Android). See crbug.com/410294 for more info and design docs. | 31 // Android). See crbug.com/410294 for more info and design docs. |
32 | 32 |
33 #include "client/linux/microdump_writer/microdump_writer.h" | 33 #include "client/linux/microdump_writer/microdump_writer.h" |
34 | 34 |
| 35 #include <algorithm> |
35 #include <sys/utsname.h> | 36 #include <sys/utsname.h> |
36 | 37 |
37 #include "client/linux/dump_writer_common/thread_info.h" | 38 #include "client/linux/dump_writer_common/thread_info.h" |
38 #include "client/linux/dump_writer_common/ucontext_reader.h" | 39 #include "client/linux/dump_writer_common/ucontext_reader.h" |
39 #include "client/linux/handler/exception_handler.h" | 40 #include "client/linux/handler/exception_handler.h" |
40 #include "client/linux/handler/microdump_extra_info.h" | 41 #include "client/linux/handler/microdump_extra_info.h" |
41 #include "client/linux/log/log.h" | 42 #include "client/linux/log/log.h" |
42 #include "client/linux/minidump_writer/linux_ptrace_dumper.h" | 43 #include "client/linux/minidump_writer/linux_ptrace_dumper.h" |
| 44 #include "common/linux/file_id.h" |
43 #include "common/linux/linux_libc_support.h" | 45 #include "common/linux/linux_libc_support.h" |
44 | 46 |
45 namespace { | 47 namespace { |
46 | 48 |
47 using google_breakpad::ExceptionHandler; | 49 using google_breakpad::ExceptionHandler; |
| 50 using google_breakpad::kDefaultBuildIdSize; |
48 using google_breakpad::LinuxDumper; | 51 using google_breakpad::LinuxDumper; |
49 using google_breakpad::LinuxPtraceDumper; | 52 using google_breakpad::LinuxPtraceDumper; |
50 using google_breakpad::MappingInfo; | 53 using google_breakpad::MappingInfo; |
51 using google_breakpad::MappingList; | 54 using google_breakpad::MappingList; |
52 using google_breakpad::MicrodumpExtraInfo; | 55 using google_breakpad::MicrodumpExtraInfo; |
53 using google_breakpad::RawContextCPU; | 56 using google_breakpad::RawContextCPU; |
54 using google_breakpad::ThreadInfo; | 57 using google_breakpad::ThreadInfo; |
55 using google_breakpad::UContextReader; | 58 using google_breakpad::UContextReader; |
| 59 using google_breakpad::wasteful_vector; |
56 | 60 |
57 const size_t kLineBufferSize = 2048; | 61 const size_t kLineBufferSize = 2048; |
58 | 62 |
59 class MicrodumpWriter { | 63 class MicrodumpWriter { |
60 public: | 64 public: |
61 MicrodumpWriter(const ExceptionHandler::CrashContext* context, | 65 MicrodumpWriter(const ExceptionHandler::CrashContext* context, |
62 const MappingList& mappings, | 66 const MappingList& mappings, |
63 const MicrodumpExtraInfo& microdump_extra_info, | 67 const MicrodumpExtraInfo& microdump_extra_info, |
64 LinuxDumper* dumper) | 68 LinuxDumper* dumper) |
65 : ucontext_(context ? &context->context : NULL), | 69 : ucontext_(context ? &context->context : NULL), |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 333 } |
330 return false; | 334 return false; |
331 } | 335 } |
332 | 336 |
333 // Dump information about the provided |mapping|. If |identifier| is non-NULL, | 337 // Dump information about the provided |mapping|. If |identifier| is non-NULL, |
334 // use it instead of calculating a file ID from the mapping. | 338 // use it instead of calculating a file ID from the mapping. |
335 void DumpModule(const MappingInfo& mapping, | 339 void DumpModule(const MappingInfo& mapping, |
336 bool member, | 340 bool member, |
337 unsigned int mapping_id, | 341 unsigned int mapping_id, |
338 const uint8_t* identifier) { | 342 const uint8_t* identifier) { |
339 MDGUID module_identifier; | 343 wasteful_vector<uint8_t> identifier_bytes(dumper_->allocator(), |
| 344 kDefaultBuildIdSize); |
340 if (identifier) { | 345 if (identifier) { |
341 // GUID was provided by caller. | 346 // GUID was provided by caller. |
342 my_memcpy(&module_identifier, identifier, sizeof(MDGUID)); | 347 identifier_bytes.resize(sizeof(MDGUID)); |
| 348 my_memcpy(&identifier_bytes[0], identifier, sizeof(MDGUID)); |
343 } else { | 349 } else { |
344 dumper_->ElfFileIdentifierForMapping( | 350 dumper_->ElfFileIdentifierForMapping( |
345 mapping, | 351 mapping, |
346 member, | 352 member, |
347 mapping_id, | 353 mapping_id, |
348 reinterpret_cast<uint8_t*>(&module_identifier)); | 354 identifier_bytes); |
349 } | 355 } |
350 | 356 |
| 357 // Copy as many bytes of |identifier| as will fit into a MDGUID |
| 358 MDGUID module_identifier = {0}; |
| 359 memcpy(&module_identifier, &identifier_bytes[0], |
| 360 std::min(sizeof(MDGUID), identifier_bytes.size())); |
| 361 |
351 char file_name[NAME_MAX]; | 362 char file_name[NAME_MAX]; |
352 char file_path[NAME_MAX]; | 363 char file_path[NAME_MAX]; |
353 dumper_->GetMappingEffectiveNameAndPath( | 364 dumper_->GetMappingEffectiveNameAndPath( |
354 mapping, file_path, sizeof(file_path), file_name, sizeof(file_name)); | 365 mapping, file_path, sizeof(file_path), file_name, sizeof(file_name)); |
355 | 366 |
356 LogAppend("M "); | 367 LogAppend("M "); |
357 LogAppend(static_cast<uintptr_t>(mapping.start_addr)); | 368 LogAppend(static_cast<uintptr_t>(mapping.start_addr)); |
358 LogAppend(" "); | 369 LogAppend(" "); |
359 LogAppend(mapping.offset); | 370 LogAppend(mapping.offset); |
360 LogAppend(" "); | 371 LogAppend(" "); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 dumper.set_crash_signal(context->siginfo.si_signo); | 441 dumper.set_crash_signal(context->siginfo.si_signo); |
431 dumper.set_crash_thread(context->tid); | 442 dumper.set_crash_thread(context->tid); |
432 } | 443 } |
433 MicrodumpWriter writer(context, mappings, microdump_extra_info, &dumper); | 444 MicrodumpWriter writer(context, mappings, microdump_extra_info, &dumper); |
434 if (!writer.Init()) | 445 if (!writer.Init()) |
435 return false; | 446 return false; |
436 return writer.Dump(); | 447 return writer.Dump(); |
437 } | 448 } |
438 | 449 |
439 } // namespace google_breakpad | 450 } // namespace google_breakpad |
OLD | NEW |