Logan Chien | 9f323e0 | 2015-05-29 15:33:38 +0000 | [diff] [blame] | 1 | #include <libunwind.h> |
| 2 | #include <stdlib.h> |
| 3 | |
| 4 | void backtrace(int lower_bound) { |
| 5 | unw_context_t context; |
| 6 | unw_getcontext(&context); |
| 7 | |
| 8 | unw_cursor_t cursor; |
| 9 | unw_init_local(&cursor, &context); |
| 10 | |
| 11 | int n = 0; |
| 12 | do { |
| 13 | ++n; |
| 14 | if (n > 100) { |
| 15 | abort(); |
| 16 | } |
| 17 | } while (unw_step(&cursor) > 0); |
| 18 | |
| 19 | if (n < lower_bound) { |
| 20 | abort(); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | void test1(int i) { |
| 25 | backtrace(i); |
| 26 | } |
| 27 | |
| 28 | void test2(int i, int j) { |
| 29 | backtrace(i); |
| 30 | test1(j); |
| 31 | } |
| 32 | |
| 33 | void test3(int i, int j, int k) { |
| 34 | backtrace(i); |
| 35 | test2(j, k); |
| 36 | } |
| 37 | |
| 38 | int main() { |
| 39 | test1(1); |
| 40 | test2(1, 2); |
| 41 | test3(1, 2, 3); |
| 42 | } |