コード例 #1
0
ファイル: glhck.c プロジェクト: Cloudef/glhck
/* \brief backtrace handler of glhck */
static void _glhckBacktrace(int signal)
{
   (void)signal;

   /* GDB */
#if defined(__linux__) || defined(__APPLE__)
   char buf[1024];
   pid_t dying_pid = getpid();
   pid_t child_pid = fork();

#if HAS_YAMA_PRCTL
   /* tell yama that we allow our child_pid to trace our process */
   if (child_pid > 0) prctl(PR_SET_PTRACER, child_pid);
#endif

   if (child_pid < 0) {
      _glhckPuts("\1fork failed for gdb backtrace.");
   } else if (child_pid == 0) {
      /* sed -n '/bar/h;/bar/!H;$!b;x;p' (another way, if problems) */
      printf("\n---- gdb ----\n");
      snprintf(buf, sizeof(buf)-1, "gdb -p %d -batch -ex bt 2>/dev/null | sed -n '/<signal handler/{n;x;b};H;${x;p}'", dying_pid);
      const char* argv[] = { "sh", "-c", buf, NULL };
      execve("/bin/sh", (char**)argv, NULL);
      _glhckPuts("\1failed to launch gdb for backtrace.");
      _exit(EXIT_FAILURE);
   } else {
      waitpid(child_pid, NULL, 0);
   }
#endif

   /* SIGABRT || SIGSEGV */
   exit(EXIT_FAILURE);
}
コード例 #2
0
ファイル: glhck.c プロジェクト: Cloudef/glhck
static void _glhckFpeHandler(int signal)
{
   (void)signal;
   _glhckPuts("\n\4SIGFPE \1signal received!");
   _glhckPuts("Run the program again with DEBUG=2,+all,+trace to catch where it happens.");
   _glhckPuts("Or optionally run the program with GDB.");
   abort();
}
コード例 #3
0
ファイル: render.c プロジェクト: zoadianCollection/glhck
 /* \brief output queued textures */
GLHCKAPI void glhckRenderPrintTextureQueue(void)
{
   unsigned int i;
   __GLHCKtextureQueue *textures;
   GLHCK_INITIALIZED();

   textures = &GLHCKRD()->textures;
   _glhckPuts("\n--- Texture Queue ---");
   for (i = 0; i != textures->count; ++i)
      _glhckPrintf("%u. %p", i, textures->queue[i]);
   _glhckPuts("---------------------");
   _glhckPrintf("count/alloc: %u/%u", textures->count, textures->allocated);
   _glhckPuts("--------------------\n");
}
コード例 #4
0
ファイル: render.c プロジェクト: zoadianCollection/glhck
/* \brief output queued objects */
GLHCKAPI void glhckRenderPrintObjectQueue(void)
{
   unsigned int i;
   __GLHCKobjectQueue *objects;
   GLHCK_INITIALIZED();

   objects = &GLHCKRD()->objects;
   _glhckPuts("\n--- Object Queue ---");
   for (i = 0; i != objects->count; ++i)
      _glhckPrintf("%u. %p", i, objects->queue[i]);
   _glhckPuts("--------------------");
   _glhckPrintf("count/alloc: %u/%u", objects->count, objects->allocated);
   _glhckPuts("--------------------\n");
}
コード例 #5
0
ファイル: util.c プロジェクト: Cloudef/glhck
/* \brief colored printf */
void _glhckPrintf(const char *fmt, ...)
{
    va_list args;
    char buffer[2048];

    memset(buffer, 0, sizeof(buffer));
    va_start(args, fmt);
    vsnprintf(buffer, sizeof(buffer)-1, fmt, args);
    va_end(args);

    _glhckPuts(buffer);
}