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.
5 #import <Foundation/Foundation.h>
9 #include "base/logging.h"
11 // This is just enough of a shim to let the support needed by test_support
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]);
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;
39 sigemptyset(&action.sa_mask);
40 bool success = (sigaction(SIGPIPE, &action, NULL) == 0);
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);