Skip to content

Instantly share code, notes, and snippets.

@quark-zju
Created April 5, 2014 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quark-zju/9992484 to your computer and use it in GitHub Desktop.
Save quark-zju/9992484 to your computer and use it in GitHub Desktop.
(Linux) Print backtrace
// Link with -rdynamic
#include <execinfo.h>
#include <assert.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
void bt() {
const size_t size = 100;
void *bufs[size];
char **syms;
int n = backtrace(bufs, size), i;
syms = backtrace_symbols(bufs, n);
assert(syms);
for (i = 0; i < n; ++i) {
printf("%s\n", syms[i]);
}
free(syms);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment