Created
          November 16, 2020 14:51 
        
      - 
      
 - 
        
Save devymex/95a51cd12afdb6f0d0357f97cb71b79c to your computer and use it in GitHub Desktop.  
    trace call stack
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <execinfo.h> | |
| void print_trace (void) { | |
| void *ppArrays[256]; | |
| int nTraceNum = backtrace(ppArrays, sizeof(ppArrays) / sizeof(ppArrays[0])); | |
| char **ppSymbols = backtrace_symbols(ppArrays, nTraceNum); | |
| if (ppSymbols != NULL) { | |
| printf("Obtained %d stack frames.\n", nTraceNum); | |
| for (int i = 0; i < nTraceNum; i++) { | |
| printf("%s\n", ppSymbols[i]); | |
| } | |
| } | |
| free(ppSymbols); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment