-
Notifications
You must be signed in to change notification settings - Fork 2
/
test1.c
40 lines (34 loc) · 765 Bytes
/
test1.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
/* Simple test, takes from libunwind docs. */
#include <stdio.h>
#include <string.h>
#define UNW_LOCAL_ONLY
#include <libunwind.h>
static void show_backtrace (void) {
unw_cursor_t cursor; unw_context_t uc;
unw_word_t ip, sp;
unw_getcontext(&uc);
unw_init_local(&cursor, &uc);
while (unw_step(&cursor) > 0) {
unw_word_t offp;
char buf[1024];
strcpy(buf, "");
unw_get_proc_name(&cursor, buf, sizeof(buf), &offp);
unw_get_reg(&cursor, UNW_REG_IP, &ip);
unw_get_reg(&cursor, UNW_REG_SP, &sp);
printf ("ip = %lx, sp = %lx <%s>+%d\n", (long) ip, (long) sp, buf, (long)offp);
}
}
static void
func(int x)
{
if (x)
func(x - 1);
else
show_backtrace();
}
int
main(int argc, char *argv[])
{
func(argc);
return 0;
}