Skip to content

Instantly share code, notes, and snippets.

@Musinux
Created May 15, 2020 08:31
Show Gist options
  • Save Musinux/6c8a7d1ca50c31309a9d6745b842ad3b to your computer and use it in GitHub Desktop.
Save Musinux/6c8a7d1ca50c31309a9d6745b842ad3b to your computer and use it in GitHub Desktop.

Revisions

  1. Musinux created this gist May 15, 2020.
    13 changes: 13 additions & 0 deletions utils.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    #include <unistd.h>
    #include <execinfo.h>

    void print_backtrace () {
    void *array[10];
    size_t size;

    // get void*'s for all entries on the stack
    size = backtrace(array, 10);

    // print out all the frames to stderr
    backtrace_symbols_fd(array, size, STDERR_FILENO);
    }
    6 changes: 6 additions & 0 deletions utils.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    #ifndef UTILS_H
    #define UTILS_H

    void print_backtrace ();

    #endif /* ifndef UTILS_H */