函数调用栈打印(C语言)

#include 
#include 
#include 

void print_backtrace(void)
{
    void *bt[64];
    char **btsym;
    int i, n;

    n = backtrace(bt, sizeof(bt)/sizeof(bt[0]));
    btsym = backtrace_symbols(bt, n);

    /* get all backtrace, including this function */
    for (i = 0; i < n; i++) {
        printf("%s:backtrace[%d]=%s\n", __FUNCTION__, i, btsym[i]);
    }
    free(btsym);
}

void main(void)
{
    print_backtrace();
}

你可能感兴趣的:(linux,c语言,调用栈打印)