Logan Chien | 7fab97f3 | 2015-05-29 15:33:38 | [diff] [blame] | 1 | #include <assert.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <unwind.h> |
| 4 | |
| 5 | #define EXPECTED_NUM_FRAMES 50 |
| 6 | #define NUM_FRAMES_UPPER_BOUND 100 |
| 7 | |
| 8 | _Unwind_Reason_Code callback(_Unwind_Context *context, void *cnt) { |
Jonathan Roelofs | 6e50d93 | 2017-07-06 15:20:12 | [diff] [blame] | 9 | (void)context; |
Logan Chien | 7fab97f3 | 2015-05-29 15:33:38 | [diff] [blame] | 10 | int *i = (int *)cnt; |
| 11 | ++*i; |
| 12 | if (*i > NUM_FRAMES_UPPER_BOUND) { |
| 13 | abort(); |
| 14 | } |
| 15 | return _URC_NO_REASON; |
| 16 | } |
| 17 | |
| 18 | void test_backtrace() { |
| 19 | int n = 0; |
| 20 | _Unwind_Backtrace(&callback, &n); |
| 21 | if (n < EXPECTED_NUM_FRAMES) { |
| 22 | abort(); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | int test(int i) { |
| 27 | if (i == 0) { |
| 28 | test_backtrace(); |
| 29 | return 0; |
| 30 | } else { |
| 31 | return i + test(i - 1); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | int main() { |
| 36 | int total = test(50); |
| 37 | assert(total == 1275); |
| 38 | } |