Esempio n. 1
1
File: test.c Progetto: hajuuk/R7000
/* FIXME: not portable beyond linux */
static void
error_handler(int signum)
{
#ifdef __linux__
	void *buf[32];

    /* FIXME: the symbols aren't printing */
	printf("***** ERROR: Program received signal %d *****\n", signum);
	backtrace_symbols_fd(buf, sizeof(buf) / sizeof(void *), 2);
#else
	printf("***** ERROR: Program received signal %d *****\n", signum);
#endif
    exit(1);
}
Esempio n. 2
1
void SigHandler(int sig) {
    void* backtrace_buffer[100];
    int num;
    int fd;

    signal(sig, SIG_DFL);
    fd = open("crash.txt",O_WRONLY|O_CREAT|O_APPEND|O_SYNC,0666);
    if (fd != -1) {
        write(fd, "--- New crash backtrace begins here ---\n", 24);
        num = backtrace(backtrace_buffer, 100);
        backtrace_symbols_fd(backtrace_buffer, num, fd);
        backtrace_symbols_fd(backtrace_buffer, num, 2);
        close(fd);
    }

    // Now we try to display a MessageBox; this might fail and also
    // corrupt the heap, but since we're dying anyway that's no big
    // deal

    ClientUI::MessageBox("The client has just crashed!\nFile a bug report and\nattach the file called 'crash.txt'\nif necessary", true);

    raise(sig);
}
Esempio n. 3
0
FCITX_EXPORT_API
void
fcitx_utils_backtrace()
{
#if defined(ENABLE_BACKTRACE)
    void *array[32];

    size_t size;

    size = backtrace(array, 32);
    backtrace_symbols_fd(array, size, STDERR_FILENO);
#endif
}
Esempio n. 4
0
/**
 * sim_debug_print_bt:
 *
 */
