summaryrefslogtreecommitdiff
path: root/test/sanitizer_common/TestCases/Linux/signal_trap_handler.cpp
blob: 9b4bc067e49205eedc744d77e0891b2fa3dc757f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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