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

Side by Side Diff: handler/main.cc

Issue 1391463002: mac: Add --use-system-default-handler option to crashpad_handler (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: For checkin 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
« no previous file with comments | « handler/crashpad_handler.ad ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 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 <getopt.h> 15 #include <getopt.h>
16 #include <stdlib.h> 16 #include <stdlib.h>
17 17
18 #include <map> 18 #include <map>
19 #include <string> 19 #include <string>
20 20
21 #include "base/files/file_path.h" 21 #include "base/files/file_path.h"
22 #include "base/logging.h" 22 #include "base/logging.h"
23 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/scoped_ptr.h"
24 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "client/crash_report_database.h" 26 #include "client/crash_report_database.h"
27 #include "client/crashpad_client.h"
27 #include "tools/tool_support.h" 28 #include "tools/tool_support.h"
28 #include "handler/crash_report_upload_thread.h" 29 #include "handler/crash_report_upload_thread.h"
29 #include "util/stdlib/map_insert.h" 30 #include "util/stdlib/map_insert.h"
30 #include "util/stdlib/string_number_conversion.h" 31 #include "util/stdlib/string_number_conversion.h"
31 #include "util/string/split_string.h" 32 #include "util/string/split_string.h"
32 #include "util/synchronization/semaphore.h" 33 #include "util/synchronization/semaphore.h"
33 34
34 #if defined(OS_MACOSX) 35 #if defined(OS_MACOSX)
35 #include <libgen.h> 36 #include <libgen.h>
36 #include "handler/mac/crash_report_exception_handler.h" 37 #include "handler/mac/crash_report_exception_handler.h"
(...skipping 11 matching lines...) Expand all
48 49
49 void Usage(const base::FilePath& me) { 50 void Usage(const base::FilePath& me) {
50 fprintf(stderr, 51 fprintf(stderr,
51 "Usage: %" PRFilePath " [OPTION]...\n" 52 "Usage: %" PRFilePath " [OPTION]...\n"
52 "Crashpad's exception handler server.\n" 53 "Crashpad's exception handler server.\n"
53 "\n" 54 "\n"
54 " --annotation=KEY=VALUE set a process annotation in each crash report\n" 55 " --annotation=KEY=VALUE set a process annotation in each crash report\n"
55 " --database=PATH store the crash report database at PATH\n" 56 " --database=PATH store the crash report database at PATH\n"
56 #if defined(OS_MACOSX) 57 #if defined(OS_MACOSX)
57 " --handshake-fd=FD establish communication with the client over FD\n " 58 " --handshake-fd=FD establish communication with the client over FD\n "
59 " --reset-own-crash-exception-port-to-system-default\n"
60 " reset the server's exception handler to default\n "
58 #elif defined(OS_WIN) 61 #elif defined(OS_WIN)
59 " --pipe-name=PIPE communicate with the client over PIPE\n" 62 " --pipe-name=PIPE communicate with the client over PIPE\n"
60 #endif // OS_MACOSX 63 #endif // OS_MACOSX
61 " --url=URL send crash reports to this Breakpad server URL,\n " 64 " --url=URL send crash reports to this Breakpad server URL,\n "
62 " only if uploads are enabled for the database\n" 65 " only if uploads are enabled for the database\n"
63 " --help display this help and exit\n" 66 " --help display this help and exit\n"
64 " --version output version information and exit\n", 67 " --version output version information and exit\n",
65 me.value().c_str()); 68 me.value().c_str());
66 ToolSupport::UsageTail(me); 69 ToolSupport::UsageTail(me);
67 } 70 }
68 71
69 int HandlerMain(int argc, char* argv[]) { 72 int HandlerMain(int argc, char* argv[]) {
70 const base::FilePath argv0( 73 const base::FilePath argv0(
71 ToolSupport::CommandLineArgumentToFilePathStringType(argv[0])); 74 ToolSupport::CommandLineArgumentToFilePathStringType(argv[0]));
72 const base::FilePath me(argv0.BaseName()); 75 const base::FilePath me(argv0.BaseName());
73 76
74 enum OptionFlags { 77 enum OptionFlags {
75 // Long options without short equivalents. 78 // Long options without short equivalents.
76 kOptionLastChar = 255, 79 kOptionLastChar = 255,
77 kOptionAnnotation, 80 kOptionAnnotation,
78 kOptionDatabase, 81 kOptionDatabase,
79 #if defined(OS_MACOSX) 82 #if defined(OS_MACOSX)
80 kOptionHandshakeFD, 83 kOptionHandshakeFD,
84 kOptionResetOwnCrashExceptionPortToSystemDefault,
81 #elif defined(OS_WIN) 85 #elif defined(OS_WIN)
82 kOptionPipeName, 86 kOptionPipeName,
83 #endif // OS_MACOSX 87 #endif // OS_MACOSX
84 kOptionURL, 88 kOptionURL,
85 89
86 // Standard options. 90 // Standard options.
87 kOptionHelp = -2, 91 kOptionHelp = -2,
88 kOptionVersion = -3, 92 kOptionVersion = -3,
89 }; 93 };
90 94
91 struct { 95 struct {
92 std::map<std::string, std::string> annotations; 96 std::map<std::string, std::string> annotations;
93 std::string url; 97 std::string url;
94 const char* database; 98 const char* database;
95 #if defined(OS_MACOSX) 99 #if defined(OS_MACOSX)
96 int handshake_fd; 100 int handshake_fd;
101 bool reset_own_crash_exception_port_to_system_default;
97 #elif defined(OS_WIN) 102 #elif defined(OS_WIN)
98 std::string pipe_name; 103 std::string pipe_name;
99 #endif 104 #endif
100 } options = {}; 105 } options = {};
101 #if defined(OS_MACOSX) 106 #if defined(OS_MACOSX)
102 options.handshake_fd = -1; 107 options.handshake_fd = -1;
108 options.reset_own_crash_exception_port_to_system_default = false;
103 #endif 109 #endif
104 110
105 const option long_options[] = { 111 const option long_options[] = {
106 {"annotation", required_argument, nullptr, kOptionAnnotation}, 112 {"annotation", required_argument, nullptr, kOptionAnnotation},
107 {"database", required_argument, nullptr, kOptionDatabase}, 113 {"database", required_argument, nullptr, kOptionDatabase},
108 #if defined(OS_MACOSX) 114 #if defined(OS_MACOSX)
109 {"handshake-fd", required_argument, nullptr, kOptionHandshakeFD}, 115 {"handshake-fd", required_argument, nullptr, kOptionHandshakeFD},
116 {"reset-own-crash-exception-port-to-system-default",
117 no_argument,
118 nullptr,
119 kOptionResetOwnCrashExceptionPortToSystemDefault},
110 #elif defined(OS_WIN) 120 #elif defined(OS_WIN)
111 {"pipe-name", required_argument, nullptr, kOptionPipeName}, 121 {"pipe-name", required_argument, nullptr, kOptionPipeName},
112 #endif 122 #endif
113 {"url", required_argument, nullptr, kOptionURL}, 123 {"url", required_argument, nullptr, kOptionURL},
114 {"help", no_argument, nullptr, kOptionHelp}, 124 {"help", no_argument, nullptr, kOptionHelp},
115 {"version", no_argument, nullptr, kOptionVersion}, 125 {"version", no_argument, nullptr, kOptionVersion},
116 {nullptr, 0, nullptr, 0}, 126 {nullptr, 0, nullptr, 0},
117 }; 127 };
118 128
119 int opt; 129 int opt;
(...skipping 20 matching lines...) Expand all
140 #if defined(OS_MACOSX) 150 #if defined(OS_MACOSX)
141 case kOptionHandshakeFD: { 151 case kOptionHandshakeFD: {
142 if (!StringToNumber(optarg, &options.handshake_fd) || 152 if (!StringToNumber(optarg, &options.handshake_fd) ||
143 options.handshake_fd < 0) { 153 options.handshake_fd < 0) {
144 ToolSupport::UsageHint(me, 154 ToolSupport::UsageHint(me,
145 "--handshake-fd requires a file descriptor"); 155 "--handshake-fd requires a file descriptor");
146 return EXIT_FAILURE; 156 return EXIT_FAILURE;
147 } 157 }
148 break; 158 break;
149 } 159 }
160 case kOptionResetOwnCrashExceptionPortToSystemDefault: {
161 options.reset_own_crash_exception_port_to_system_default = true;
162 break;
163 }
150 #elif defined(OS_WIN) 164 #elif defined(OS_WIN)
151 case kOptionPipeName: { 165 case kOptionPipeName: {
152 options.pipe_name = optarg; 166 options.pipe_name = optarg;
153 break; 167 break;
154 } 168 }
155 #endif // OS_MACOSX 169 #endif // OS_MACOSX
156 case kOptionURL: { 170 case kOptionURL: {
157 options.url = optarg; 171 options.url = optarg;
158 break; 172 break;
159 } 173 }
(...skipping 29 matching lines...) Expand all
189 if (!options.database) { 203 if (!options.database) {
190 ToolSupport::UsageHint(me, "--database is required"); 204 ToolSupport::UsageHint(me, "--database is required");
191 return EXIT_FAILURE; 205 return EXIT_FAILURE;
192 } 206 }
193 207
194 if (argc) { 208 if (argc) {
195 ToolSupport::UsageHint(me, nullptr); 209 ToolSupport::UsageHint(me, nullptr);
196 return EXIT_FAILURE; 210 return EXIT_FAILURE;
197 } 211 }
198 212
213 #if defined(OS_MACOSX)
214 if (options.reset_own_crash_exception_port_to_system_default) {
215 CrashpadClient::UseSystemDefaultHandler();
216 }
217 #endif
218
199 ExceptionHandlerServer exception_handler_server; 219 ExceptionHandlerServer exception_handler_server;
200 220
201 #if defined(OS_MACOSX) 221 #if defined(OS_MACOSX)
202 CloseStdinAndStdout(); 222 CloseStdinAndStdout();
203 ChildPortHandshake::RunClient(options.handshake_fd, 223 ChildPortHandshake::RunClient(options.handshake_fd,
204 exception_handler_server.receive_port(), 224 exception_handler_server.receive_port(),
205 MACH_MSG_TYPE_MAKE_SEND); 225 MACH_MSG_TYPE_MAKE_SEND);
206 #endif // OS_MACOSX 226 #endif // OS_MACOSX
207 227
208 scoped_ptr<CrashReportDatabase> database( 228 scoped_ptr<CrashReportDatabase> database(
(...skipping 30 matching lines...) Expand all
239 259
240 #if defined(OS_MACOSX) 260 #if defined(OS_MACOSX)
241 int main(int argc, char* argv[]) { 261 int main(int argc, char* argv[]) {
242 return crashpad::HandlerMain(argc, argv); 262 return crashpad::HandlerMain(argc, argv);
243 } 263 }
244 #elif defined(OS_WIN) 264 #elif defined(OS_WIN)
245 int wmain(int argc, wchar_t* argv[]) { 265 int wmain(int argc, wchar_t* argv[]) {
246 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::HandlerMain); 266 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::HandlerMain);
247 } 267 }
248 #endif // OS_MACOSX 268 #endif // OS_MACOSX
OLDNEW
« no previous file with comments | « handler/crashpad_handler.ad ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698