OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #import <Foundation/Foundation.h> | |
6 #include <mach/task.h> | |
7 #include <stdio.h> | |
8 | |
9 #include "base/logging.h" | |
10 | |
11 // This is just enough of a shim to let the support needed by test_support | |
12 // link. | |
13 | |
14 namespace base { | |
15 namespace debug { | |
16 | |
17 namespace { | |
18 | |
19 void StackDumpSignalHandler(int signal) { | |
20 // TODO(phajdan.jr): Fix async-signal unsafety. | |
21 LOG(ERROR) << "Received signal " << signal; | |
22 NSArray *stack_symbols = [NSThread callStackSymbols]; | |
23 for (NSString* stack_symbol in stack_symbols) { | |
24 fprintf(stderr, "\t%s\n", [stack_symbol UTF8String]); | |
25 } | |
26 _exit(1); | |
27 } | |
28 | |
29 } // namespace | |
30 | |
31 // TODO(phajdan.jr): Deduplicate, see copy in stack_trace_posix.cc. | |
32 bool EnableInProcessStackDumping() { | |
33 // When running in an application, our code typically expects SIGPIPE | |
34 // to be ignored. Therefore, when testing that same code, it should run | |
35 // with SIGPIPE ignored as well. | |
36 struct sigaction action; | |
37 action.sa_handler = SIG_IGN; | |
38 action.sa_flags = 0; | |
39 sigemptyset(&action.sa_mask); | |
40 bool success = (sigaction(SIGPIPE, &action, NULL) == 0); | |
41 | |
42 success &= (signal(SIGILL, &StackDumpSignalHandler) != SIG_ERR); | |
43 success &= (signal(SIGABRT, &StackDumpSignalHandler) != SIG_ERR); | |
44 success &= (signal(SIGFPE, &StackDumpSignalHandler) != SIG_ERR); | |
45 success &= (signal(SIGBUS, &StackDumpSignalHandler) != SIG_ERR); | |
46 success &= (signal(SIGSEGV, &StackDumpSignalHandler) != SIG_ERR); | |
47 success &= (signal(SIGSYS, &StackDumpSignalHandler) != SIG_ERR); | |
48 | |
49 return success; | |
50 } | |
51 | |
52 } // namespace debug | |
53 } // namespace base | |
OLD | NEW |