| 1 |
// RUN: %clangxx -O1 %s -o %t && %env_tool_opts=handle_sigtrap=1 %run %t 2>&1 | FileCheck %s |
| 2 |
|
| 3 |
// __builtin_debugtrap() does not raise SIGTRAP on these platforms. |
| 4 |
// UNSUPPORTED: target=s390{{.*}} |
| 5 |
|
| 6 |
#include <assert.h> |
| 7 |
#include <signal.h> |
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
|
| 11 |
int in_handler; |
| 12 |
|
| 13 |
void handler(int signo, siginfo_t *info, void *uctx) { |
| 14 |
fprintf(stderr, "in_handler: %d\n", in_handler); |
| 15 |
fflush(stderr); |
| 16 |
// CHECK: in_handler: 1 |
| 17 |
_Exit(0); |
| 18 |
} |
| 19 |
|
| 20 |
int main() { |
| 21 |
struct sigaction a = {}, old = {}; |
| 22 |
a.sa_sigaction = handler; |
| 23 |
a.sa_flags = SA_SIGINFO; |
| 24 |
sigaction(SIGTRAP, &a, &old); |
| 25 |
|
| 26 |
a = {}; |
| 27 |
sigaction(SIGTRAP, 0, &a); |
| 28 |
assert(a.sa_sigaction == handler); |
| 29 |
assert(a.sa_flags & SA_SIGINFO); |
| 30 |
|
| 31 |
in_handler = 1; |
| 32 |
// Check that signal handler is not postponed by sanitizer. |
| 33 |
// Don't use raise here as it calls any signal handler immediately. |
| 34 |
__builtin_debugtrap(); |
| 35 |
in_handler = 0; |
| 36 |
|
| 37 |
fprintf(stderr, "UNREACHABLE\n"); |
| 38 |
return 1; |
| 39 |
} |