void
sim_debug_print_bt ()
{
	gint fd, nptrs;
	gpointer buffer [100];

	fd = g_open (SIM_DEBUG_ERR_FILE, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
	nptrs = backtrace (buffer, 100);
	backtrace_symbols_fd (buffer, nptrs, fd);
    (void)close (fd);

	return;
}
void myHandler(int i){
#ifdef ENABLE_BACKTRACE
  int nptrs;
  void * buffer[BT_SIZE];
#endif

  printf("(%d) signal %d received.\n", getpid(), i);
#ifdef ENABLE_BACKTRACE
  nptrs = backtrace (buffer, BT_SIZE);
  backtrace_symbols_fd ( buffer, nptrs, STDOUT_FILENO );
  printf("\n");
#endif
}
Esempio n. 6
0
void verr_print_stacktrace() {
#ifdef DEBUG
  char** symbols = backtrace_symbols(backtrace_buffer, backtrace_size);
  if (!symbols) {
    backtrace_symbols_fd(backtrace_buffer, backtrace_size, 2);
    return;
  }
  for (int i = 0; i < backtrace_size; i++) {
    fprintf(stderr, "  %s\n", symbols[i]);
  }
  free(symbols);
#endif
}
Esempio n. 7
0
void tracy_backtrace(void) {
    void *array [40];
    size_t size;

    size = backtrace(array, 40);
    if (!size) {
        fprintf(stderr, "Backtrace failed!\n");
        return;
    }
    backtrace_symbols_fd(array, 10, 2);

    return;
}
Esempio n. 8
0
void stdTerminateHandler()
{
      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
      //fprintf(stderr, "Error: signal %d:\n", sig);
      backtrace_symbols_fd(array, size, 2);
      exit(1);
}
Esempio n. 9
0
static void yaz_invoke_backtrace(int sig)
{
    int fd = yaz_panic_fd;
    void *backtrace_info[BACKTRACE_SZ];
    int sz = BACKTRACE_SZ;

    yaz_panic_signal = sig;
    signal(SIGALRM, yaz_panic_alarm);
    alarm(1);
    sz = backtrace(backtrace_info, sz);
    backtrace_symbols_fd(backtrace_info, sz, fd);
    alarm(0);
}
Esempio n. 10
0
void warn_upon_switch(int sig __attribute__((unused)))
{
#if BACKTRACE // couldn't compile this for some reason; TODO
  void *bt[32];
  int nentries;
  /* Dump a backtrace of the frame which caused the switch to
     secondary mode: */
  nentries = backtrace(bt,sizeof(bt) / sizeof(bt[0]));
  backtrace_symbols_fd(bt,nentries,fileno(stdout));
#else
  log_alert("Switched to 2ndary mode\n");
#endif
}
Esempio n. 11
0
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>  /* exit */
#include <time.h>  /* time difftime */

#ifndef NDEBUG
#include <signal.h>  /* signal */
#include <execinfo.h>  /* backtrace */
#include <unistd.h>  /* STDERR_FILENO */
void debug_handler(int sig) {
    void *array[10];
    size_t size=backtrace(array, 10);

    fprintf(stderr, "Error: signal %d:\n", sig);
    backtrace_symbols_fd(array, size, STDERR_FILENO);

    /* additional instructions */
    if (sig == SIGILL){
        fprintf(stderr, "This error may raised when integer overflowing.\n");
    }

    exit(1);
}
Esempio n. 12
0
void
BongoAgentHandleSignal(BongoAgent *agent,
                       int sigtype)
{
    switch(sigtype) {
    // handle various fatal errors to spurt a backtrace when possible
    case SIGILL:
    case SIGABRT:
    case SIGPIPE:
    case SIGKILL:
    case SIGSEGV:
    {
        char path[XPL_MAX_PATH + 1];
        int boomfile;
        const int buff_size = 50;

        snprintf(path, XPL_MAX_PATH, "%s/guru-meditation-%d", XPL_DEFAULT_WORK_DIR, (int)time(NULL));
        boomfile = open(path, O_CREAT | O_WRONLY, (S_IRUSR | S_IWUSR));
        if (boomfile != -1) {
            void * buffer[buff_size];
            int buff_used;

            buff_used = backtrace(buffer, buff_size);
            backtrace_symbols_fd(buffer, buff_used, boomfile);
            close(boomfile);
        }
        XplExit(-1);
    }
    break;
    case SIGHUP:
        if (agent->state < BONGO_AGENT_STATE_UNLOADING) {
            agent->state = BONGO_AGENT_STATE_UNLOADING;
        }

        break;
    case SIGINT:
    case SIGTERM:
        if (agent->state == BONGO_AGENT_STATE_STOPPING) {
            XplExit(0);
        } else if (agent->state < BONGO_AGENT_STATE_STOPPING) {
            agent->state = BONGO_AGENT_STATE_STOPPING;
        }

        break;
    default:
        break;
    }

    return;
}
Esempio n. 13
0
int backtrace_dump_fd(int fd)
{
    void *callstack[STACK_SIZE];
    int frames = -1;

    if (fd < 0) {
        return -1;
    }

    frames = backtrace(callstack, STACK_SIZE);
    backtrace_symbols_fd(callstack, frames, fd);

    return 0;
}
Esempio n. 14
0
void segfaultHandler(int sig) {
#ifndef __CYGWIN__
    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
    fprintf(stderr, "Error: signal %d:\n", sig);
    backtrace_symbols_fd(array, size, 2);
#endif
    exit(1);
}
Esempio n. 15
0
void
dmnsn_backtrace(FILE *file)
{
#if DMNSN_BACKTRACE
#define DMNSN_BACKTRACE_SIZE 128
  void *buffer[DMNSN_BACKTRACE_SIZE];

  int nptrs = backtrace(buffer, DMNSN_BACKTRACE_SIZE);
  int fd = fileno(file);
  if (fd != -1) {
    backtrace_symbols_fd(buffer, nptrs, fd);
  }
#endif
}
Esempio n. 16
0
void
(qWarning)(const char *msg, ...)
{
    if (count++ > 10) {
        abort();
    }
    void *buff[1024];
    size_t size = backtrace(buff, 1024);
    backtrace_symbols_fd(buff, size, 2);
    va_list ap;
    va_start(ap, msg); // use variable arg list
    vprintf(msg, ap);
    va_end(ap);
}
Esempio n. 17
0
static void ui__signal_backtrace(int sig)
{
	void *stackdump[32];
	size_t size;

	ui__exit(false);
	psignal(sig, "perf");

	printf("-------- backtrace --------\n");
	size = backtrace(stackdump, ARRAY_SIZE(stackdump));
	backtrace_symbols_fd(stackdump, size, STDOUT_FILENO);

	exit(0);
}
Esempio n. 18
0
static void 
faultd_signal_handler__(int signal, siginfo_t* siginfo, void* context)
{
    int rv; 

    /*
     * Make sure we syncronize properly with other threads that
     * may *also* be faulting
     */
    rv = pthread_spin_trylock(&thread_lock__); 

    if (rv == EBUSY) { 
        sigset_t mask; 
        sigemptyset(&mask); 
        pselect(0, NULL, NULL, NULL, NULL, &mask); 
    }
    
    /*
     * Generate our fault information. 
     */ 
    faultd_info__.pid = getpid(); 
    faultd_info__.tid = 0; 
    faultd_info__.signal = signal; 
    faultd_info__.signal_code = siginfo->si_code; 
    faultd_info__.fault_address = siginfo->si_addr; 
    faultd_info__.last_errno = errno; 

    faultd_info__.backtrace_size = signal_backtrace__(faultd_info__.backtrace, 
                                                      AIM_ARRAYSIZE(faultd_info__.backtrace),
                                                      context, 0); 
    faultd_info__.backtrace_symbols = (void*)1; 
    if(faultd_client__) { 
        faultd_client_write(faultd_client__, &faultd_info__); 
    }
    if(localfd__ >= 0) { 
        char* signame = strsignal(faultd_info__.signal); 
        char* nl = "\n"; 
        write(localfd__, signame, strlen(signame)+1); 
        write(localfd__, nl, 2); 
        backtrace_symbols_fd(faultd_info__.backtrace, 
                             faultd_info__.backtrace_size, 
                             localfd__); 
    }

    /* 
     * Unlock spinlock, in case this signal wasn't fatal
     */
    pthread_spin_unlock(&thread_lock__); 
}
Esempio n. 19
0
void CrashHandlerPrivateMac::storeStackTrace() {
    const QString path = AppContext::getWorkingDirectoryPath() + "/ugenem";

    char pid_buf[30];
    sprintf(pid_buf, "%d", getpid());
    char name_buf[512];
    name_buf[readlink(path.toLatin1().constData(), name_buf, 511)] = 0;
    FILE *fp = fopen(stacktraceFilePath.toLocal8Bit().constData(), "w+");
    stacktraceFileSucessfullyCreated = (NULL != fp);
    void * stackTrace[1024];
    int frames = backtrace(stackTrace, 1024);
    backtrace_symbols_fd(stackTrace, frames, fileno(fp));
    const int closed = fclose(fp);
    stacktraceFileWasSucessfullyClosed = (closed == 0);
}
Esempio n. 20
0
void* mlm_malloc(size_t size, int level) {
    if(size == 0) {
        printf("ZERO BYTE MALLOC\n");
        void* bt_entries[64];
        int entries = backtrace(bt_entries, 64);
        backtrace_symbols_fd(bt_entries, entries, 1);
        exit(-1);
    }

#ifdef mlm_DEBUG
    printf("Performing a mlm Malloc for size %llu\n", size);
#endif

    return malloc(size);
}
Esempio n. 21
0
void save_backtrace(int sig)
{
  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
  fprintf(stderr, "Error: signal %d\n", sig);
  FILE *log = fopen("/tmp/mhddfs_backtrace.log", "w");
  backtrace_symbols_fd(array, size, fileno(log));
  fclose(log);
  exit(1);
}
Esempio n. 22
0
void
ofc_bt()
{
    void *trace[128];
    int n = backtrace(trace, sizeof(trace) / sizeof(trace[0]));
#ifdef OFC_SYSLOG


#else
    fprintf(stderr,"<ofchecker> : ***  Start backtrace ***\n");
    backtrace_symbols_fd(trace, n, 2);
    fprintf(stderr,"<ofchecker> : ***   End backtrace  ***\n");
#endif
    return;
}
Esempio n. 23
0
void printBacktrace()
{
#if ANKI_POSIX && ANKI_OS != ANKI_OS_ANDROID
	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, 2);
#else
	printf("TODO\n");
#endif
}
Esempio n. 24
0
File: CRT.c Progetto: guns/htop-vi
static void CRT_handleSIGSEGV(int sgn) {
   (void) sgn;
   CRT_done();
   #if __linux
   fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://htop.sf.net\n");
   #ifdef HAVE_EXECINFO_H
   size_t size = backtrace(backtraceArray, sizeof(backtraceArray));
   fprintf(stderr, "Backtrace: \n");
   backtrace_symbols_fd(backtraceArray, size, 2);
   #endif
   #else
   fprintf(stderr, "\n\nhtop " VERSION " aborting. Unsupported platform.\n");
   #endif
   abort();
}
Esempio n. 25
0
static void handle_signal(int sigval)
{
    void *stack[20];
    int depth;

    if(SIGSEGV == sigval || SIGABRT == sigval)
    {
        depth = backtrace(stack, 20);
        fputs("Backtrace follows (most recent first):\n", stderr);
        backtrace_symbols_fd(stack, depth, fileno(stderr));
        signal(sigval, SIG_DFL);
    }

    raise(sigval);
}
Esempio n. 26
0
void
hi_stacktrace_fd(int fd)
{
	if(fd > 0)
	{
		
	}
#ifdef HI_HAVE_BACKTRACE
    void *stack[64];
    int size;

    size = backtrace(stack, 64);
    backtrace_symbols_fd(stack, size, fd);
#endif
}
Esempio n. 27
0
void handler(int sig)
{
#if defined(OS_LINUX) || defined(OS_SOLARIS)
	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
	fprintf(stderr, "Error: signal %d:\n", sig);
	backtrace_symbols_fd(array, size, STDERR_FILENO);
	exit(1);
#endif
}
Esempio n. 28
0
  static void segv_handler(int sig) {
    static int crashing = 0;
    void *array[32];
    size_t size;

    // So we don't recurse!
    if(crashing) exit(101);

    crashing = 1;

    // print out all the frames to stderr
    static const char msg[] = "Error: signal ";
    if(write(2, msg, 14) == 0) exit(101);

    switch(sig) {
    case SIGSEGV:
      if(write(2, "SIGSEGV\n", 8) == 0) exit(101);
      break;
    case SIGBUS:
      if(write(2, "SIGBUS\n", 7) == 0) exit(101);
      break;
    case SIGILL:
      if(write(2, "SIGILL\n", 7) == 0) exit(101);
      break;
    case SIGABRT:
      if(write(2, "SIGABRT\n", 8) == 0) exit(101);
      break;
    case SIGFPE:
      if(write(2, "SIGFPE\n", 7) == 0) exit(101);
      break;
    default:
      if(write(2, "UNKNOWN\n", 8) == 0) exit(101);
      break;
    }

    // Try to get the output to flush...
    if(write(2, "\n\n", 2) == 0) exit(101);

    // get void*'s for all entries on the stack
    size = backtrace(array, 32);

    backtrace_symbols_fd(array, size, 2);

    // Try to get the output to flush...
    if(write(2, "\n\n", 2) == 0) exit(101);

    exit(100);
  }
