static void sigprof_handler(int sig_nr, siginfo_t* info, void *ucontext) { void* stack[MAX_STACK_DEPTH]; int saved_errno = errno; stack[0] = GetPC((ucontext_t*)ucontext); int depth = frame_forcer(get_stack_trace(stack+1, MAX_STACK_DEPTH-1, ucontext)); depth++; // To account for pc value in stack[0]; prof_write_stacktrace(stack, depth, 1); errno = saved_errno; }
/** * Invokes realloc() and perform error checking. * @param nmemb [in] see calloc() man pages. * @param size [in] see calloc() man pages. * @return pointer to the allocated memory. */ void *realloc_check(void *ptr, size_t nmemb, size_t size) { void *ret = realloc(ptr, nmemb * size); if ((ret == NULL) && ((nmemb * size) != 0)) { LOGFATAL("out of memory - realloc nmemb %zd, size %zd.\n", nmemb, size); LOGFATAL("Shutting down eucanetd.\n"); get_stack_trace(); exit(1); } return (ret); }
/** * Appends pointer ptr to the end of the given pointer array arr. The array should * have been malloc'd. The allocation is adjusted as needed. * @param arr [i/o] arr pointer to an array of pointers * @param max_arr [i/o] max_arr the number of array entries. * @param ptr (in] pointer to be appended to the array. * @return 0 on success. 1 otherwise. */ void *append_ptrarr(void *arr, int *max_arr, void *ptr) { arr = EUCA_REALLOC(arr, *max_arr + 1, sizeof (void *)); if (arr == NULL) { LOGFATAL("out of memory: failed to (re)allocate array of pointers\n"); LOGFATAL("Shutting down eucanetd.\n"); get_stack_trace(); exit (1); } void **parr = arr; parr[*max_arr] = ptr; (*max_arr)++; return (arr); }
std::string Exception::get_message_and_stack_trace() const { std::vector<std::string> stack_trace = get_stack_trace(); std::string text = message; for (auto & elem : stack_trace) { #ifdef WIN32 text += string_format("\r\n at %1", elem); #else text += string_format("\n at %1", elem); #endif } return text; }
std::string Exception::get_message_and_stack_trace() const { std::vector<std::string> stack_trace = get_stack_trace(); std::string text = message; for (size_t i = 0; i < stack_trace.size(); i++) { #ifdef WIN32 text += string_format("\r\n at %1", stack_trace[i]); #else text += string_format("\n at %1", stack_trace[i]); #endif } return text; }
InternalError::InternalError(const String& str) : Error( _("An internal error occured:\n\n") + str + _("\n") _("Please save your work (use 'save as' to so you don't overwrite things)\n") _("and restart Magic Set Editor.\n\n") _("You should leave a bug report on http://magicseteditor.sourceforge.net/\n") _("Press Ctrl+C to copy this message to the clipboard.") ) { // add a stacktrace const String stack_trace = get_stack_trace(); if (!stack_trace.empty()) { message << _("\n\nCall stack:\n") << stack_trace; } }
bool print_backtrace( const ch_string & file, int line ) { bj_out << get_stack_trace(file, line) << bj_eol; return true; }