-
Notifications
You must be signed in to change notification settings - Fork 1
/
unwind.c
61 lines (50 loc) · 1.54 KB
/
unwind.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include "llco.h"
#define STKSZ 32768
void cleanup(void *stk, size_t stksz, void *udata) {
printf("== CLEANUP ==\n");
free(stk);
}
bool symbol(struct llco_symbol *sym, void *udata) {
printf("== UNWIND ==\n");
printf(" cfa: %p\n", sym->cfa);
printf(" ip: %p\n", sym->ip);
printf(" fname: %s\n", sym->fname);
printf(" fbase: %p\n", sym->fbase);
printf(" sname: %s\n", sym->sname);
printf(" saddr: %p\n", sym->saddr);
return true;
}
__attribute__((noinline)) void func4(int x) {
printf("func4 (%d)\n", x);
printf("nsymbols: %d\n", llco_unwind(symbol, 0));
// _Unwind_Backtrace(btfnc, NULL);
}
__attribute__((noinline)) void func3(int x) { printf("func3\n"); func4(x); }
__attribute__((noinline)) void func2(int x) { printf("func2\n"); func3(x); }
__attribute__((noinline)) void func1(int x) { printf("func1\n"); func2(x); }
// __attribute__((noinline))
void entry(void *udata) {
printf("== COROUTINE ==\n");
func1(10);
printf("== SWITCH TO MAIN ==\n");
llco_switch(0, true);
}
int main(void) {
printf("%s\n", llco_method(0));
printf("== MAIN ==\n");
struct llco_desc desc = {
.stack = malloc(STKSZ),
.stack_size = STKSZ,
.entry = entry,
.cleanup = cleanup,
.udata = (void*)1,
};
llco_start(&desc, false);
printf("== EXIT ==\n");
printf("nsymbols: %d\n", llco_unwind(symbol, 0));
return 0;
}