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

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

Issue 1356383002: win: Implement CRASHPAD_SIMULATE_CRASH() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 5 years, 2 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 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,
(...skipping 22 matching lines...) Expand all
33 upload_thread_(upload_thread), 33 upload_thread_(upload_thread),
34 process_annotations_(process_annotations) { 34 process_annotations_(process_annotations) {
35 } 35 }
36 36
37 CrashReportExceptionHandler::~CrashReportExceptionHandler() { 37 CrashReportExceptionHandler::~CrashReportExceptionHandler() {
38 } 38 }
39 39
40 void CrashReportExceptionHandler::ExceptionHandlerServerStarted() { 40 void CrashReportExceptionHandler::ExceptionHandlerServerStarted() {
41 } 41 }
42 42
43 unsigned int CrashReportExceptionHandler::ExceptionHandlerServerException( 43 void CrashReportExceptionHandler::ExceptionHandlerServerException(
44 HANDLE process, 44 HANDLE process,
45 WinVMAddress exception_information_address) { 45 WinVMAddress exception_information_address) {
46 const unsigned int kFailedTerminationCode = 0xffff7002;
47
48 ScopedProcessSuspend suspend(process); 46 ScopedProcessSuspend suspend(process);
49 47
50 ProcessSnapshotWin process_snapshot; 48 ProcessSnapshotWin process_snapshot;
51 if (!process_snapshot.Initialize(process, 49 if (!process_snapshot.Initialize(process,
52 ProcessSuspensionState::kSuspended)) { 50 ProcessSuspensionState::kSuspended)) {
53 LOG(WARNING) << "ProcessSnapshotWin::Initialize failed"; 51 LOG(WARNING) << "ProcessSnapshotWin::Initialize failed";
54 return kFailedTerminationCode; 52 return;
55 } 53 }
56 54
57 if (!process_snapshot.InitializeException(exception_information_address)) { 55 if (!process_snapshot.InitializeException(exception_information_address)) {
58 LOG(WARNING) << "ProcessSnapshotWin::InitializeException failed"; 56 LOG(WARNING) << "ProcessSnapshotWin::InitializeException failed";
59 return kFailedTerminationCode; 57 return;
60 } 58 }
61 59
62 // Now that we have the exception information, even if something else fails we
63 // can terminate the process with the correct exit code.
64 const unsigned int termination_code =
65 process_snapshot.Exception()->Exception();
66
67 CrashpadInfoClientOptions client_options; 60 CrashpadInfoClientOptions client_options;
68 process_snapshot.GetCrashpadOptions(&client_options); 61 process_snapshot.GetCrashpadOptions(&client_options);
69 if (client_options.crashpad_handler_behavior != TriState::kDisabled) { 62 if (client_options.crashpad_handler_behavior != TriState::kDisabled) {
70 UUID client_id; 63 UUID client_id;
71 Settings* const settings = database_->GetSettings(); 64 Settings* const settings = database_->GetSettings();
72 if (settings) { 65 if (settings) {
73 // If GetSettings() or GetClientID() fails, something else will log a 66 // If GetSettings() or GetClientID() fails, something else will log a
74 // message and client_id will be left at its default value, all zeroes, 67 // message and client_id will be left at its default value, all zeroes,
75 // which is appropriate. 68 // which is appropriate.
76 settings->GetClientID(&client_id); 69 settings->GetClientID(&client_id);
77 } 70 }
78 71
79 process_snapshot.SetClientID(client_id); 72 process_snapshot.SetClientID(client_id);
80 process_snapshot.SetAnnotationsSimpleMap(*process_annotations_); 73 process_snapshot.SetAnnotationsSimpleMap(*process_annotations_);
81 74
82 CrashReportDatabase::NewReport* new_report; 75 CrashReportDatabase::NewReport* new_report;
83 CrashReportDatabase::OperationStatus database_status = 76 CrashReportDatabase::OperationStatus database_status =
84 database_->PrepareNewCrashReport(&new_report); 77 database_->PrepareNewCrashReport(&new_report);
85 if (database_status != CrashReportDatabase::kNoError) { 78 if (database_status != CrashReportDatabase::kNoError) {
86 LOG(ERROR) << "PrepareNewCrashReport failed"; 79 LOG(ERROR) << "PrepareNewCrashReport failed";
87 return termination_code; 80 return;
88 } 81 }
89 82
90 process_snapshot.SetReportID(new_report->uuid); 83 process_snapshot.SetReportID(new_report->uuid);
91 84
92 CrashReportDatabase::CallErrorWritingCrashReport 85 CrashReportDatabase::CallErrorWritingCrashReport
93 call_error_writing_crash_report(database_, new_report); 86 call_error_writing_crash_report(database_, new_report);
94 87
95 WeakFileHandleFileWriter file_writer(new_report->handle); 88 WeakFileHandleFileWriter file_writer(new_report->handle);
96 89
97 MinidumpFileWriter minidump; 90 MinidumpFileWriter minidump;
98 minidump.InitializeFromSnapshot(&process_snapshot); 91 minidump.InitializeFromSnapshot(&process_snapshot);
99 if (!minidump.WriteEverything(&file_writer)) { 92 if (!minidump.WriteEverything(&file_writer)) {
100 LOG(ERROR) << "WriteEverything failed"; 93 LOG(ERROR) << "WriteEverything failed";
101 return termination_code; 94 return;
102 } 95 }
103 96
104 call_error_writing_crash_report.Disarm(); 97 call_error_writing_crash_report.Disarm();
105 98
106 UUID uuid; 99 UUID uuid;
107 database_status = database_->FinishedWritingCrashReport(new_report, &uuid); 100 database_status = database_->FinishedWritingCrashReport(new_report, &uuid);
108 if (database_status != CrashReportDatabase::kNoError) { 101 if (database_status != CrashReportDatabase::kNoError) {
109 LOG(ERROR) << "FinishedWritingCrashReport failed"; 102 LOG(ERROR) << "FinishedWritingCrashReport failed";
110 return termination_code; 103 return;
111 } 104 }
112 105
113 upload_thread_->ReportPending(); 106 upload_thread_->ReportPending();
114 } 107 }
115
116 return termination_code;
117 } 108 }
118 109
119 } // namespace crashpad 110 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698