Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 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 <sys/utsname.h> | 35 #include <sys/utsname.h> |
| 36 | 36 |
| 37 #include <algorithm> | |
| 38 | |
| 39 #include "client/linux/dump_writer_common/thread_info.h" | 37 #include "client/linux/dump_writer_common/thread_info.h" |
| 40 #include "client/linux/dump_writer_common/ucontext_reader.h" | 38 #include "client/linux/dump_writer_common/ucontext_reader.h" |
| 41 #include "client/linux/handler/exception_handler.h" | 39 #include "client/linux/handler/exception_handler.h" |
| 42 #include "client/linux/handler/microdump_extra_info.h" | 40 #include "client/linux/handler/microdump_extra_info.h" |
| 43 #include "client/linux/log/log.h" | 41 #include "client/linux/log/log.h" |
| 44 #include "client/linux/minidump_writer/linux_ptrace_dumper.h" | 42 #include "client/linux/minidump_writer/linux_ptrace_dumper.h" |
| 45 #include "common/linux/file_id.h" | 43 #include "common/linux/file_id.h" |
| 46 #include "common/linux/linux_libc_support.h" | 44 #include "common/linux/linux_libc_support.h" |
| 45 #include "common/memory.h" | |
| 47 | 46 |
| 48 namespace { | 47 namespace { |
| 49 | 48 |
| 50 using google_breakpad::auto_wasteful_vector; | 49 using google_breakpad::auto_wasteful_vector; |
| 51 using google_breakpad::ExceptionHandler; | 50 using google_breakpad::ExceptionHandler; |
| 52 using google_breakpad::kDefaultBuildIdSize; | 51 using google_breakpad::kDefaultBuildIdSize; |
| 53 using google_breakpad::LinuxDumper; | 52 using google_breakpad::LinuxDumper; |
| 54 using google_breakpad::LinuxPtraceDumper; | 53 using google_breakpad::LinuxPtraceDumper; |
| 55 using google_breakpad::MappingInfo; | 54 using google_breakpad::MappingInfo; |
| 56 using google_breakpad::MappingList; | 55 using google_breakpad::MappingList; |
| 57 using google_breakpad::MicrodumpExtraInfo; | 56 using google_breakpad::MicrodumpExtraInfo; |
| 58 using google_breakpad::RawContextCPU; | 57 using google_breakpad::RawContextCPU; |
| 59 using google_breakpad::ThreadInfo; | 58 using google_breakpad::ThreadInfo; |
| 60 using google_breakpad::UContextReader; | 59 using google_breakpad::UContextReader; |
| 61 | 60 |
| 62 const size_t kLineBufferSize = 2048; | 61 const size_t kLineBufferSize = 2048; |
| 63 | 62 |
| 63 bool MappingsAreAdjacent(const MappingInfo* a, const MappingInfo* b) { | |
| 64 // Because of load biasing, we can end up with a situation where two | |
|
Primiano Tucci (use gerrit)
2016/05/06 11:07:56
Hmm I thought that after the latest linker changes
Tobias Sargeant
2016/05/06 13:29:31
It definitely came up during writing this CL. When
Primiano Tucci (use gerrit)
2016/05/06 13:58:38
https://codereview.chromium.org/1218493004
And the
| |
| 65 // mappings actually overlap. So we will define adjacency to also include a | |
| 66 // b start address that lies within a's address range (including starting | |
| 67 // immediately after a). | |
| 68 // Because load biasing only ever moves the start address backwards, the end | |
| 69 // address should still increase. | |
| 70 return a->start_addr <= b->start_addr && | |
| 71 a->start_addr + a->size >= b->start_addr; | |
| 72 } | |
| 73 | |
| 74 size_t NextOrderedMapping( | |
|
Primiano Tucci (use gerrit)
2016/05/06 11:07:56
Not sure I get the full logic here. Why is not eno
Tobias Sargeant
2016/05/06 11:33:45
size here is mappings array length, not the size o
Primiano Tucci (use gerrit)
2016/05/06 13:29:23
Oh ok I misread it. This seems overly complicated.
Tobias Sargeant
2016/05/13 16:16:54
Could do this, although you'd have to set best = c
| |
| 75 const google_breakpad::wasteful_vector<MappingInfo*>& mappings, | |
| 76 size_t curr) { | |
| 77 size_t best = mappings.size(); | |
| 78 for (size_t next = 0; next < mappings.size(); ++next) { | |
| 79 if (mappings[curr]->start_addr < mappings[next]->start_addr && | |
| 80 (best == mappings.size() || | |
| 81 mappings[next]->start_addr < mappings[best]->start_addr)) { | |
| 82 best = next; | |
| 83 } | |
| 84 } | |
| 85 return best; | |
| 86 } | |
| 87 | |
| 64 class MicrodumpWriter { | 88 class MicrodumpWriter { |
| 65 public: | 89 public: |
| 66 MicrodumpWriter(const ExceptionHandler::CrashContext* context, | 90 MicrodumpWriter(const ExceptionHandler::CrashContext* context, |
| 67 const MappingList& mappings, | 91 const MappingList& mappings, |
| 68 const MicrodumpExtraInfo& microdump_extra_info, | 92 const MicrodumpExtraInfo& microdump_extra_info, |
| 69 LinuxDumper* dumper) | 93 LinuxDumper* dumper) |
| 70 : ucontext_(context ? &context->context : NULL), | 94 : ucontext_(context ? &context->context : NULL), |
| 71 #if !defined(__ARM_EABI__) && !defined(__mips__) | 95 #if !defined(__ARM_EABI__) && !defined(__mips__) |
| 72 float_state_(context ? &context->float_state : NULL), | 96 float_state_(context ? &context->float_state : NULL), |
| 73 #endif | 97 #endif |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 91 return false; | 115 return false; |
| 92 return dumper_->ThreadsSuspend() && dumper_->LateInit(); | 116 return dumper_->ThreadsSuspend() && dumper_->LateInit(); |
| 93 } | 117 } |
| 94 | 118 |
| 95 bool Dump() { | 119 bool Dump() { |
| 96 bool success; | 120 bool success; |
| 97 LogLine("-----BEGIN BREAKPAD MICRODUMP-----"); | 121 LogLine("-----BEGIN BREAKPAD MICRODUMP-----"); |
| 98 DumpProductInformation(); | 122 DumpProductInformation(); |
| 99 DumpOSInformation(); | 123 DumpOSInformation(); |
| 100 DumpGPUInformation(); | 124 DumpGPUInformation(); |
| 125 DumpFreeSpace(); | |
| 101 success = DumpCrashingThread(); | 126 success = DumpCrashingThread(); |
| 102 if (success) | 127 if (success) |
| 103 success = DumpMappings(); | 128 success = DumpMappings(); |
| 104 LogLine("-----END BREAKPAD MICRODUMP-----"); | 129 LogLine("-----END BREAKPAD MICRODUMP-----"); |
| 105 dumper_->ThreadsResume(); | 130 dumper_->ThreadsResume(); |
| 106 return success; | 131 return success; |
| 107 } | 132 } |
| 108 | 133 |
| 109 private: | 134 private: |
| 110 // Writes one line to the system log. | 135 // Writes one line to the system log. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 133 // Make enough room to hex encode the largest int type + NUL. | 158 // Make enough room to hex encode the largest int type + NUL. |
| 134 static const char HEX[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', | 159 static const char HEX[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
| 135 'A', 'B', 'C', 'D', 'E', 'F'}; | 160 'A', 'B', 'C', 'D', 'E', 'F'}; |
| 136 char hexstr[sizeof(T) * 2 + 1]; | 161 char hexstr[sizeof(T) * 2 + 1]; |
| 137 for (int i = sizeof(T) * 2 - 1; i >= 0; --i, value >>= 4) | 162 for (int i = sizeof(T) * 2 - 1; i >= 0; --i, value >>= 4) |
| 138 hexstr[i] = HEX[static_cast<uint8_t>(value) & 0x0F]; | 163 hexstr[i] = HEX[static_cast<uint8_t>(value) & 0x0F]; |
| 139 hexstr[sizeof(T) * 2] = '\0'; | 164 hexstr[sizeof(T) * 2] = '\0'; |
| 140 LogAppend(hexstr); | 165 LogAppend(hexstr); |
| 141 } | 166 } |
| 142 | 167 |
| 168 void LogAppendDecimal(unsigned int value) { | |
| 169 const int SZ = sizeof(unsigned int) * 3; | |
|
Primiano Tucci (use gerrit)
2016/05/06 11:07:56
can we just use hex for everything, for consistenc
Tobias Sargeant
2016/05/06 11:33:45
Can do, but would still need to trim leading zeros
Primiano Tucci (use gerrit)
2016/05/06 13:29:23
LogAppend<T> will emit leading zeros only to pad t
Tobias Sargeant
2016/05/13 16:16:54
I modified LogAppend<T> to optionally strip leadin
| |
| 170 if (!value) { | |
| 171 LogAppend("0"); | |
| 172 return; | |
| 173 } | |
| 174 char decstr[SZ + 1]; | |
| 175 decstr[SZ] = '\0'; | |
| 176 int i; | |
| 177 for (i = SZ - 1; i >= 0; --i) { | |
| 178 decstr[i] = '0' + value % 10; | |
| 179 value /= 10; | |
| 180 if (!value) break; | |
| 181 } | |
| 182 LogAppend(decstr+i); | |
| 183 } | |
| 184 | |
| 143 // Stages the buffer content hex-encoded in the current line buffer. | 185 // Stages the buffer content hex-encoded in the current line buffer. |
| 144 void LogAppend(const void* buf, size_t length) { | 186 void LogAppend(const void* buf, size_t length) { |
| 145 const uint8_t* ptr = reinterpret_cast<const uint8_t*>(buf); | 187 const uint8_t* ptr = reinterpret_cast<const uint8_t*>(buf); |
| 146 for (size_t i = 0; i < length; ++i, ++ptr) | 188 for (size_t i = 0; i < length; ++i, ++ptr) |
| 147 LogAppend(*ptr); | 189 LogAppend(*ptr); |
| 148 } | 190 } |
| 149 | 191 |
| 150 // Writes out the current line buffer on the system log. | 192 // Writes out the current line buffer on the system log. |
| 151 void LogCommitLine() { | 193 void LogCommitLine() { |
| 152 LogLine(log_line_); | 194 LogLine(log_line_); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 LogAppend(module_identifier.data4[3]); | 426 LogAppend(module_identifier.data4[3]); |
| 385 LogAppend(module_identifier.data4[4]); | 427 LogAppend(module_identifier.data4[4]); |
| 386 LogAppend(module_identifier.data4[5]); | 428 LogAppend(module_identifier.data4[5]); |
| 387 LogAppend(module_identifier.data4[6]); | 429 LogAppend(module_identifier.data4[6]); |
| 388 LogAppend(module_identifier.data4[7]); | 430 LogAppend(module_identifier.data4[7]); |
| 389 LogAppend("0 "); // Age is always 0 on Linux. | 431 LogAppend("0 "); // Age is always 0 on Linux. |
| 390 LogAppend(file_name); | 432 LogAppend(file_name); |
| 391 LogCommitLine(); | 433 LogCommitLine(); |
| 392 } | 434 } |
| 393 | 435 |
| 436 bool DumpFreeSpace() { | |
| 437 const google_breakpad::wasteful_vector<MappingInfo*>& mappings = | |
| 438 dumper_->mappings(); | |
| 439 if (mappings.size() == 0) return false; | |
| 440 | |
| 441 // This is complicated by the fact that mappings is not in order. It should | |
| 442 // be mostly in order, however the mapping that contains the entry point for | |
| 443 // the process is always at the front of the vector. | |
| 444 | |
| 445 static const int HBITS = sizeof(size_t) * 8; | |
| 446 unsigned int hole_hist[HBITS]; | |
|
Primiano Tucci (use gerrit)
2016/05/06 11:07:56
can you call this hole_histogram? For a long while
Tobias Sargeant
2016/05/06 13:29:31
Done.
| |
| 447 my_memset(hole_hist, 0, sizeof(hole_hist)); | |
| 448 | |
| 449 // Find the lowest address mapping. | |
| 450 size_t curr = 0; | |
| 451 for (size_t i = 1; i < mappings.size(); ++i) { | |
| 452 if (mappings[i]->start_addr < mappings[curr]->start_addr) curr = i; | |
| 453 } | |
| 454 | |
| 455 uintptr_t lo_addr = mappings[curr]->start_addr; | |
| 456 | |
| 457 unsigned int hole_cnt = 0; | |
| 458 size_t hole_max = 0; | |
| 459 size_t hole_tot = 0; | |
|
Primiano Tucci (use gerrit)
2016/05/06 11:07:56
I'd probably rename this to hole_sum (or unmapped_
Tobias Sargeant
2016/05/06 13:29:31
Done.
| |
| 460 | |
| 461 while (true) { | |
| 462 // Skip to the end of an adjacent run of mappings. This is an optimization | |
| 463 // for the fact that mappings is mostly sorted. | |
| 464 while (curr != mappings.size() - 1 && | |
| 465 MappingsAreAdjacent(mappings[curr], mappings[curr + 1])) | |
| 466 ++curr; | |
| 467 | |
| 468 size_t next = NextOrderedMapping(mappings, curr); | |
| 469 if (next == mappings.size()) | |
| 470 break; | |
|
Primiano Tucci (use gerrit)
2016/05/06 11:07:57
isn't this going to ignore the big hole that you c
Tobias Sargeant
2016/05/06 11:33:45
It is, but we don't know exactly how big that hole
Primiano Tucci (use gerrit)
2016/05/06 13:29:23
Hmm but then you will never know if that hole is t
Tobias Sargeant
2016/05/13 16:16:54
This is what happens. The log line is:
H lo_addr
| |
| 471 | |
| 472 uintptr_t hole_lo = mappings[curr]->start_addr + mappings[curr]->size; | |
| 473 uintptr_t hole_hi = mappings[next]->start_addr; | |
| 474 | |
| 475 if (hole_hi > hole_lo) { | |
| 476 size_t hole_sz = hole_hi - hole_lo; | |
| 477 hole_tot += hole_sz; | |
| 478 hole_max = std::max(hole_sz, hole_max); | |
| 479 ++hole_cnt; | |
| 480 size_t h = 0; | |
| 481 while (hole_sz) { | |
|
Primiano Tucci (use gerrit)
2016/05/06 11:07:56
Can we just copy chrome base::Log2Floor(uint32_t n
Tobias Sargeant
2016/05/06 13:29:31
Done.
| |
| 482 ++h; | |
| 483 hole_sz >>= 1; | |
| 484 } | |
| 485 ++hole_hist[h]; | |
| 486 } | |
| 487 curr = next; | |
| 488 } | |
| 489 | |
| 490 uintptr_t hi_addr = mappings[curr]->start_addr + mappings[curr]->size; | |
| 491 | |
| 492 LogAppend("H "); | |
| 493 LogAppend(lo_addr); | |
| 494 LogAppend(" "); | |
| 495 LogAppend(hi_addr); | |
| 496 | |
| 497 LogAppend(" "); LogAppendDecimal(hole_cnt); | |
|
Primiano Tucci (use gerrit)
2016/05/06 11:07:56
are you appending the count three times here?
I s
Tobias Sargeant
2016/05/06 13:29:31
Certainly did!
| |
| 498 LogAppend(" "); LogAppend(hole_cnt); | |
|
Primiano Tucci (use gerrit)
2016/05/06 11:07:56
Also plz newlines after each statement
Tobias Sargeant
2016/05/06 13:29:31
Done.
| |
| 499 LogAppend(" "); LogAppend(hole_cnt); | |
| 500 for (unsigned int i = 0; i < HBITS; ++i) { | |
|
Primiano Tucci (use gerrit)
2016/05/06 11:07:57
can we saturate this up and down?
First of all, al
Torne
2016/05/06 11:13:36
We should probably just not do this at all on 64bi
Tobias Sargeant
2016/05/06 11:33:45
I'm not sure we want to cap at 1GB. On 32 bit that
Primiano Tucci (use gerrit)
2016/05/06 13:29:23
ok sorry I completely missed the if (!hole_hist[i]
Primiano Tucci (use gerrit)
2016/05/06 13:29:23
SGTM but nothing in this CL is preventing this to
| |
| 501 if (!hole_hist[i]) continue; | |
| 502 LogAppend(" "); | |
| 503 LogAppendDecimal(i); | |
| 504 LogAppend(":"); | |
| 505 LogAppendDecimal(hole_hist[i]); | |
| 506 } | |
| 507 LogCommitLine(); | |
| 508 return true; | |
| 509 } | |
| 510 | |
| 394 // Write information about the mappings in effect. | 511 // Write information about the mappings in effect. |
| 395 bool DumpMappings() { | 512 bool DumpMappings() { |
| 396 // First write all the mappings from the dumper | 513 // First write all the mappings from the dumper |
| 397 for (unsigned i = 0; i < dumper_->mappings().size(); ++i) { | 514 for (unsigned i = 0; i < dumper_->mappings().size(); ++i) { |
| 398 const MappingInfo& mapping = *dumper_->mappings()[i]; | 515 const MappingInfo& mapping = *dumper_->mappings()[i]; |
| 399 if (mapping.name[0] == 0 || // only want modules with filenames. | 516 if (mapping.name[0] == 0 || // only want modules with filenames. |
| 400 !mapping.exec || // only want executable mappings. | 517 !mapping.exec || // only want executable mappings. |
| 401 mapping.size < 4096 || // too small to get a signature for. | 518 mapping.size < 4096 || // too small to get a signature for. |
| 402 HaveMappingInfo(mapping)) { | 519 HaveMappingInfo(mapping)) { |
| 403 continue; | 520 continue; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 dumper.set_crash_signal(context->siginfo.si_signo); | 562 dumper.set_crash_signal(context->siginfo.si_signo); |
| 446 dumper.set_crash_thread(context->tid); | 563 dumper.set_crash_thread(context->tid); |
| 447 } | 564 } |
| 448 MicrodumpWriter writer(context, mappings, microdump_extra_info, &dumper); | 565 MicrodumpWriter writer(context, mappings, microdump_extra_info, &dumper); |
| 449 if (!writer.Init()) | 566 if (!writer.Init()) |
| 450 return false; | 567 return false; |
| 451 return writer.Dump(); | 568 return writer.Dump(); |
| 452 } | 569 } |
| 453 | 570 |
| 454 } // namespace google_breakpad | 571 } // namespace google_breakpad |
| OLD | NEW |