1 // TODO: Investigate these failures 2 // XFAIL: asan, tsan, ubsan 3 4 // TODO: Investigate this failure 5 // XFAIL: 32bits-on-64bits 6 7 #include <assert.h> 8 #include <stdlib.h> 9 #include <unwind.h> 10 11 #define EXPECTED_NUM_FRAMES 50 12 #define NUM_FRAMES_UPPER_BOUND 100 13 14 _Unwind_Reason_Code callback(_Unwind_Context *context, void *cnt) { 15 (void)context; 16 int *i = (int *)cnt; 17 ++*i; 18 if (*i > NUM_FRAMES_UPPER_BOUND) { 19 abort(); 20 } 21 return _URC_NO_REASON; 22 } 23 24 void test_backtrace() { 25 int n = 0; 26 _Unwind_Backtrace(&callback, &n); 27 if (n < EXPECTED_NUM_FRAMES) { 28 abort(); 29 } 30 } 31 32 int test(int i) { 33 if (i == 0) { 34 test_backtrace(); 35 return 0; 36 } else { 37 return i + test(i - 1); 38 } 39 } 40 41 int main(int, char**) { 42 int total = test(50); 43 assert(total == 1275); 44 return 0; 45 } 46