CCTLib
Calling-context and data-object attribution library for Intel Pin
rec_exception.cpp
Go to the documentation of this file.
1 // Exception thrown from deep in direct-self-recursion, caught at the
2 // outermost frame. Verifies that cctlib's existing exception-unwind
3 // path (RememberUnwindGetIPFromImage / FindNearestCallerCoveringIP)
4 // continues to work when the recursive routine's activations have
5 // been collapsed to a single physical TraceNode. A regression would
6 // either strand tlsCurrentTraceNode inside the collapsed frame after
7 // the catch, or fail to find the handler at all.
8 #include <cstdint>
9 #include <cstdio>
10 #include <cstdlib>
11 
12 static volatile int64_t sink;
13 
14 struct Deep {};
15 
16 static void descend(int n) {
17  if (n <= 0) throw Deep{};
18  descend(n - 1);
19 }
20 
21 int main(int argc, char** argv) {
22  (void)argc; (void)argv;
23  int caught = 0;
24  try {
25  // Depth 15 -> comfortably under cctlib's MAX_CCT_PRINT_DEPTH=20.
26  descend(15);
27  } catch (const Deep&) {
28  caught = 1;
29  }
30  sink ^= caught;
31  fprintf(stderr, "rec_exception: caught=%d sink=%llx\n",
32  caught, (unsigned long long)sink);
33  return caught ? 0 : 1;
34 }
int main(int argc, char **argv)
static volatile int64_t sink
static void descend(int n)