unix_backtrace.h (377B)
1 #pragma once 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <errno.h> 6 #include <unistd.h> 7 #include <execinfo.h> 8 9 inline void print_backtrace_and_abort() { 10 int error = errno; 11 printf( "errno = %d: %s\n", error, strerror( error ) ); 12 13 void * stack[ 128 ]; 14 const int stack_size = backtrace( stack, 128 ); 15 backtrace_symbols_fd( stack, stack_size, STDERR_FILENO ); 16 abort(); 17 }