diff options
Diffstat (limited to 'test/sanitizer_common/TestCases/Linux/signal_trap_handler.cpp')
-rw-r--r-- | test/sanitizer_common/TestCases/Linux/signal_trap_handler.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/sanitizer_common/TestCases/Linux/signal_trap_handler.cpp b/test/sanitizer_common/TestCases/Linux/signal_trap_handler.cpp new file mode 100644 index 000000000..9b4bc067e --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/signal_trap_handler.cpp @@ -0,0 +1,29 @@ +// RUN: %clangxx -O1 %s -o %t && %env_tool_opts=handle_sigtrap=1 %run %t 2>&1 | FileCheck %s + +#include <assert.h> +#include <signal.h> +#include <stdio.h> + +int handled; + +void handler(int signo, siginfo_t *info, void *uctx) { + handled = 1; +} + +int main() { + struct sigaction a = {}, old = {}; + a.sa_sigaction = handler; + a.sa_flags = SA_SIGINFO; + sigaction(SIGTRAP, &a, &old); + + a = {}; + sigaction(SIGTRAP, 0, &a); + assert(a.sa_sigaction == handler); + assert(a.sa_flags & SA_SIGINFO); + + __builtin_debugtrap(); + assert(handled); + fprintf(stderr, "HANDLED %d\n", handled); +} + +// CHECK: HANDLED 1 |