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

Side by Side Diff: handler/mac/crash_report_exception_handler.cc

Issue 997713002: Allow exception forwarding to the system’s native crash reporter to be disabled (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Remove unused function declaration Created 5 years, 9 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
« no previous file with comments | « client/crashpad_info.cc ('k') | snapshot/mac/crashpad_info_client_options.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 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 "handler/mac/crash_report_exception_handler.h" 15 #include "handler/mac/crash_report_exception_handler.h"
16 16
17 #include <servers/bootstrap.h> 17 #include <servers/bootstrap.h>
18 18
19 #include <vector> 19 #include <vector>
20 20
21 #include "base/logging.h" 21 #include "base/logging.h"
22 #include "base/mac/mach_logging.h" 22 #include "base/mac/mach_logging.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "minidump/minidump_file_writer.h" 24 #include "minidump/minidump_file_writer.h"
25 #include "snapshot/mac/crashpad_info_client_options.h"
25 #include "snapshot/mac/process_snapshot_mac.h" 26 #include "snapshot/mac/process_snapshot_mac.h"
26 #include "util/file/file_writer.h" 27 #include "util/file/file_writer.h"
27 #include "util/mach/exc_client_variants.h" 28 #include "util/mach/exc_client_variants.h"
28 #include "util/mach/exception_behaviors.h" 29 #include "util/mach/exception_behaviors.h"
29 #include "util/mach/mach_extensions.h" 30 #include "util/mach/mach_extensions.h"
30 #include "util/mach/scoped_task_suspend.h" 31 #include "util/mach/scoped_task_suspend.h"
32 #include "util/misc/tri_state.h"
31 #include "util/misc/uuid.h" 33 #include "util/misc/uuid.h"
32 34
33 namespace crashpad { 35 namespace crashpad {
34 36
35 namespace { 37 namespace {
36 38
37 // Calls CrashReportDatabase::ErrorWritingCrashReport() upon destruction unless 39 // Calls CrashReportDatabase::ErrorWritingCrashReport() upon destruction unless
38 // disarmed by calling Disarm(). Armed upon construction. 40 // disarmed by calling Disarm(). Armed upon construction.
39 class CallErrorWritingCrashReport { 41 class CallErrorWritingCrashReport {
40 public: 42 public:
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return KERN_FAILURE; 111 return KERN_FAILURE;
110 } 112 }
111 113
112 ScopedTaskSuspend suspend(task); 114 ScopedTaskSuspend suspend(task);
113 115
114 ProcessSnapshotMac process_snapshot; 116 ProcessSnapshotMac process_snapshot;
115 if (!process_snapshot.Initialize(task)) { 117 if (!process_snapshot.Initialize(task)) {
116 return KERN_FAILURE; 118 return KERN_FAILURE;
117 } 119 }
118 120
119 if (!process_snapshot.InitializeException(thread, 121 CrashpadInfoClientOptions client_options;
120 exception, 122 process_snapshot.GetCrashpadOptions(&client_options);
121 code, 123
122 code_count, 124 if (client_options.crashpad_handler_behavior != TriState::kDisabled) {
123 *flavor, 125 if (!process_snapshot.InitializeException(thread,
124 old_state, 126 exception,
125 old_state_count)) { 127 code,
126 return KERN_FAILURE; 128 code_count,
129 *flavor,
130 old_state,
131 old_state_count)) {
132 return KERN_FAILURE;
133 }
134
135 process_snapshot.SetAnnotationsSimpleMap(*process_annotations_);
136
137 CrashReportDatabase::NewReport* new_report;
138 CrashReportDatabase::OperationStatus database_status =
139 database_->PrepareNewCrashReport(&new_report);
140 if (database_status != CrashReportDatabase::kNoError) {
141 return KERN_FAILURE;
142 }
143
144 CallErrorWritingCrashReport call_error_writing_crash_report(database_,
145 new_report);
146
147 WeakFileHandleFileWriter file_writer(new_report->handle);
148
149 MinidumpFileWriter minidump;
150 minidump.InitializeFromSnapshot(&process_snapshot);
151 if (!minidump.WriteEverything(&file_writer)) {
152 return KERN_FAILURE;
153 }
154
155 call_error_writing_crash_report.Disarm();
156
157 UUID uuid;
158 database_status = database_->FinishedWritingCrashReport(new_report, &uuid);
159 if (database_status != CrashReportDatabase::kNoError) {
160 return KERN_FAILURE;
161 }
162
163 upload_thread_->ReportPending();
127 } 164 }
128 165
129 process_snapshot.SetAnnotationsSimpleMap(*process_annotations_); 166 if (client_options.system_crash_reporter_forwarding != TriState::kDisabled &&
130 167 (exception == EXC_CRASH ||
131 CrashReportDatabase::NewReport* new_report; 168 exception == EXC_RESOURCE ||
132 CrashReportDatabase::OperationStatus database_status = 169 exception == EXC_GUARD)) {
133 database_->PrepareNewCrashReport(&new_report);
134 if (database_status != CrashReportDatabase::kNoError) {
135 return KERN_FAILURE;
136 }
137
138 CallErrorWritingCrashReport call_error_writing_crash_report(database_,
139 new_report);
140
141 WeakFileHandleFileWriter file_writer(new_report->handle);
142
143 MinidumpFileWriter minidump;
144 minidump.InitializeFromSnapshot(&process_snapshot);
145 if (!minidump.WriteEverything(&file_writer)) {
146 return KERN_FAILURE;
147 }
148
149 call_error_writing_crash_report.Disarm();
150
151 UUID uuid;
152 database_status = database_->FinishedWritingCrashReport(new_report, &uuid);
153 if (database_status != CrashReportDatabase::kNoError) {
154 return KERN_FAILURE;
155 }
156
157 upload_thread_->ReportPending();
158
159 if (exception == EXC_CRASH ||
160 exception == EXC_RESOURCE ||
161 exception == EXC_GUARD) {
162 // Don’t forward simulated exceptions such as kMachExceptionSimulated to the 170 // Don’t forward simulated exceptions such as kMachExceptionSimulated to the
163 // system crash reporter. Only forward the types of exceptions that it would 171 // system crash reporter. Only forward the types of exceptions that it would
164 // receive under normal conditions. Although the system crash reporter is 172 // receive under normal conditions. Although the system crash reporter is
165 // able to deal with other exceptions including simulated ones, forwarding 173 // able to deal with other exceptions including simulated ones, forwarding
166 // them to the system crash reporter could present the system’s crash UI for 174 // them to the system crash reporter could present the system’s crash UI for
167 // processes that haven’t actually crashed, and could result in reports not 175 // processes that haven’t actually crashed, and could result in reports not
168 // actually associated with crashes being sent to the operating system 176 // actually associated with crashes being sent to the operating system
169 // vendor. 177 // vendor.
170 mach_port_t system_crash_reporter_port; 178 mach_port_t system_crash_reporter_port;
171 const char kSystemCrashReporterServiceName[] = "com.apple.ReportCrash"; 179 const char kSystemCrashReporterServiceName[] = "com.apple.ReportCrash";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 &new_state_forward_count); 215 &new_state_forward_count);
208 MACH_LOG_IF(WARNING, kr != KERN_SUCCESS, kr) 216 MACH_LOG_IF(WARNING, kr != KERN_SUCCESS, kr)
209 << "UniversalExceptionRaise " << kSystemCrashReporterServiceName; 217 << "UniversalExceptionRaise " << kSystemCrashReporterServiceName;
210 } 218 }
211 } 219 }
212 220
213 return ExcServerSuccessfulReturnValue(behavior, false); 221 return ExcServerSuccessfulReturnValue(behavior, false);
214 } 222 }
215 223
216 } // namespace crashpad 224 } // namespace crashpad
OLDNEW
« no previous file with comments | « client/crashpad_info.cc ('k') | snapshot/mac/crashpad_info_client_options.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698