blob: a0efd1df79fa45d325daba8da1857eaead333029 [file] [log] [blame]
Logan Chien7fab97f32015-05-29 15:33:381#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 Roelofs6e50d932017-07-06 15:20:129 (void)context;
Logan Chien7fab97f32015-05-29 15:33:3810 int *i = (int *)cnt;
11 ++*i;
12 if (*i > NUM_FRAMES_UPPER_BOUND) {
13 abort();
14 }
15 return _URC_NO_REASON;
16}
17
18void test_backtrace() {
19 int n = 0;
20 _Unwind_Backtrace(&callback, &n);
21 if (n < EXPECTED_NUM_FRAMES) {
22 abort();
23 }
24}
25
26int test(int i) {
27 if (i == 0) {
28 test_backtrace();
29 return 0;
30 } else {
31 return i + test(i - 1);
32 }
33}
34
35int main() {
36 int total = test(50);
37 assert(total == 1275);
38}