This topic created in 1362 days ago, the information mentioned may be changed or developed.
应用程序蛮复杂的,并且还带多个动态链接库。现在想打印某个函数调用的 backtrace.有方便的办法吗?
在内核中可以调用 dump_stack.应用程序呢?搜索了一下,似乎没有很方便的办法。有个初步的想法是故意触发一个 crash,然后获取 coredump, 最后用 gdb 去看 backtrace.还没实践。
7 replies • 2022-08-21 14:17:50 +08:00
 |
|
5
Madcrow Aug 19, 2022
函数里调用一下:
``` #include <stdio.h> #include <execinfo.h>
void print_trace(void) { char **strings; size_t i, size; enum Constexpr { MAX_SIZE = 1024 }; void *array[MAX_SIZE]; size = backtrace(array, MAX_SIZE); strings = backtrace_symbols(array, size); for (i = 0; i < size; i++) printf("%s\n", strings[i]); puts(""); free(strings); } ```
|
 |
|
6
Inn0Vat10n Aug 19, 2022
简单的方式,while true 或者 sleep, gdb/pstack 看
|