#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int j, nptrs;
void *buffer[100];
char **strings;
nptrs = backtrace(buffer, 100);
printf("haha backtrace() returned %d addresses\n", nptrs);
strings = backtrace_symbols(buffer, nptrs);
if (strings == NULL) {
perror("backtrace_symbols");
exit(EXIT_FAILURE);
}
for (j = 0; j < nptrs; j++)
printf("haha %s\n", strings[j]);
free(strings);
Makefile加入:
CFLAGS += -rdynamic
沒有留言:
張貼留言