Esempio n. 29
0
memory_region::~memory_region() {
    if (_synchronized) {
        _lock.lock();
    }
    if (_live_allocations == 0 && !_detailed_leaks) {
        if (_synchronized) {
            _lock.unlock();
        }
        return;
    }
    char msg[128];
    if(_live_allocations > 0) {
        snprintf(msg, sizeof(msg),
                 "leaked memory in rust main loop (%d objects)",
                 _live_allocations);
    }

#   if RUSTRT_TRACK_ALLOCATIONS >= 2
    if (_detailed_leaks) {
        int leak_count = 0;
        for (size_t i = 0; i < _allocation_list.size(); i++) {
            if (_allocation_list[i] != NULL) {
                alloc_header *header = (alloc_header*)_allocation_list[i];
                printf("allocation (%s) 0x%" PRIxPTR " was not freed\n",
                       header->tag,
                       (uintptr_t) get_data(header));
                ++leak_count;

#               if RUSTRT_TRACK_ALLOCATIONS >= 3
                if (_detailed_leaks) {
                    backtrace_symbols_fd(header->bt + 1,
                                         header->btframes - 1, 2);
                }
#               endif
            }
        }
        assert(leak_count == _live_allocations);
    }
#   endif

    if (_live_allocations > 0) {
        fprintf(stderr, "%s\n", msg);
        assert(false);
    }
    if (_synchronized) {
        _lock.unlock();
    }
}
Esempio n. 30
0
	void show_stack_trace() {
#ifdef WIN32
	    Logger::err("StackTrace") << "Not implemented in Graphite for Windows" << std::endl ;
#else
	    Logger::err("StackTrace") << "==================== Stack trace ========================" << std::endl ;
	    const int size = 200 ;
	    static void* buffer[size] ;
	    size_t nb_pointers = backtrace(buffer, size) ;
	    Logger::err("StackTrace") << nb_pointers << " stack frames" << std::endl ;
	    int fd = ::open("/tmp/stacktrace.txt", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) ;
	    backtrace_symbols_fd(buffer, nb_pointers, fd) ;
	    ::close(fd) ;
	    system("cat /tmp/stacktrace.txt | sed -e \'sx/.*/xx' | /usr/bin/c++filt") ;
	    Logger::err("StackTrace") << "=========================================================" << std::endl ;
#endif
	}