summaryrefslogtreecommitdiffstats
path: root/src/util.cc
blob: 7a1c4e6663d4b922bdff57c3e7ebe5e872c64f82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "util.h"

#include <execinfo.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

void DumpBacktrace(int skip_frames) {
  void* stack[256];
  int size = backtrace(stack, 256);
  ++skip_frames;  // Skip ourselves as well.
  backtrace_symbols_fd(stack + skip_frames, size - skip_frames, 2);
}

void Fatal(const char* msg, ...) {
  va_list ap;
  fprintf(stderr, "FATAL: ");
  va_start(ap, msg);
  vfprintf(stderr, msg, ap);
  va_end(ap);
  fprintf(stderr, "\n");
  DumpBacktrace(1);
  exit(1);
}