Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(560)

Side by Side Diff: components/crash/content/app/breakpad_linux.cc

Issue 2694083004: Fix minidump-generation for debug builds. (Closed)
Patch Set: Remove some old setters. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // resulting in the same effect. 125 // resulting in the same effect.
126 // 126 //
127 // The following restrictions apply, however: 127 // The following restrictions apply, however:
128 // * Both methods must be called from the same thread. 128 // * Both methods must be called from the same thread.
129 // * Both methods must be called at most once. 129 // * Both methods must be called at most once.
130 // 130 //
131 // Microdumps will only be generated if Initialize is called. If 131 // Microdumps will only be generated if Initialize is called. If
132 // SetGpuFingerprint has not been called called at the point at 132 // SetGpuFingerprint has not been called called at the point at
133 // which a microdump is generated, then the GPU fingerprint will be 133 // which a microdump is generated, then the GPU fingerprint will be
134 // UNKNOWN. 134 // UNKNOWN.
135 void SetGpuFingerprint(const std::string& gpu_fingerprint); 135 void SetGpuFingerprintForMicrodump(const std::string& gpu_fingerprint);
136 void SetSkipDumpIfPrincipalMappingNotReferenced( 136 void UpdateMicrodumpExceptionHandler();
137 uintptr_t address_within_principal_mapping); 137 void UpdateMicrodumpDescriptor(MinidumpDescriptor* minidump_descriptor);
138 void SetShouldSanitizeDumps(bool should_sanitize_dumps);
139 void UpdateMinidumpDescriptor(MinidumpDescriptor* minidump_descriptor);
140 void UpdateExceptionHandlers();
141 void Initialize(const std::string& process_type, 138 void Initialize(const std::string& process_type,
142 const char* product_name, 139 const char* product_name,
143 const char* product_version, 140 const char* product_version,
144 const char* android_build_fp); 141 const char* android_build_fp,
142 const SanitizationInfo& sanitizationInfo);
145 143
146 private: 144 private:
147 base::ThreadChecker thread_checker_; 145 base::ThreadChecker thread_checker_;
148 const char* microdump_build_fingerprint_; 146 const char* microdump_build_fingerprint_;
149 const char* microdump_product_info_; 147 const char* microdump_product_info_;
150 const char* microdump_gpu_fingerprint_; 148 const char* microdump_gpu_fingerprint_;
151 const char* microdump_process_type_; 149 const char* microdump_process_type_;
152 bool skip_dump_if_principal_mapping_not_referenced_; 150 bool skip_dump_if_principal_mapping_not_referenced_;
153 uintptr_t address_within_principal_mapping_; 151 uintptr_t address_within_principal_mapping_;
154 bool should_sanitize_dumps_; 152 bool should_sanitize_dumps_;
155 }; 153 };
156 154
155 void SetMinidumpSanitizationFields(MinidumpDescriptor* minidump_descriptor,
156 const SanitizationInfo& sanitizationInfo);
157
157 base::LazyInstance<MicrodumpInfo> g_microdump_info = 158 base::LazyInstance<MicrodumpInfo> g_microdump_info =
158 LAZY_INSTANCE_INITIALIZER; 159 LAZY_INSTANCE_INITIALIZER;
159 160
160 #endif 161 #endif
161 162
162 CrashKeyStorage* g_crash_keys = nullptr; 163 CrashKeyStorage* g_crash_keys = nullptr;
163 164
164 // Writes the value |v| as 16 hex characters to the memory pointed at by 165 // Writes the value |v| as 16 hex characters to the memory pointed at by
165 // |output|. 166 // |output|.
166 void write_uint64_hex(char* output, uint64_t v) { 167 void write_uint64_hex(char* output, uint64_t v) {
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 void __asan_set_error_report_callback(void (*cb)(const char*)); 774 void __asan_set_error_report_callback(void (*cb)(const char*));
774 775
775 extern "C" 776 extern "C"
776 void AsanLinuxBreakpadCallback(const char* report) { 777 void AsanLinuxBreakpadCallback(const char* report) {
777 g_asan_report_str = report; 778 g_asan_report_str = report;
778 // Send minidump here. 779 // Send minidump here.
779 g_breakpad->SimulateSignalDelivery(SIGKILL); 780 g_breakpad->SimulateSignalDelivery(SIGKILL);
780 } 781 }
781 #endif 782 #endif
782 783
783 void EnableCrashDumping(bool unattended) { 784 void EnableCrashDumping(bool unattended,
785 const SanitizationInfo& sanitizationInfo) {
784 g_is_crash_reporter_enabled = true; 786 g_is_crash_reporter_enabled = true;
785 787
786 base::FilePath tmp_path("/tmp"); 788 base::FilePath tmp_path("/tmp");
787 PathService::Get(base::DIR_TEMP, &tmp_path); 789 PathService::Get(base::DIR_TEMP, &tmp_path);
788 790
789 base::FilePath dumps_path(tmp_path); 791 base::FilePath dumps_path(tmp_path);
790 if (GetCrashReporterClient()->GetCrashDumpLocation(&dumps_path)) { 792 if (GetCrashReporterClient()->GetCrashDumpLocation(&dumps_path)) {
791 base::FilePath logfile = 793 base::FilePath logfile =
792 dumps_path.Append(GetCrashReporterClient()->GetReporterLogFilename()); 794 dumps_path.Append(GetCrashReporterClient()->GetReporterLogFilename());
793 std::string logfile_str = logfile.value(); 795 std::string logfile_str = logfile.value();
794 const size_t crash_log_path_len = logfile_str.size() + 1; 796 const size_t crash_log_path_len = logfile_str.size() + 1;
795 g_crash_log_path = new char[crash_log_path_len]; 797 g_crash_log_path = new char[crash_log_path_len];
796 strncpy(g_crash_log_path, logfile_str.c_str(), crash_log_path_len); 798 strncpy(g_crash_log_path, logfile_str.c_str(), crash_log_path_len);
797 } 799 }
798 DCHECK(!g_breakpad); 800 DCHECK(!g_breakpad);
799 MinidumpDescriptor minidump_descriptor(dumps_path.value()); 801 MinidumpDescriptor minidump_descriptor(dumps_path.value());
800 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 802 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
801 switches::kFullMemoryCrashReport)) { 803 switches::kFullMemoryCrashReport)) {
802 minidump_descriptor.set_size_limit(-1); // unlimited. 804 minidump_descriptor.set_size_limit(-1); // unlimited.
803 } else { 805 } else {
804 minidump_descriptor.set_size_limit(kMaxMinidumpFileSize); 806 minidump_descriptor.set_size_limit(kMaxMinidumpFileSize);
805 } 807 }
806 #if defined(OS_ANDROID) 808 #if defined(OS_ANDROID)
807 unattended = true; // Android never uploads directly. 809 unattended = true; // Android never uploads directly.
808 g_microdump_info.Get().UpdateMinidumpDescriptor(&minidump_descriptor); 810 SetMinidumpSanitizationFields(&minidump_descriptor, sanitizationInfo);
809 #endif 811 #endif
810 if (unattended) { 812 if (unattended) {
811 g_breakpad = new ExceptionHandler( 813 g_breakpad = new ExceptionHandler(
812 minidump_descriptor, 814 minidump_descriptor,
813 #if defined(OS_ANDROID) 815 #if defined(OS_ANDROID)
814 ShouldGenerateDump, 816 ShouldGenerateDump,
815 #else 817 #else
816 nullptr, 818 nullptr,
817 #endif 819 #endif
818 CrashDoneNoUpload, 820 CrashDoneNoUpload,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 info.distro_length = 0; 878 info.distro_length = 0;
877 info.upload = false; 879 info.upload = false;
878 info.process_start_time = g_process_start_time; 880 info.process_start_time = g_process_start_time;
879 info.pid = g_pid; 881 info.pid = g_pid;
880 info.crash_keys = g_crash_keys; 882 info.crash_keys = g_crash_keys;
881 HandleCrashDump(info); 883 HandleCrashDump(info);
882 return FinalizeCrashDoneAndroid(false /* is_browser_process */); 884 return FinalizeCrashDoneAndroid(false /* is_browser_process */);
883 } 885 }
884 886
885 void EnableNonBrowserCrashDumping(const std::string& process_type, 887 void EnableNonBrowserCrashDumping(const std::string& process_type,
886 int minidump_fd) { 888 int minidump_fd,
889 const SanitizationInfo& sanitizationInfo) {
887 // This will guarantee that the BuildInfo has been initialized and subsequent 890 // This will guarantee that the BuildInfo has been initialized and subsequent
888 // calls will not require memory allocation. 891 // calls will not require memory allocation.
889 base::android::BuildInfo::GetInstance(); 892 base::android::BuildInfo::GetInstance();
890 SetClientIdFromCommandLine(*base::CommandLine::ForCurrentProcess()); 893 SetClientIdFromCommandLine(*base::CommandLine::ForCurrentProcess());
891 894
892 // On Android, the current sandboxing uses process isolation, in which the 895 // On Android, the current sandboxing uses process isolation, in which the
893 // child process runs with a different UID. That breaks the normal crash 896 // child process runs with a different UID. That breaks the normal crash
894 // reporting where the browser process generates the minidump by inspecting 897 // reporting where the browser process generates the minidump by inspecting
895 // the child process. This is because the browser process now does not have 898 // the child process. This is because the browser process now does not have
896 // the permission to access the states of the child process (as it has a 899 // the permission to access the states of the child process (as it has a
897 // different UID). 900 // different UID).
898 // TODO(jcivelli): http://b/issue?id=6776356 we should use a watchdog 901 // TODO(jcivelli): http://b/issue?id=6776356 we should use a watchdog
899 // process forked from the renderer process that generates the minidump. 902 // process forked from the renderer process that generates the minidump.
900 if (minidump_fd == -1) { 903 if (minidump_fd == -1) {
901 LOG(ERROR) << "Minidump file descriptor not found, crash reporting will " 904 LOG(ERROR) << "Minidump file descriptor not found, crash reporting will "
902 " not work."; 905 " not work.";
903 return; 906 return;
904 } 907 }
905 SetProcessStartTime(); 908 SetProcessStartTime();
906 g_pid = getpid(); 909 g_pid = getpid();
907 910
908 g_is_crash_reporter_enabled = true; 911 g_is_crash_reporter_enabled = true;
909 // Save the process type (it is leaked). 912 // Save the process type (it is leaked).
910 const size_t process_type_len = process_type.size() + 1; 913 const size_t process_type_len = process_type.size() + 1;
911 g_process_type = new char[process_type_len]; 914 g_process_type = new char[process_type_len];
912 strncpy(g_process_type, process_type.c_str(), process_type_len); 915 strncpy(g_process_type, process_type.c_str(), process_type_len);
913 916
914 MinidumpDescriptor descriptor(minidump_fd); 917 MinidumpDescriptor descriptor(minidump_fd);
915 g_microdump_info.Get().UpdateMinidumpDescriptor(&descriptor); 918 SetMinidumpSanitizationFields(&descriptor, sanitizationInfo);
916 g_breakpad = 919 g_breakpad =
917 new ExceptionHandler(descriptor, ShouldGenerateDump, 920 new ExceptionHandler(descriptor, ShouldGenerateDump,
918 CrashDoneInProcessNoUpload, nullptr, true, -1); 921 CrashDoneInProcessNoUpload, nullptr, true, -1);
919 } 922 }
920 923
921 void MicrodumpInfo::SetGpuFingerprint(const std::string& gpu_fingerprint) { 924 void MicrodumpInfo::SetGpuFingerprintForMicrodump(
925 const std::string& gpu_fingerprint) {
922 DCHECK(thread_checker_.CalledOnValidThread()); 926 DCHECK(thread_checker_.CalledOnValidThread());
923 DCHECK(!microdump_gpu_fingerprint_); 927 DCHECK(!microdump_gpu_fingerprint_);
924 microdump_gpu_fingerprint_ = strdup(gpu_fingerprint.c_str()); 928 microdump_gpu_fingerprint_ = strdup(gpu_fingerprint.c_str());
925 ANNOTATE_LEAKING_OBJECT_PTR(microdump_gpu_fingerprint_); 929 ANNOTATE_LEAKING_OBJECT_PTR(microdump_gpu_fingerprint_);
926 930
927 UpdateExceptionHandlers(); 931 UpdateMicrodumpExceptionHandler();
928 } 932 }
929 933
930 void MicrodumpInfo::SetSkipDumpIfPrincipalMappingNotReferenced( 934 void SetMinidumpSanitizationFields(MinidumpDescriptor* minidump_descriptor,
931 uintptr_t address_within_principal_mapping) { 935 const SanitizationInfo& sanitizationInfo) {
932 DCHECK(thread_checker_.CalledOnValidThread()); 936 minidump_descriptor->set_skip_dump_if_principal_mapping_not_referenced(
933 skip_dump_if_principal_mapping_not_referenced_ = true; 937 sanitizationInfo.skip_dump_if_principal_mapping_not_referenced);
934 address_within_principal_mapping_ = address_within_principal_mapping; 938 minidump_descriptor->set_address_within_principal_mapping(
935 939 sanitizationInfo.address_within_principal_mapping);
936 UpdateExceptionHandlers(); 940 minidump_descriptor->set_sanitize_stacks(
941 sanitizationInfo.should_sanitize_dumps);
937 } 942 }
938 943
939 void MicrodumpInfo::SetShouldSanitizeDumps(bool should_sanitize_dumps) { 944 void MicrodumpInfo::UpdateMicrodumpDescriptor(
940 DCHECK(thread_checker_.CalledOnValidThread());
941 should_sanitize_dumps_ = should_sanitize_dumps;
942
943 UpdateExceptionHandlers();
944 }
945
946 void MicrodumpInfo::UpdateMinidumpDescriptor(
947 MinidumpDescriptor* minidump_descriptor) { 945 MinidumpDescriptor* minidump_descriptor) {
948 google_breakpad::MicrodumpExtraInfo* microdump_extra_info = 946 google_breakpad::MicrodumpExtraInfo* microdump_extra_info =
949 minidump_descriptor->microdump_extra_info(); 947 minidump_descriptor->microdump_extra_info();
950 948
951 minidump_descriptor->set_skip_dump_if_principal_mapping_not_referenced(
952 skip_dump_if_principal_mapping_not_referenced_);
953 minidump_descriptor->set_address_within_principal_mapping(
954 address_within_principal_mapping_);
955 minidump_descriptor->set_sanitize_stacks(should_sanitize_dumps_);
956
957 microdump_extra_info->gpu_fingerprint = microdump_gpu_fingerprint_; 949 microdump_extra_info->gpu_fingerprint = microdump_gpu_fingerprint_;
958 microdump_extra_info->product_info = microdump_product_info_; 950 microdump_extra_info->product_info = microdump_product_info_;
959 microdump_extra_info->process_type = microdump_process_type_; 951 microdump_extra_info->process_type = microdump_process_type_;
960 microdump_extra_info->build_fingerprint = microdump_build_fingerprint_; 952 microdump_extra_info->build_fingerprint = microdump_build_fingerprint_;
961 } 953 }
962 954
963 void MicrodumpInfo::UpdateExceptionHandlers() { 955 void MicrodumpInfo::UpdateMicrodumpExceptionHandler() {
964 if (g_breakpad) {
965 MinidumpDescriptor descriptor(g_breakpad->minidump_descriptor());
966 UpdateMinidumpDescriptor(&descriptor);
967 g_breakpad->set_minidump_descriptor(descriptor);
968 }
969 if (g_microdump) { 956 if (g_microdump) {
970 MinidumpDescriptor descriptor(g_microdump->minidump_descriptor()); 957 MinidumpDescriptor descriptor(g_microdump->minidump_descriptor());
971 UpdateMinidumpDescriptor(&descriptor); 958 UpdateMicrodumpDescriptor(&descriptor);
972 g_microdump->set_minidump_descriptor(descriptor); 959 g_microdump->set_minidump_descriptor(descriptor);
973 } 960 }
974 } 961 }
975 962
976 void MicrodumpInfo::Initialize(const std::string& process_type, 963 void MicrodumpInfo::Initialize(const std::string& process_type,
977 const char* product_name, 964 const char* product_name,
978 const char* product_version, 965 const char* product_version,
979 const char* android_build_fp) { 966 const char* android_build_fp,
967 const SanitizationInfo& sanitizationInfo) {
980 DCHECK(thread_checker_.CalledOnValidThread()); 968 DCHECK(thread_checker_.CalledOnValidThread());
981 DCHECK(!g_microdump); 969 DCHECK(!g_microdump);
982 // |process_type| for webview's browser process is kBrowserProcessType or 970 // |process_type| for webview's browser process is kBrowserProcessType or
983 // kWebViewSingleProcessType. |process_type| for chrome's browser process is 971 // kWebViewSingleProcessType. |process_type| for chrome's browser process is
984 // an empty string. 972 // an empty string.
985 bool is_browser_process = process_type.empty() || 973 bool is_browser_process = process_type.empty() ||
986 process_type == kWebViewSingleProcessType || 974 process_type == kWebViewSingleProcessType ||
987 process_type == kBrowserProcessType; 975 process_type == kBrowserProcessType;
988 976
989 MinidumpDescriptor descriptor(MinidumpDescriptor::kMicrodumpOnConsole); 977 MinidumpDescriptor descriptor(MinidumpDescriptor::kMicrodumpOnConsole);
990 978
991 if (product_name && product_version) { 979 if (product_name && product_version) {
992 microdump_product_info_ = 980 microdump_product_info_ =
993 strdup((product_name + std::string(":") + product_version).c_str()); 981 strdup((product_name + std::string(":") + product_version).c_str());
994 ANNOTATE_LEAKING_OBJECT_PTR(microdump_product_info_); 982 ANNOTATE_LEAKING_OBJECT_PTR(microdump_product_info_);
995 } 983 }
996 984
997 microdump_process_type_ = 985 microdump_process_type_ =
998 strdup(process_type.empty() ? kBrowserProcessType : process_type.c_str()); 986 strdup(process_type.empty() ? kBrowserProcessType : process_type.c_str());
999 ANNOTATE_LEAKING_OBJECT_PTR(microdump_process_type_); 987 ANNOTATE_LEAKING_OBJECT_PTR(microdump_process_type_);
1000 988
1001 if (android_build_fp) { 989 if (android_build_fp) {
1002 microdump_build_fingerprint_ = strdup(android_build_fp); 990 microdump_build_fingerprint_ = strdup(android_build_fp);
1003 ANNOTATE_LEAKING_OBJECT_PTR(microdump_build_fingerprint_); 991 ANNOTATE_LEAKING_OBJECT_PTR(microdump_build_fingerprint_);
1004 } 992 }
1005 993
1006 UpdateMinidumpDescriptor(&descriptor); 994 SetMinidumpSanitizationFields(&descriptor, sanitizationInfo);
1007 995
1008 g_microdump = 996 g_microdump =
1009 new ExceptionHandler(descriptor, ShouldGenerateDump, MicrodumpCrashDone, 997 new ExceptionHandler(descriptor, ShouldGenerateDump, MicrodumpCrashDone,
1010 reinterpret_cast<void*>(is_browser_process), 998 reinterpret_cast<void*>(is_browser_process),
1011 true, // Install handlers. 999 true, // Install handlers.
1012 -1); // Server file descriptor. -1 for in-process. 1000 -1); // Server file descriptor. -1 for in-process.
1013 1001
1014 if (process_type != kWebViewSingleProcessType && 1002 if (process_type != kWebViewSingleProcessType &&
1015 process_type != kBrowserProcessType && 1003 process_type != kBrowserProcessType &&
1016 !process_type.empty()) { 1004 !process_type.empty()) {
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 sys__exit(0); 1912 sys__exit(0);
1925 } 1913 }
1926 1914
1927 // Main browser process. 1915 // Main browser process.
1928 if (child <= 0) 1916 if (child <= 0)
1929 return; 1917 return;
1930 (void) HANDLE_EINTR(sys_waitpid(child, nullptr, 0)); 1918 (void) HANDLE_EINTR(sys_waitpid(child, nullptr, 0));
1931 } 1919 }
1932 1920
1933 void InitCrashReporter(const std::string& process_type) { 1921 void InitCrashReporter(const std::string& process_type) {
1922 SanitizationInfo sanitizationInfo;
1923 sanitizationInfo.should_sanitize_dumps = false;
1924 sanitizationInfo.skip_dump_if_principal_mapping_not_referenced = false;
1925 InitCrashReporter(process_type, sanitizationInfo);
1926 }
1927
1928 void InitCrashReporter(const std::string& process_type,
1929 const SanitizationInfo& sanitizationInfo) {
1934 // The maximum lengths specified by breakpad include the trailing NULL, so the 1930 // The maximum lengths specified by breakpad include the trailing NULL, so the
1935 // actual length of the chunk is one less. 1931 // actual length of the chunk is one less.
1936 static_assert(crash_keys::kChunkMaxLength == 63, "kChunkMaxLength mismatch"); 1932 static_assert(crash_keys::kChunkMaxLength == 63, "kChunkMaxLength mismatch");
1937 static_assert(crash_keys::kSmallSize <= crash_keys::kChunkMaxLength, 1933 static_assert(crash_keys::kSmallSize <= crash_keys::kChunkMaxLength,
1938 "crash key chunk size too small"); 1934 "crash key chunk size too small");
1939 #if defined(OS_ANDROID) 1935 #if defined(OS_ANDROID)
1940 // This will guarantee that the BuildInfo has been initialized and subsequent 1936 // This will guarantee that the BuildInfo has been initialized and subsequent
1941 // calls will not require memory allocation. 1937 // calls will not require memory allocation.
1942 base::android::BuildInfo::GetInstance(); 1938 base::android::BuildInfo::GetInstance();
1943 1939
1944 // Handler registration is LIFO. Install the microdump handler first, such 1940 // Handler registration is LIFO. Install the microdump handler first, such
1945 // that if conventional minidump crash reporting is enabled below, it takes 1941 // that if conventional minidump crash reporting is enabled below, it takes
1946 // precedence (i.e. its handler is run first) over the microdump handler. 1942 // precedence (i.e. its handler is run first) over the microdump handler.
1947 InitMicrodumpCrashHandlerIfNecessary(process_type); 1943 InitMicrodumpCrashHandlerIfNecessary(process_type, sanitizationInfo);
1948 #endif 1944 #endif
1949 // Determine the process type and take appropriate action. 1945 // Determine the process type and take appropriate action.
1950 const base::CommandLine& parsed_command_line = 1946 const base::CommandLine& parsed_command_line =
1951 *base::CommandLine::ForCurrentProcess(); 1947 *base::CommandLine::ForCurrentProcess();
1952 if (parsed_command_line.HasSwitch(switches::kDisableBreakpad)) 1948 if (parsed_command_line.HasSwitch(switches::kDisableBreakpad))
1953 return; 1949 return;
1954 1950
1955 if (process_type.empty()) { 1951 if (process_type.empty()) {
1956 bool enable_breakpad = GetCrashReporterClient()->GetCollectStatsConsent() || 1952 bool enable_breakpad = GetCrashReporterClient()->GetCollectStatsConsent() ||
1957 GetCrashReporterClient()->IsRunningUnattended(); 1953 GetCrashReporterClient()->IsRunningUnattended();
1958 enable_breakpad &= 1954 enable_breakpad &=
1959 !parsed_command_line.HasSwitch(switches::kDisableBreakpad); 1955 !parsed_command_line.HasSwitch(switches::kDisableBreakpad);
1960 if (!enable_breakpad) { 1956 if (!enable_breakpad) {
1961 enable_breakpad = parsed_command_line.HasSwitch( 1957 enable_breakpad = parsed_command_line.HasSwitch(
1962 switches::kEnableCrashReporterForTesting); 1958 switches::kEnableCrashReporterForTesting);
1963 } 1959 }
1964 if (!enable_breakpad) { 1960 if (!enable_breakpad) {
1965 VLOG(1) << "Breakpad disabled"; 1961 VLOG(1) << "Breakpad disabled";
1966 return; 1962 return;
1967 } 1963 }
1968 1964
1969 InitCrashKeys(); 1965 InitCrashKeys();
1970 EnableCrashDumping(GetCrashReporterClient()->IsRunningUnattended()); 1966 EnableCrashDumping(GetCrashReporterClient()->IsRunningUnattended(),
1967 sanitizationInfo);
1971 } else if (GetCrashReporterClient()->EnableBreakpadForProcess(process_type)) { 1968 } else if (GetCrashReporterClient()->EnableBreakpadForProcess(process_type)) {
1972 #if defined(OS_ANDROID) 1969 #if defined(OS_ANDROID)
1973 NOTREACHED() << "Breakpad initialized with InitCrashReporter() instead of " 1970 NOTREACHED() << "Breakpad initialized with InitCrashReporter() instead of "
1974 "InitNonBrowserCrashReporter in " << process_type << " process."; 1971 "InitNonBrowserCrashReporter in " << process_type << " process.";
1975 return; 1972 return;
1976 #else 1973 #else
1977 // We might be chrooted in a zygote or renderer process so we cannot call 1974 // We might be chrooted in a zygote or renderer process so we cannot call
1978 // GetCollectStatsConsent because that needs access the the user's home 1975 // GetCollectStatsConsent because that needs access the the user's home
1979 // dir. Instead, we set a command line flag for these processes. 1976 // dir. Instead, we set a command line flag for these processes.
1980 // Even though plugins are not chrooted, we share the same code path for 1977 // Even though plugins are not chrooted, we share the same code path for
1981 // simplicity. 1978 // simplicity.
1982 if (!parsed_command_line.HasSwitch(switches::kEnableCrashReporter)) 1979 if (!parsed_command_line.HasSwitch(switches::kEnableCrashReporter))
1983 return; 1980 return;
1984 1981
1985 InitCrashKeys(); 1982 InitCrashKeys();
1986 SetChannelFromCommandLine(parsed_command_line); 1983 SetChannelFromCommandLine(parsed_command_line);
1987 SetClientIdFromCommandLine(parsed_command_line); 1984 SetClientIdFromCommandLine(parsed_command_line);
1988 EnableNonBrowserCrashDumping(); 1985 EnableNonBrowserCrashDumping();
1989 VLOG(1) << "Non Browser crash dumping enabled for: " << process_type; 1986 VLOG(1) << "Non Browser crash dumping enabled for: " << process_type;
1990 #endif // #if defined(OS_ANDROID) 1987 #endif // #if defined(OS_ANDROID)
1991 } 1988 }
1992 1989
1993 PostEnableBreakpadInitialization(); 1990 PostEnableBreakpadInitialization();
1994 } 1991 }
1995 1992
1996 #if defined(OS_ANDROID) 1993 #if defined(OS_ANDROID)
1997 void InitNonBrowserCrashReporterForAndroid(const std::string& process_type) { 1994 void InitNonBrowserCrashReporterForAndroid(const std::string& process_type) {
1995 SanitizationInfo sanitizationInfo;
1996 sanitizationInfo.should_sanitize_dumps = false;
1997 sanitizationInfo.skip_dump_if_principal_mapping_not_referenced = false;
1998 InitNonBrowserCrashReporterForAndroid(process_type, sanitizationInfo);
1999 }
2000
2001 void InitNonBrowserCrashReporterForAndroid(
2002 const std::string& process_type,
2003 const SanitizationInfo& sanitizationInfo) {
1998 const base::CommandLine* command_line = 2004 const base::CommandLine* command_line =
1999 base::CommandLine::ForCurrentProcess(); 2005 base::CommandLine::ForCurrentProcess();
2000 2006
2001 // Handler registration is LIFO. Install the microdump handler first, such 2007 // Handler registration is LIFO. Install the microdump handler first, such
2002 // that if conventional minidump crash reporting is enabled below, it takes 2008 // that if conventional minidump crash reporting is enabled below, it takes
2003 // precedence (i.e. its handler is run first) over the microdump handler. 2009 // precedence (i.e. its handler is run first) over the microdump handler.
2004 InitMicrodumpCrashHandlerIfNecessary(process_type); 2010 InitMicrodumpCrashHandlerIfNecessary(process_type, sanitizationInfo);
2005 2011
2006 if (command_line->HasSwitch(switches::kEnableCrashReporter)) { 2012 if (command_line->HasSwitch(switches::kEnableCrashReporter)) {
2007 // On Android we need to provide a FD to the file where the minidump is 2013 // On Android we need to provide a FD to the file where the minidump is
2008 // generated as the renderer and browser run with different UIDs 2014 // generated as the renderer and browser run with different UIDs
2009 // (preventing the browser from inspecting the renderer process). 2015 // (preventing the browser from inspecting the renderer process).
2010 int minidump_fd = base::GlobalDescriptors::GetInstance()->MaybeGet( 2016 int minidump_fd = base::GlobalDescriptors::GetInstance()->MaybeGet(
2011 GetCrashReporterClient()->GetAndroidMinidumpDescriptor()); 2017 GetCrashReporterClient()->GetAndroidMinidumpDescriptor());
2012 if (minidump_fd < 0) { 2018 if (minidump_fd < 0) {
2013 NOTREACHED() << "Could not find minidump FD, crash reporting disabled."; 2019 NOTREACHED() << "Could not find minidump FD, crash reporting disabled.";
2014 } else { 2020 } else {
2015 InitCrashKeys(); 2021 InitCrashKeys();
2016 EnableNonBrowserCrashDumping(process_type, minidump_fd); 2022 EnableNonBrowserCrashDumping(process_type, minidump_fd, sanitizationInfo);
2017 // Note: not installing DumpWithoutCrash handler here because browser 2023 // Note: not installing DumpWithoutCrash handler here because browser
2018 // is not set up to receive multiple reports from child process. 2024 // is not set up to receive multiple reports from child process.
2019 } 2025 }
2020 } 2026 }
2021 } 2027 }
2022 2028
2023 // The microdump handler does NOT upload anything. It just dumps out on the 2029 // The microdump handler does NOT upload anything. It just dumps out on the
2024 // system console (logcat) a restricted and serialized variant of a minidump. 2030 // system console (logcat) a restricted and serialized variant of a minidump.
2025 // See crbug.com/410294 for more details. 2031 // See crbug.com/410294 for more details.
2026 void InitMicrodumpCrashHandlerIfNecessary(const std::string& process_type) { 2032 void InitMicrodumpCrashHandlerIfNecessary(
2033 const std::string& process_type,
2034 const SanitizationInfo& sanitizationInfo) {
2027 if (!GetCrashReporterClient()->ShouldEnableBreakpadMicrodumps()) 2035 if (!GetCrashReporterClient()->ShouldEnableBreakpadMicrodumps())
2028 return; 2036 return;
2029 2037
2030 VLOG(1) << "Enabling microdumps crash handler (process_type:" 2038 VLOG(1) << "Enabling microdumps crash handler (process_type:"
2031 << process_type << ")"; 2039 << process_type << ")";
2032 2040
2033 // The exception handler runs in a compromised context and cannot use c_str() 2041 // The exception handler runs in a compromised context and cannot use c_str()
2034 // as that would require the heap. Therefore, we have to guarantee that the 2042 // as that would require the heap. Therefore, we have to guarantee that the
2035 // build fingerprint and product info pointers are always valid. 2043 // build fingerprint and product info pointers are always valid.
2036 const char* product_name = nullptr; 2044 const char* product_name = nullptr;
2037 const char* product_version = nullptr; 2045 const char* product_version = nullptr;
2038 GetCrashReporterClient()->GetProductNameAndVersion(&product_name, 2046 GetCrashReporterClient()->GetProductNameAndVersion(&product_name,
2039 &product_version); 2047 &product_version);
2040 2048
2041 const char* android_build_fp = 2049 const char* android_build_fp =
2042 base::android::BuildInfo::GetInstance()->android_build_fp(); 2050 base::android::BuildInfo::GetInstance()->android_build_fp();
2043 2051
2044 g_microdump_info.Get().Initialize(process_type, product_name, product_version, 2052 g_microdump_info.Get().Initialize(process_type, product_name, product_version,
2045 android_build_fp); 2053 android_build_fp, sanitizationInfo);
2046 } 2054 }
2047 2055
2048 void AddGpuFingerprintToMicrodumpCrashHandler( 2056 void AddGpuFingerprintToMicrodumpCrashHandler(
2049 const std::string& gpu_fingerprint) { 2057 const std::string& gpu_fingerprint) {
2050 g_microdump_info.Get().SetGpuFingerprint(gpu_fingerprint); 2058 g_microdump_info.Get().SetGpuFingerprintForMicrodump(gpu_fingerprint);
2051 } 2059 }
2052 2060
2053 void GenerateMinidumpOnDemandForAndroid(int dump_fd) { 2061 void GenerateMinidumpOnDemandForAndroid(int dump_fd) {
2054 if (dump_fd >= 0) { 2062 if (dump_fd >= 0) {
2055 MinidumpDescriptor minidump_descriptor(dump_fd); 2063 MinidumpDescriptor minidump_descriptor(dump_fd);
2056 minidump_descriptor.set_size_limit(-1); 2064 minidump_descriptor.set_size_limit(-1);
2057 ExceptionHandler(minidump_descriptor, nullptr, MinidumpGenerated, nullptr, 2065 ExceptionHandler(minidump_descriptor, nullptr, MinidumpGenerated, nullptr,
2058 false, -1) 2066 false, -1)
2059 .WriteMinidump(); 2067 .WriteMinidump();
2060 } 2068 }
2061 } 2069 }
2062 2070
2063 void SuppressDumpGeneration() { 2071 void SuppressDumpGeneration() {
2064 g_dumps_suppressed = G_DUMPS_SUPPRESSED_MAGIC; 2072 g_dumps_suppressed = G_DUMPS_SUPPRESSED_MAGIC;
2065 } 2073 }
2066
2067 void SetSkipDumpIfPrincipalMappingNotReferenced(
2068 uintptr_t address_within_principal_mapping) {
2069 g_microdump_info.Get().SetSkipDumpIfPrincipalMappingNotReferenced(
2070 address_within_principal_mapping);
2071 }
2072
2073 void SetShouldSanitizeDumps(bool should_sanitize_dumps) {
2074 g_microdump_info.Get().SetShouldSanitizeDumps(should_sanitize_dumps);
2075 }
2076 #endif // OS_ANDROID 2074 #endif // OS_ANDROID
2077 2075
2078 bool IsCrashReporterEnabled() { 2076 bool IsCrashReporterEnabled() {
2079 return g_is_crash_reporter_enabled; 2077 return g_is_crash_reporter_enabled;
2080 } 2078 }
2081 2079
2082 } // namespace breakpad 2080 } // namespace breakpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698