CCTLib
Calling-context and data-object attribution library for Intel Pin
exc_stress_loop.cpp
Go to the documentation of this file.
1 // High-frequency exception loop. Exercises the resolver's static caching
2 // (g_appUnwindGetIP) and asserts that repeated exception CCT unwinds do
3 // not corrupt cctlib state. ITERS bounded so the CCT still fits under
4 // Pin's recursive VisitAllNodesOfSplayTree stack budget at Fini.
5 //
6 // stress_try_marker / stress_catch_marker verify both markers are direct
7 // children of main across many iterations (regression: pending-reset
8 // state must not drift as CCT accumulates).
9 #include <cstdint>
10 #include <cstdio>
11 #define ITERS 5000
12 static volatile uint64_t sink;
13 
14 extern "C" __attribute__((noinline)) void stress_try_marker(uint64_t i) {
15  __asm__ __volatile__("" ::: "memory"); sink ^= i;
16 }
17 extern "C" __attribute__((noinline)) void stress_catch_marker(uint64_t i) {
18  __asm__ __volatile__("" ::: "memory"); sink ^= i << 8;
19 }
20 
21 static void thrower(uint64_t v) { throw v; }
22 
23 int main(int argc, char** argv) {
24  (void)argc; (void)argv;
25  uint64_t sum = 0;
26  for (uint64_t i = 0; i < ITERS; ++i) {
27  try {
28  stress_try_marker(i);
29  thrower(i * 3);
30  } catch (uint64_t v) {
31  stress_catch_marker(i);
32  sum += v;
33  }
34  }
35  sink = sum;
36  fprintf(stderr, "exc_stress_loop: iters=%d sum=%llu\n", ITERS,
37  (unsigned long long)sum);
38  return sum == (uint64_t)ITERS * (ITERS - 1) / 2 * 3 ? 0 : 1;
39 }
#define ITERS
static void thrower(uint64_t v)
int main(int argc, char **argv)
__attribute__((noinline)) void stress_try_marker(uint64_t i)
static volatile uint64_t sink