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

Side by Side Diff: tools/catch_exception_tool.cc

Issue 775943005: UniversalMachExcServer: eliminate multiple implementation inheritance (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years 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 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,
(...skipping 29 matching lines...) Expand all
40 40
41 struct Options { 41 struct Options {
42 std::string file_path; 42 std::string file_path;
43 std::string mach_service; 43 std::string mach_service;
44 FILE* file; 44 FILE* file;
45 int timeout_secs; 45 int timeout_secs;
46 MachMessageServer::Nonblocking nonblocking; 46 MachMessageServer::Nonblocking nonblocking;
47 MachMessageServer::Persistent persistent; 47 MachMessageServer::Persistent persistent;
48 }; 48 };
49 49
50 class ExceptionServer : public UniversalMachExcServer { 50 class ExceptionServer : public UniversalMachExcServer::Interface {
51 public: 51 public:
52 ExceptionServer(const Options& options, 52 ExceptionServer(const Options& options,
53 const std::string& me, 53 const std::string& me,
54 int* exceptions_handled) 54 int* exceptions_handled)
55 : UniversalMachExcServer(), 55 : UniversalMachExcServer::Interface(),
56 options_(options), 56 options_(options),
57 me_(me), 57 me_(me),
58 exceptions_handled_(exceptions_handled) {} 58 exceptions_handled_(exceptions_handled) {}
59 59
60 // UniversalMachExcServer::Interface:
60 virtual kern_return_t CatchMachException( 61 virtual kern_return_t CatchMachException(
61 exception_behavior_t behavior, 62 exception_behavior_t behavior,
62 exception_handler_t exception_port, 63 exception_handler_t exception_port,
63 thread_t thread, 64 thread_t thread,
64 task_t task, 65 task_t task,
65 exception_type_t exception, 66 exception_type_t exception,
66 const mach_exception_data_type_t* code, 67 const mach_exception_data_type_t* code,
67 mach_msg_type_number_t code_count, 68 mach_msg_type_number_t code_count,
68 thread_state_flavor_t* flavor, 69 thread_state_flavor_t* flavor,
69 const natural_t* old_state, 70 const natural_t* old_state,
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 file_owner.reset(fopen(options.file_path.c_str(), "a")); 269 file_owner.reset(fopen(options.file_path.c_str(), "a"));
269 if (!file_owner.get()) { 270 if (!file_owner.get()) {
270 PLOG(ERROR) << "fopen " << options.file_path; 271 PLOG(ERROR) << "fopen " << options.file_path;
271 return EXIT_FAILURE; 272 return EXIT_FAILURE;
272 } 273 }
273 options.file = file_owner.get(); 274 options.file = file_owner.get();
274 } 275 }
275 276
276 int exceptions_handled = 0; 277 int exceptions_handled = 0;
277 ExceptionServer exception_server(options, me, &exceptions_handled); 278 ExceptionServer exception_server(options, me, &exceptions_handled);
279 UniversalMachExcServer universal_mach_exc_server(&exception_server);
278 280
279 // Assume that if persistent mode has been requested, it’s desirable to ignore 281 // Assume that if persistent mode has been requested, it’s desirable to ignore
280 // large messages and keep running. 282 // large messages and keep running.
281 MachMessageServer::ReceiveLarge receive_large = 283 MachMessageServer::ReceiveLarge receive_large =
282 (options.persistent == MachMessageServer::kPersistent) 284 (options.persistent == MachMessageServer::kPersistent)
283 ? MachMessageServer::kReceiveLargeIgnore 285 ? MachMessageServer::kReceiveLargeIgnore
284 : MachMessageServer::kReceiveLargeError; 286 : MachMessageServer::kReceiveLargeError;
285 287
286 mach_msg_timeout_t timeout_ms = options.timeout_secs 288 mach_msg_timeout_t timeout_ms = options.timeout_secs
287 ? options.timeout_secs * 1000 289 ? options.timeout_secs * 1000
288 : MACH_MSG_TIMEOUT_NONE; 290 : MACH_MSG_TIMEOUT_NONE;
289 291
290 mach_msg_return_t mr = MachMessageServer::Run(&exception_server, 292 mach_msg_return_t mr = MachMessageServer::Run(&universal_mach_exc_server,
291 service_port, 293 service_port,
292 MACH_MSG_OPTION_NONE, 294 MACH_MSG_OPTION_NONE,
293 options.persistent, 295 options.persistent,
294 options.nonblocking, 296 options.nonblocking,
295 receive_large, 297 receive_large,
296 timeout_ms); 298 timeout_ms);
297 if (mr == MACH_RCV_TIMED_OUT && options.timeout_secs && options.persistent && 299 if (mr == MACH_RCV_TIMED_OUT && options.timeout_secs && options.persistent &&
298 exceptions_handled) { 300 exceptions_handled) {
299 // This is not an error: when exiting on timeout during persistent 301 // This is not an error: when exiting on timeout during persistent
300 // processing and at least one exception was handled, it’s considered a 302 // processing and at least one exception was handled, it’s considered a
301 // success. 303 // success.
302 } else if (mr != MACH_MSG_SUCCESS) { 304 } else if (mr != MACH_MSG_SUCCESS) {
303 MACH_LOG(ERROR, mr) << "MachMessageServer::Run"; 305 MACH_LOG(ERROR, mr) << "MachMessageServer::Run";
304 return EXIT_FAILURE; 306 return EXIT_FAILURE;
305 } 307 }
306 308
307 return EXIT_SUCCESS; 309 return EXIT_SUCCESS;
308 } 310 }
309 311
310 } // namespace 312 } // namespace
311 } // namespace crashpad 313 } // namespace crashpad
312 314
313 int main(int argc, char* argv[]) { 315 int main(int argc, char* argv[]) {
314 return crashpad::CatchExceptionToolMain(argc, argv); 316 return crashpad::CatchExceptionToolMain(argc, argv);
315 } 317 }
OLDNEW
« no previous file with comments | « snapshot/mac/mach_o_image_annotations_reader_test.cc ('k') | util/mach/exc_client_variants_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698