forked from paolorotolo/redex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebug.cpp
43 lines (38 loc) · 1.06 KB
/
Debug.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "Debug.h"
#include <execinfo.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void assert_fail(const char* expr,
const char* file,
unsigned line,
const char* func,
const char* fmt,
...) {
va_list ap;
va_start(ap, fmt);
fprintf(
stderr, "%s:%u: %s: assertion `%s' failed.\n", file, line, func, expr);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
abort();
}
void crash_backtrace(int sig) {
constexpr int max_bt_frames = 256;
void* buf[max_bt_frames];
auto frames = backtrace(buf, max_bt_frames);
backtrace_symbols_fd(buf, frames, STDERR_FILENO);
signal(sig, SIG_DFL);
raise(sig);
}