CCTLib
Calling-context and data-object attribution library for Intel Pin
exc_uncaught_tn.cpp
Go to the documentation of this file.
1 // Regression test for the uncaught-exception path in cctlib.
2 //
3 // When an exception has no handler, libgcc's phase-1 search returns
4 // _URC_END_OF_STACK -> phase 2 is never entered -> _Unwind_SetIP is
5 // never called -> cctlib's CaptureLandingPadTarget never fires and
6 // no pending landing-pad reset is armed. The tool must nonetheless
7 // survive the uncaught-exception path (which continues through
8 // std::terminate) without crashing on stale exception TLS.
9 //
10 // The victim throws, no one catches, and set_terminate installs a
11 // handler that _exit(0)s so the OS-visible exit is clean while the
12 // tool still had to survive the uncaught-exception unwind path.
13 //
14 // If the NULL guard is ever removed, this test will surface it as
15 // SIGSEGV-in-tool.
16 #include <cstdint>
17 #include <cstdio>
18 #include <cstdlib>
19 #include <exception>
20 #include <unistd.h>
21 
22 static void my_terminate() {
23  // Uncaught-exception path exercised. Exit cleanly so the harness
24  // asserts rc == 0.
25  fprintf(stderr, "exc_uncaught_tn: my_terminate reached; exiting 0\n");
26  _exit(0);
27 }
28 
29 static void thrower() {
30  volatile int local = 42;
31  throw local;
32 }
33 
34 int main(int argc, char** argv) {
35  (void)argc; (void)argv;
36  std::set_terminate(&my_terminate);
37  thrower(); // never returns
38  return 99; // unreachable
39 }
int main(int argc, char **argv)
static void thrower()
static void my_terminate()