annotate libunwind/test/libunwind_01.pass.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 79ff65ed7e25
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 #include <libunwind.h>
anatofuz
parents:
diff changeset
2 #include <stdlib.h>
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 void backtrace(int lower_bound) {
anatofuz
parents:
diff changeset
5 unw_context_t context;
anatofuz
parents:
diff changeset
6 unw_getcontext(&context);
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 unw_cursor_t cursor;
anatofuz
parents:
diff changeset
9 unw_init_local(&cursor, &context);
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 int n = 0;
anatofuz
parents:
diff changeset
12 do {
anatofuz
parents:
diff changeset
13 ++n;
anatofuz
parents:
diff changeset
14 if (n > 100) {
anatofuz
parents:
diff changeset
15 abort();
anatofuz
parents:
diff changeset
16 }
anatofuz
parents:
diff changeset
17 } while (unw_step(&cursor) > 0);
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 if (n < lower_bound) {
anatofuz
parents:
diff changeset
20 abort();
anatofuz
parents:
diff changeset
21 }
anatofuz
parents:
diff changeset
22 }
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 void test1(int i) {
anatofuz
parents:
diff changeset
25 backtrace(i);
anatofuz
parents:
diff changeset
26 }
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 void test2(int i, int j) {
anatofuz
parents:
diff changeset
29 backtrace(i);
anatofuz
parents:
diff changeset
30 test1(j);
anatofuz
parents:
diff changeset
31 }
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 void test3(int i, int j, int k) {
anatofuz
parents:
diff changeset
34 backtrace(i);
anatofuz
parents:
diff changeset
35 test2(j, k);
anatofuz
parents:
diff changeset
36 }
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 void test_no_info() {
anatofuz
parents:
diff changeset
39 unw_context_t context;
anatofuz
parents:
diff changeset
40 unw_getcontext(&context);
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 unw_cursor_t cursor;
anatofuz
parents:
diff changeset
43 unw_init_local(&cursor, &context);
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 unw_proc_info_t info;
anatofuz
parents:
diff changeset
46 int ret = unw_get_proc_info(&cursor, &info);
anatofuz
parents:
diff changeset
47 if (ret != UNW_ESUCCESS)
anatofuz
parents:
diff changeset
48 abort();
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 // Set the IP to an address clearly outside any function.
anatofuz
parents:
diff changeset
51 unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)0);
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 ret = unw_get_proc_info(&cursor, &info);
anatofuz
parents:
diff changeset
54 if (ret != UNW_ENOINFO)
anatofuz
parents:
diff changeset
55 abort();
anatofuz
parents:
diff changeset
56 }
anatofuz
parents:
diff changeset
57
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
58 int main(int, char**) {
150
anatofuz
parents:
diff changeset
59 test1(1);
anatofuz
parents:
diff changeset
60 test2(1, 2);
anatofuz
parents:
diff changeset
61 test3(1, 2, 3);
anatofuz
parents:
diff changeset
62 test_no_info();
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
63 return 0;
150
anatofuz
parents:
diff changeset
64 }