| 8 | #include "libmm.h" |
| 9 | |
| 10 | static void stacktrace(void) |
| 11 | { |
| 12 | unw_cursor_t cursor; |
| 13 | unw_word_t off, pc; |
| 14 | char name[128]; |
| 15 | int ret; |
| 16 | ucontext_t context; |
| 17 | |
| 18 | if (getcontext(&context) < 0) { |
| 19 | printf("getcontext error\r\n"); |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | ret = unw_init_local(&cursor, (unw_context_t*) &context); |
| 24 | if (ret != 0) { |
| 25 | printf("unw_init_local error, ret=%d\r\n", ret); |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | while (unw_step(&cursor) > 0) { |
| 30 | ret = unw_get_proc_name(&cursor, name, sizeof(name), &off); |
| 31 | if (ret != 0) { |
| 32 | printf("unw_get_proc_name error =%d\n", ret); |
| 33 | } else { |
| 34 | unw_get_reg(&cursor, UNW_REG_IP, &pc); |
| 35 | printf("0x%lx:(%s()+0x%lx)\n", pc, name, off); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | static size_t total_size = 0; |
| 41 | static bool __check = false; |