static void DaoStackTrace( int sig ) { #ifdef TRACE_ON void *array[128]; int size = backtrace(array, 128); char **strings = backtrace_symbols(array, size); int i; printf( "ERROR: program failed with segmentation error!\n" ); printf( "The calling stack for the error:\n" ); for(i = 0; i < size; ++i) printf("%s\n", strings[i]); free(strings); #else printf( "ERROR: program failed with segmentation error!\n" ); #endif fflush( stdout ); exit( sig ); }
std::string stack_trace() { std::ostringstream buffer; void *stack[CPP2PY_TRACE_MAX_FRAMES + 1]; std::size_t depth = backtrace(stack, CPP2PY_TRACE_MAX_FRAMES + 1); if (!depth) buffer << " empty " << std::endl; else { char **symbols = backtrace_symbols(stack, depth); for (std::size_t i = 1; i < depth; ++i) { std::string symbol = symbols[i]; std::istringstream iss(symbol); std::vector<std::string> strs{std::istream_iterator<std::string>{iss}, std::istream_iterator<std::string>{}}; for (auto const &x : strs) buffer << " " << demangle(x); buffer << std::endl; } free(symbols); } return buffer.str(); }
void show_stackframe() { void *trace[32]; char **messages = (char **)NULL; int i, trace_size = 0; trace_size = backtrace(trace, 32); messages = backtrace_symbols(trace, trace_size); if( messages ) { debug( 0, L"Backtrace:" ); for( i=0; i<trace_size; i++ ) { fwprintf( stderr, L"%s\n", messages[i]); } free( messages ); } }
static void ReportProfileSample(int, siginfo_t *, void *) { #if 0 // Print stack trace if context is unknown #if 0 && defined(PBRT_IS_OSX) static std::atomic<int> foo(20); if (ProfilerState == 0 && --foo == 0) { void* callstack[128]; int i, frames = backtrace(callstack, 128); char** strs = backtrace_symbols(callstack, frames); for (i = 0; i < frames; ++i) { printf("%s\n", strs[i]); } free(strs); foo = 20; } #endif #endif if (profileSamples) profileSamples[ProfilerState]++; }
void do_backtrace( int signum, void *ip ) { #ifndef __CYGWIN__ void *array[100]; size_t size; char **strings; size_t i; char *name; static char *unknown = "unknown"; if( ip ) { /* This was a signal, so print the thread name */ name = thread_name( pthread_self() ); if( !name ) { name = unknown; } LogPrint( LOG_DEBUG, "Thread: %s backtrace", name ); } else { name = NULL; } size = backtrace( array, 100 ); #if 0 /* replace the sigaction/pthread_kill with the caller's address */ if( ip ) { array[1] = ip; } #endif strings = backtrace_symbols( array, size ); LogPrint( LOG_DEBUG, "%s%sObtained %zd stack frames.", (name ? name : ""), (name ? ": " : ""), size ); for( i = 0; i < size; i++ ) { LogPrint( LOG_DEBUG, "%s%s%s", (name ? name : ""), (name? ": " : ""), strings[i] ); } free( strings ); #endif }
char * mono_exception_handle_get_native_backtrace (MonoExceptionHandle exc) { #ifdef HAVE_BACKTRACE_SYMBOLS MonoDomain *domain; MonoArrayHandle arr = MONO_HANDLE_NEW(MonoArray, NULL); int i, len; GString *text; char **messages; MONO_HANDLE_GET (arr, exc, native_trace_ips); if (MONO_HANDLE_IS_NULL(arr)) return g_strdup (""); domain = mono_domain_get (); len = mono_array_handle_length (arr); text = g_string_new_len (NULL, len * 20); uint32_t gchandle; gpointer *addr = MONO_ARRAY_HANDLE_PIN (arr, gpointer, 0, &gchandle); MONO_ENTER_GC_SAFE; messages = backtrace_symbols (addr, len); MONO_EXIT_GC_SAFE; mono_gchandle_free_internal (gchandle); for (i = 0; i < len; ++i) { gpointer ip; MONO_HANDLE_ARRAY_GETVAL (ip, arr, gpointer, i); MonoJitInfo *ji = mono_jit_info_table_find (domain, ip); if (ji) { char *msg = mono_debug_print_stack_frame (mono_jit_info_get_method (ji), (char*)ip - (char*)ji->code_start, domain); g_string_append_printf (text, "%s\n", msg); g_free (msg); } else { g_string_append_printf (text, "%s\n", messages [i]); } } g_free (messages); return g_string_free (text, FALSE); #else return g_strdup (""); #endif }
static void log_stack_trace(void) { #if defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) void *array[24]; size_t size; char **strings; size_t i; size = backtrace(array, sizeof(array)/sizeof(array[0])); strings = backtrace_symbols(array, size); w_log(W_LOG_ERR, "Fatal error detected at:\n"); for (i = 0; i < size; i++) { w_log(W_LOG_ERR, "%s\n", strings[i]); } free(strings); #endif }
static void show_backtrace() { void *buff[100]; char **symbl; int nb_addr; int a; memset(&buff[0], 0, 100 * sizeof(void*)); if (!(nb_addr = backtrace(buff, 100)) || !(symbl = backtrace_symbols(buff, nb_addr))) return ; a = 0; fprintf(stderr, "%s\n", BTRACE); while (a < nb_addr) { fprintf(stderr, "%s\n", symbl[a]); ++a; } }
void stack_trace(void) { #ifndef HAVE_BACKTRACE fputs("This platform doesn't support backtrace() yet.\n", stderr); #else void *trace[100]; char **messages = NULL; int i; int trace_size = 0; trace_size = backtrace(trace, sizeof(trace) / sizeof(trace[0])); messages = backtrace_symbols(trace, trace_size); fprintf(stderr, "======== Stack trace ========\n"); for (i = 1; i < trace_size; ++i) { fprintf(stderr, "%s\n", messages[i]); } #endif }
static void output_backtrace_mom (momout_t *pout, void **bbuf, int depth, int lev) { assert (pout && pout->mout_magic == MOM_MOUT_MAGIC); FILE *out = pout->mout_file; if (!out) return; char **backsyms = backtrace_symbols (bbuf, depth); if (MOM_UNLIKELY (!backsyms)) MOM_FATAPRINTF ("backtrace failing for depth %d, level %d", depth, lev); for (unsigned ix = 0; ix < (unsigned) depth; ix++) { MOM_OUT (pout, MOMOUT_LITERAL ("#"), MOMOUT_DEC_INT ((int) ix), MOMOUT_LITERAL (": "), MOMOUT_LITERALV ((const char *) backsyms[ix]), MOMOUT_NEWLINE ()); } free (backsyms); }
void StackTraceUtils::getStackTrace(StackTraceHandler &handler) { if (impl_ == NULL) { return; } const size_t maxCallstackDepth = 30; void *stack[maxCallstackDepth]; DynamicLockGuard<util::Mutex> guard( impl_ == NULL ? NULL : &impl_->mutex_); #ifdef _WIN32 if (impl_->captureStackBackTraceFunc_ == NULL) { return; } const int skipSize = 3; int callStackSize = impl_->captureStackBackTraceFunc_( skipSize, maxCallstackDepth, stack, NULL); for(int i = 0; i < callStackSize; ++i) { impl_->getSymbolName(handler, stack[i]); } #else int callStackSize = backtrace(stack, maxCallstackDepth); char **symbols = backtrace_symbols(stack, callStackSize); if (symbols == NULL) { return; } try { for (int i = 0; i < callStackSize; i++) { impl_->getSymbolName(handler, symbols[i]); } } catch (...) { ::free(symbols); throw; } ::free(symbols); #endif }
int diag_backtrace(diag_output_t *o, diag_backtrace_param_t *p, diag_context_t *c) { void *pointers[DIAG_BT_LIMIT]; int count; int size; char **strings; int i; if (p->backtrace_count && p->backtrace_count < DIAG_BT_LIMIT) { count = p->backtrace_count; } else { count = DIAG_BT_LIMIT; } size = backtrace(pointers, DIAG_BT_LIMIT); if (size > 0) { if (o->output_mode == DIAG_WRITE_FD) { /* XXX we won't be able to filter out diag_backtrace() */ backtrace_symbols_fd(pointers, size, o->outfile); } else { strings = backtrace_symbols(pointers, size); for (i = 0; i < size && count; i++) { char buf[256] = {0}; if (strstr(strings[i], "diag_backtrace")) { continue; } format_frameinfo(strings[i], p->backtrace_fields, buf, sizeof buf); o->output_fn(o->user_data, buf); count--; } free(strings); } } return 0; }
EAPI char * ecore_timer_dump(void) { #ifdef WANT_ECORE_TIMER_DUMP Eina_Strbuf *result; char *out; Ecore_Timer *tm; Eina_List *tmp = NULL; int living_timer = 0; int unknow_timer = 0; _ecore_lock(); result = eina_strbuf_new(); EINA_INLIST_FOREACH(timers, tm) tmp = eina_list_sorted_insert(tmp, _ecore_timer_cmp, tm); EINA_LIST_FREE(tmp, tm) { char **strings; int j; if (!tm->frozen && !tm->delete_me) living_timer++; strings = backtrace_symbols((void **)tm->timer_bt, tm->timer_bt_num); if (tm->timer_bt_num <= 0 || strings == NULL) { unknow_timer++; continue; } eina_strbuf_append_printf(result, "*** timer: %f ***\n", tm->in); if (tm->frozen) eina_strbuf_append(result, "FROZEN\n"); if (tm->delete_me) eina_strbuf_append(result, "DELETED\n"); for (j = 0; j < tm->timer_bt_num; j++) eina_strbuf_append_printf(result, "%s\n", strings[j]); free(strings); }
inline void DumpBacktrace(std::ostream& out, unsigned skip = 0) { static const size_t maxSize = 100; void *array[maxSize]; int size = backtrace(array, maxSize); if (size <= 0) return; boost::scoped_array<char*> symbols(backtrace_symbols(array, size)); if (!symbols) return; for (int i = skip; i < size; ++i) { std::string symbol(symbols[i]); std::string::size_type pos = symbol.find('('); std::string path(symbol, 0, pos); std::string mangled(symbol, pos + 1, symbol.find(')') - pos - 1); std::string offset; pos = mangled.find('+'); if (pos != std::string::npos) { offset.assign(mangled, pos + 1, mangled.length() - pos); mangled.erase(pos); } pos = symbol.find('['); std::string address(symbol, pos + 1, symbol.find(']', pos) - pos - 1); out << std::left << std::setw(3) << (i - skip + 1); boost::scoped_array<char> demangled(abi:: __cxa_demangle(mangled.c_str(), nullptr, nullptr, nullptr)); out << path << " "; if (demangled.get()) out << demangled.get() << " "; else if (!mangled.empty()) out << mangled << " "; if (!offset.empty()) out << "[+" << offset << "] "; out << "[" << address << "]" << std::endl; } }
static void stack_trace(int sig, siginfo_t *info, void *secret) { #ifdef REG_PC ucontext_t *uc = (ucontext_t *)secret; #else /* not used */ (void)secret; #endif /* Do something useful with siginfo_t */ char buf[256]; snprintf(buf, sizeof(buf), "Got signal %d, faulty address is %p, " "from %p", sig, info->si_addr, #ifdef REG_PC (void*)uc->uc_mcontext.gregs[REG_PC]); #else /* TODO: need to handle compilers other than GCC */ __builtin_return_address(0)); #endif syslog(LOG_INFO, "%s", buf); void *trace[30]; char **messages = (char **)NULL; int i; int trace_size = 0; trace_size = backtrace(trace, 30); /* overwrite sigaction with caller's address */ #ifdef REG_PC trace[1] = (void *) uc->uc_mcontext.gregs[REG_PC]; #else /* TODO: need to handle compilers other than GCC */ trace[1] = __builtin_return_address(0); #endif messages = backtrace_symbols(trace, trace_size); if (messages) { /* skip first stack frame (points here) */ for (i = 1; i < trace_size; ++i) syslog(LOG_INFO, "%s", messages[i]); free(messages); } }
/** * Get a stack trace, ignoring the first "offset" symbols. */ std::string GetStackTrace(uint32_t offset) { void *stackTrace[128]; int stackSize = backtrace(stackTrace, 128); char **mangledSymbols = backtrace_symbols(stackTrace, stackSize); std::stringstream trace; for(int i = offset; i < stackSize; i++) { // Only print recursive functions once in a row. if(i == 0 ||stackTrace[i] != stackTrace[i - 1]) { trace << "\tat " << demangle(mangledSymbols[i]) << std::endl; } } free(mangledSymbols); return trace.str(); }
void px4_backtrace() { #ifdef __PX4_POSIX void *buffer[10]; char **callstack; int bt_size; int idx; bt_size = backtrace(buffer, 10); callstack = backtrace_symbols(buffer, bt_size); PX4_INFO("Backtrace: %d", bt_size); for (idx = 0; idx < bt_size; idx++) { PX4_INFO("%s", callstack[idx]); } free(callstack); #endif }
/* * ut_dump_backtrace -- dump stacktrace to error log using libc's backtrace */ void ut_dump_backtrace(void) { int j, nptrs; void *buffer[SIZE]; char **strings; nptrs = backtrace(buffer, SIZE); strings = backtrace_symbols(buffer, nptrs); if (strings == NULL) { ERR("!backtrace_symbols"); return; } for (j = 0; j < nptrs; j++) ERR("%u: %s", j, strings[j]); free(strings); }
/* * Dump the stack of the calling core. */ static void nvme_dump_stack(void) { #define BACKTRACE_SIZE 256 void *func[BACKTRACE_SIZE]; char **symb = NULL; int size; size = backtrace(func, BACKTRACE_SIZE); symb = backtrace_symbols(func, size); if (symb == NULL) return; while (size > 0) { nvme_crit("%d: [%s]\n", size, symb[size - 1]); size --; } free(symb); }
/* TODO: Make an async-safe alternative */ void xseg_printtrace(void) { void *array[20]; char **bt; size_t size; int i; pid_t tid = __get_id(); size = backtrace(array, 20); bt = backtrace_symbols(array, size); if (!bt) { return; } XSEGLOG2(I, "Backtrace of tid %d:", tid); for (i = 0; i < size; ++i) { XSEGLOG2(I, "\t%s", bt[i]); } }
/** FIXME: Use REG_RIP on IA64 */ void print_backtrace(void) { static const char start[] = "BACKTRACE ------------\n"; static const char end[] = "----------------------\n"; int bt_size; char **bt_syms; int i; bt_size = backtrace(bt, 1024); bt_syms = backtrace_symbols(bt, bt_size); full_write(STDERR_FILENO, start, strlen(start)); for (i = 2; i < bt_size; i++) { size_t len = strlen(bt_syms[i]); full_write(STDERR_FILENO, bt_syms[i], len); full_write(STDERR_FILENO, "\n", 1); } full_write(STDERR_FILENO, end, strlen(end)); free(bt_syms); }
void print_trace(int nSig) { printf("print_trace: got signal %d\n", nSig); void *array[32]; /* Array to store backtrace symbols */ size_t size; /* To store the exact no of values stored */ char **strings; /* To store functions from the backtrace list in ARRAY */ size_t nCnt; size = backtrace(array, 32); strings = backtrace_symbols(array, size); /* prints each string of function names of trace*/ for (nCnt = 0; nCnt < size; nCnt++) fprintf(stderr, "%s\n", strings[nCnt]); abort(); }
void panda_show_backtrace() { int j, nptrs; void *buffer[32]; char **strings; nptrs = backtrace(buffer, 32); strings = backtrace_symbols(buffer, nptrs); if (strings == NULL) { perror("backtrace_symbols"); return; } printf("-----------------------------------------------------------\n"); for (j = 0; j < nptrs; j++) printf("%s\n", strings[j]); printf("-----------------------------------------------------------\n"); free(strings); }
/** print stack **/ void print_stack() { // prepare symbols void* arr[64] = {0}; const size_t s =backtrace(arr, 64); if(s == 0) { OutputDebug("print stack error"); return; } char** syms =backtrace_symbols(arr, s); // make str OutputDebug("print stack:\n"); OutputDebug("\tstack size is %d.\n", (int)s); if(syms) { for(size_t i=0; i<s; ++i) { OutputDebug("\t[%d] %s\n", (int)i, (syms[i] ? syms[i] : "")); } free(syms); } }
std::string get_symbols(void * const *address,int size) { char ** ptr = backtrace_symbols(address,size); try { if(ptr==0) return std::string(); std::string res; for(int i=0;i<size;i++) { res+=ptr[i]; res+='\n'; } free(ptr); ptr = 0; return res; } catch(...) { free(ptr); throw; } }
ch_string get_stack_trace( const ch_string & file, int line ) { bj_ostr_stream result; result << "Call Stack from " << file << ":" << line << "\n"; const size_t k_max_depth = 100; void *stack_addrs[k_max_depth]; size_t stack_depth; char **stack_strings; stack_depth = backtrace( stack_addrs, k_max_depth ); stack_strings = backtrace_symbols( stack_addrs, stack_depth ); for( size_t i = 1; i < stack_depth; ++i ) { //result << " " << demangle_cxx_name( stack_strings[i] ) << "\n"; result << " " << stack_strings[i] << bj_eol; } result << "(to see full call names link with -rdynamic option)" << bj_eol; std::free( stack_strings ); return result.str(); }
static void crash_sig(int signum) { void* array[10]; size_t size; char** strings; size_t i; signal(signum, SIG_DFL); size = backtrace(array, sizeof(array) / sizeof(void*)); strings = (char**)backtrace_symbols(array, size); for (i = 0; i < size; ++i) { fprintf(stderr, "%s\n", strings[i]); } free(strings); exit(1); }
static void sigprocess(int sig) { int ii = 0; void *tracePtrs[16]; int count = backtrace(tracePtrs, 16); char **funcNames = backtrace_symbols(tracePtrs, count); for(ii = 0; ii < count; ii++) printf("%s\n", funcNames[ii]); free(funcNames); fflush(stderr); printf("##signal %d caught\n", sig); fflush(stdout); if(sig == SIGINT || sig == SIGSEGV || sig == SIGTERM) { appExit(); } exit(1); }
/* Obtain a backtrace and print it to stdout. */ void print_trace (void) { void *array[10]; size_t size; char **strings; size_t i; size = backtrace (array, 10); strings = backtrace_symbols (array, size); printf ("Obtained %zd stack frames.\n", size); for (i = 0; i < size; i++) printf ("%s\n", strings[i]); free (strings); prev_handler(); abort(); }
void trace() { // 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); void* callstack[128]; int i, frames = backtrace(callstack, 128); char** strs = backtrace_symbols(callstack, frames); for (i = 0; i < frames; ++i) { printf("%s\n", strs[i]); } free(strs); }