zoukankan      html  css  js  c++  java
  • linux之backtrace

    backtrace用于打印函数调用堆栈

    /*******************************************************************************
    * File Name        : backtrace.c
    * Author        : zjw
    * Email            : zjw_0722@163.com
    * Create Time    : 2015年03月30日 星期一 09时44分15秒
    *******************************************************************************/
    #include <execinfo.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    void print_trace()
    {
        void *array[10];
        int size = 0;
        char **strings = NULL;
        int i = 0;
    
        size = backtrace(array, 10);
        strings = backtrace_symbols(array, size);
        if (strings == NULL)
        {
            perror("backtrace_symbols");
            exit(-1);
        }
    
        printf("Obtained %zd stack frames.
    ", size);
    
        for (i = 0; i < size; i++)
        {
            printf("%s
    ", strings[i]);
        }
    
        free(strings);
        strings = NULL;
    }
    
    void dump_function()
    {
        print_trace();
    }
    
    int main(int argc, char **argv)
    {
        dump_function();
    
        return 0;
    }
  • 相关阅读:
    Python 函数 -range()
    Python 函数 -xrange()
    Python 函数 -globals()
    Python 函数-max()
    Python 函数 -hasattr()
    Python 函数 memoryview()
    Python函数 hash()
    QAQ
    Õ() Big-O-notation
    一道有趣的条件概率题
  • 原文地址:https://www.cnblogs.com/lit10050528/p/4377228.html
Copyright © 2011-2022 走看看