In plain C:
#include <corkscrew/backtrace.h>
void print_backtrace()
{
backtrace_frame_t frames[256];
ssize_t count = unwind_backtrace(frames, 2, sizeof(frames));
backtrace_symbol_t symbols[count];
get_backtrace_symbols(frames, count, symbols);
for(size_t i = 0; i < count; i++){
char line[1024] = {0};
format_backtrace_line(i, frames + i, symbols +i, line, 1024);
log(LOG_INFO, " #%d %s\n", i, line); /* use your logging here */
}
free_backtrace_symbols(symbols, count);
}
You should link your app with libcorkscrew.
I have removed the call to __cxx_demangle() in system/core/libcorkscrew/demangle.c to simplify linking. It works anyway, you can use the c++filt tool for the demangling.