Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // For linux_syscall_support.h. This makes it safe to call embedded system | 5 // For linux_syscall_support.h. This makes it safe to call embedded system |
| 6 // calls when in seccomp mode. | 6 // calls when in seccomp mode. |
| 7 | 7 |
| 8 #include "components/crash/content/app/breakpad_linux.h" | 8 #include "components/crash/content/app/breakpad_linux.h" |
| 9 | 9 |
| 10 #include <fcntl.h> | 10 #include <fcntl.h> |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 bool g_is_crash_reporter_enabled = false; | 94 bool g_is_crash_reporter_enabled = false; |
| 95 uint64_t g_process_start_time = 0; | 95 uint64_t g_process_start_time = 0; |
| 96 pid_t g_pid = 0; | 96 pid_t g_pid = 0; |
| 97 char* g_crash_log_path = nullptr; | 97 char* g_crash_log_path = nullptr; |
| 98 ExceptionHandler* g_breakpad = nullptr; | 98 ExceptionHandler* g_breakpad = nullptr; |
| 99 | 99 |
| 100 #if defined(ADDRESS_SANITIZER) | 100 #if defined(ADDRESS_SANITIZER) |
| 101 const char* g_asan_report_str = nullptr; | 101 const char* g_asan_report_str = nullptr; |
| 102 #endif | 102 #endif |
| 103 #if defined(OS_ANDROID) | 103 #if defined(OS_ANDROID) |
| 104 #define G_DUMPS_SUPPRESSED_MAGIC 0x5AFECEDE | |
| 105 uint32_t g_dumps_suppressed = 0; | |
| 104 char* g_process_type = nullptr; | 106 char* g_process_type = nullptr; |
| 105 ExceptionHandler* g_microdump = nullptr; | 107 ExceptionHandler* g_microdump = nullptr; |
| 106 int g_signal_code_pipe_fd = -1; | 108 int g_signal_code_pipe_fd = -1; |
| 107 | 109 |
| 108 class MicrodumpInfo { | 110 class MicrodumpInfo { |
| 109 public: | 111 public: |
| 110 MicrodumpInfo() | 112 MicrodumpInfo() |
| 111 : microdump_build_fingerprint_(nullptr), | 113 : microdump_build_fingerprint_(nullptr), |
| 112 microdump_product_info_(nullptr), | 114 microdump_product_info_(nullptr), |
| 113 microdump_gpu_fingerprint_(nullptr) {} | 115 microdump_gpu_fingerprint_(nullptr) {} |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 my_strlcat(buf, android_build_info->package_version_code(), kMaxSize); | 571 my_strlcat(buf, android_build_info->package_version_code(), kMaxSize); |
| 570 my_strlcat(buf, " (", kMaxSize); | 572 my_strlcat(buf, " (", kMaxSize); |
| 571 my_strlcat(buf, android_build_info->package_version_name(), kMaxSize); | 573 my_strlcat(buf, android_build_info->package_version_name(), kMaxSize); |
| 572 my_strlcat(buf, ")", kMaxSize); | 574 my_strlcat(buf, ")", kMaxSize); |
| 573 | 575 |
| 574 writer.AddPairString("package", buf); | 576 writer.AddPairString("package", buf); |
| 575 } | 577 } |
| 576 #endif // defined(OS_ANDROID) | 578 #endif // defined(OS_ANDROID) |
| 577 | 579 |
| 578 void DumpProcess() { | 580 void DumpProcess() { |
| 581 #if defined(OS_ANDROID) | |
| 582 // Don't use g_breakpad and g_microdump directly here, because their | |
| 583 // output might currently be suppressed. | |
| 584 if (g_breakpad) { | |
| 585 ExceptionHandler(g_breakpad->minidump_descriptor(), | |
| 586 nullptr, | |
| 587 CrashDoneNoUpload, | |
| 588 nullptr, | |
| 589 false, -1).WriteMinidump(); | |
| 590 } | |
| 591 // If microdumps are enabled write also a microdump on the system log. | |
| 592 if (g_microdump) { | |
| 593 ExceptionHandler(g_microdump->minidump_descriptor(), | |
| 594 nullptr, | |
| 595 MicrodumpCrashDone, | |
| 596 nullptr, | |
| 597 false, -1).WriteMinidump(); | |
| 598 } | |
| 599 #else | |
| 579 if (g_breakpad) | 600 if (g_breakpad) |
| 580 g_breakpad->WriteMinidump(); | 601 g_breakpad->WriteMinidump(); |
| 581 | |
| 582 #if defined(OS_ANDROID) | |
| 583 // If microdumps are enabled write also a microdump on the system log. | |
| 584 if (g_microdump) | |
| 585 g_microdump->WriteMinidump(); | |
| 586 #endif | 602 #endif |
| 587 } | 603 } |
| 588 | 604 |
| 589 #if defined(OS_ANDROID) | 605 #if defined(OS_ANDROID) |
| 590 const char kGoogleBreakpad[] = "google-breakpad"; | 606 const char kGoogleBreakpad[] = "google-breakpad"; |
| 591 #endif | 607 #endif |
| 592 | 608 |
| 593 size_t WriteLog(const char* buf, size_t nbytes) { | 609 size_t WriteLog(const char* buf, size_t nbytes) { |
| 594 #if defined(OS_ANDROID) | 610 #if defined(OS_ANDROID) |
| 595 return __android_log_write(ANDROID_LOG_WARN, kGoogleBreakpad, buf); | 611 return __android_log_write(ANDROID_LOG_WARN, kGoogleBreakpad, buf); |
| 596 #else | 612 #else |
| 597 return sys_write(2, buf, nbytes); | 613 return sys_write(2, buf, nbytes); |
| 598 #endif | 614 #endif |
| 599 } | 615 } |
| 600 | 616 |
| 601 size_t WriteNewline() { | 617 size_t WriteNewline() { |
| 602 return WriteLog("\n", 1); | 618 return WriteLog("\n", 1); |
| 603 } | 619 } |
| 604 | 620 |
| 605 #if defined(OS_ANDROID) | 621 #if defined(OS_ANDROID) |
| 622 bool ShouldGenerateDump(void *context) { | |
| 623 return g_dumps_suppressed != G_DUMPS_SUPPRESSED_MAGIC; | |
| 624 } | |
| 625 | |
| 606 void AndroidLogWriteHorizontalRule() { | 626 void AndroidLogWriteHorizontalRule() { |
| 607 __android_log_write(ANDROID_LOG_WARN, kGoogleBreakpad, | 627 __android_log_write(ANDROID_LOG_WARN, kGoogleBreakpad, |
| 608 "### ### ### ### ### ### ### ### ### ### ### ### ###"); | 628 "### ### ### ### ### ### ### ### ### ### ### ### ###"); |
| 609 } | 629 } |
| 610 | 630 |
| 611 // Android's native crash handler outputs a diagnostic tombstone to the device | 631 // Android's native crash handler outputs a diagnostic tombstone to the device |
| 612 // log. By returning false from the HandlerCallbacks, breakpad will reinstall | 632 // log. By returning false from the HandlerCallbacks, breakpad will reinstall |
| 613 // the previous (i.e. native) signal handlers before returning from its own | 633 // the previous (i.e. native) signal handlers before returning from its own |
| 614 // handler. A Chrome build fingerprint is written to the log, so that the | 634 // handler. A Chrome build fingerprint is written to the log, so that the |
| 615 // specific build of Chrome and the location of the archived Chrome symbols can | 635 // specific build of Chrome and the location of the archived Chrome symbols can |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 749 minidump_descriptor.set_size_limit(-1); // unlimited. | 769 minidump_descriptor.set_size_limit(-1); // unlimited. |
| 750 } else { | 770 } else { |
| 751 minidump_descriptor.set_size_limit(kMaxMinidumpFileSize); | 771 minidump_descriptor.set_size_limit(kMaxMinidumpFileSize); |
| 752 } | 772 } |
| 753 #if defined(OS_ANDROID) | 773 #if defined(OS_ANDROID) |
| 754 unattended = true; // Android never uploads directly. | 774 unattended = true; // Android never uploads directly. |
| 755 #endif | 775 #endif |
| 756 if (unattended) { | 776 if (unattended) { |
| 757 g_breakpad = new ExceptionHandler( | 777 g_breakpad = new ExceptionHandler( |
| 758 minidump_descriptor, | 778 minidump_descriptor, |
| 759 nullptr, | 779 ShouldGenerateDump, |
|
Torne
2017/01/16 12:08:57
Does this need to be #if defined(OS_ANDROID)? The
Tobias Sargeant
2017/01/16 14:01:36
It certainly should be. Thanks.
| |
| 760 CrashDoneNoUpload, | 780 CrashDoneNoUpload, |
| 761 nullptr, | 781 nullptr, |
| 762 true, // Install handlers. | 782 true, // Install handlers. |
| 763 -1); // Server file descriptor. -1 for in-process. | 783 -1); // Server file descriptor. -1 for in-process. |
| 764 return; | 784 return; |
| 765 } | 785 } |
| 766 | 786 |
| 767 #if !defined(OS_ANDROID) | 787 #if !defined(OS_ANDROID) |
| 768 // Attended mode | 788 // Attended mode |
| 769 g_breakpad = new ExceptionHandler( | 789 g_breakpad = new ExceptionHandler( |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 858 return; | 878 return; |
| 859 } | 879 } |
| 860 SetProcessStartTime(); | 880 SetProcessStartTime(); |
| 861 g_pid = getpid(); | 881 g_pid = getpid(); |
| 862 | 882 |
| 863 g_is_crash_reporter_enabled = true; | 883 g_is_crash_reporter_enabled = true; |
| 864 // Save the process type (it is leaked). | 884 // Save the process type (it is leaked). |
| 865 const size_t process_type_len = process_type.size() + 1; | 885 const size_t process_type_len = process_type.size() + 1; |
| 866 g_process_type = new char[process_type_len]; | 886 g_process_type = new char[process_type_len]; |
| 867 strncpy(g_process_type, process_type.c_str(), process_type_len); | 887 strncpy(g_process_type, process_type.c_str(), process_type_len); |
| 868 new google_breakpad::ExceptionHandler(MinidumpDescriptor(minidump_fd), | 888 new ExceptionHandler(MinidumpDescriptor(minidump_fd), ShouldGenerateDump, |
| 869 nullptr, CrashDoneInProcessNoUpload, nullptr, true, -1); | 889 CrashDoneInProcessNoUpload, nullptr, true, -1); |
| 870 } | 890 } |
| 871 | 891 |
| 872 void MicrodumpInfo::SetGpuFingerprint(const std::string& gpu_fingerprint) { | 892 void MicrodumpInfo::SetGpuFingerprint(const std::string& gpu_fingerprint) { |
| 873 DCHECK(thread_checker_.CalledOnValidThread()); | 893 DCHECK(thread_checker_.CalledOnValidThread()); |
| 874 DCHECK(!microdump_gpu_fingerprint_); | 894 DCHECK(!microdump_gpu_fingerprint_); |
| 875 microdump_gpu_fingerprint_ = strdup(gpu_fingerprint.c_str()); | 895 microdump_gpu_fingerprint_ = strdup(gpu_fingerprint.c_str()); |
| 876 ANNOTATE_LEAKING_OBJECT_PTR(microdump_gpu_fingerprint_); | 896 ANNOTATE_LEAKING_OBJECT_PTR(microdump_gpu_fingerprint_); |
| 877 | 897 |
| 878 if (g_microdump) { | 898 if (g_microdump) { |
| 879 MinidumpDescriptor minidump_descriptor(g_microdump->minidump_descriptor()); | 899 MinidumpDescriptor minidump_descriptor(g_microdump->minidump_descriptor()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 916 descriptor.microdump_extra_info()->build_fingerprint = | 936 descriptor.microdump_extra_info()->build_fingerprint = |
| 917 microdump_build_fingerprint_; | 937 microdump_build_fingerprint_; |
| 918 } | 938 } |
| 919 | 939 |
| 920 if (microdump_gpu_fingerprint_) { | 940 if (microdump_gpu_fingerprint_) { |
| 921 descriptor.microdump_extra_info()->gpu_fingerprint = | 941 descriptor.microdump_extra_info()->gpu_fingerprint = |
| 922 microdump_gpu_fingerprint_; | 942 microdump_gpu_fingerprint_; |
| 923 } | 943 } |
| 924 | 944 |
| 925 g_microdump = | 945 g_microdump = |
| 926 new ExceptionHandler(descriptor, nullptr, MicrodumpCrashDone, | 946 new ExceptionHandler(descriptor, ShouldGenerateDump, MicrodumpCrashDone, |
| 927 reinterpret_cast<void*>(is_browser_process), | 947 reinterpret_cast<void*>(is_browser_process), |
| 928 true, // Install handlers. | 948 true, // Install handlers. |
| 929 -1); // Server file descriptor. -1 for in-process. | 949 -1); // Server file descriptor. -1 for in-process. |
| 930 | 950 |
| 931 if (process_type != kWebViewSingleProcessType && | 951 if (process_type != kWebViewSingleProcessType && |
| 932 process_type != kBrowserProcessType && | 952 process_type != kBrowserProcessType && |
| 933 !process_type.empty()) { | 953 !process_type.empty()) { |
| 934 g_signal_code_pipe_fd = | 954 g_signal_code_pipe_fd = |
| 935 GetCrashReporterClient()->GetAndroidCrashSignalFD(); | 955 GetCrashReporterClient()->GetAndroidCrashSignalFD(); |
| 936 if (g_signal_code_pipe_fd != -1) | 956 if (g_signal_code_pipe_fd != -1) |
| (...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1939 | 1959 |
| 1940 void GenerateMinidumpOnDemandForAndroid(int dump_fd) { | 1960 void GenerateMinidumpOnDemandForAndroid(int dump_fd) { |
| 1941 if (dump_fd >= 0) { | 1961 if (dump_fd >= 0) { |
| 1942 MinidumpDescriptor minidump_descriptor(dump_fd); | 1962 MinidumpDescriptor minidump_descriptor(dump_fd); |
| 1943 minidump_descriptor.set_size_limit(-1); | 1963 minidump_descriptor.set_size_limit(-1); |
| 1944 ExceptionHandler(minidump_descriptor, nullptr, MinidumpGenerated, nullptr, | 1964 ExceptionHandler(minidump_descriptor, nullptr, MinidumpGenerated, nullptr, |
| 1945 false, -1) | 1965 false, -1) |
| 1946 .WriteMinidump(); | 1966 .WriteMinidump(); |
| 1947 } | 1967 } |
| 1948 } | 1968 } |
| 1969 | |
| 1970 void SuppressDumpGeneration() { | |
| 1971 g_dumps_suppressed = G_DUMPS_SUPPRESSED_MAGIC; | |
| 1972 } | |
| 1949 #endif // OS_ANDROID | 1973 #endif // OS_ANDROID |
| 1950 | 1974 |
| 1951 bool IsCrashReporterEnabled() { | 1975 bool IsCrashReporterEnabled() { |
| 1952 return g_is_crash_reporter_enabled; | 1976 return g_is_crash_reporter_enabled; |
| 1953 } | 1977 } |
| 1954 | 1978 |
| 1955 } // namespace breakpad | 1979 } // namespace breakpad |
| OLD | NEW |