-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathassert.cc
65 lines (48 loc) · 1.32 KB
/
assert.cc
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// (c) Robert Muth - see LICENSE for more info
#include "Util/assert.h"
#include <iostream>
static AbortHandlerFun MyAbortHandler = &abort;
void SetAbortHandler(AbortHandlerFun handler) {
MyAbortHandler = handler;
}
#ifdef CWERG_ENABLE_UNWIND
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#include <iomanip>
#include <iostream>
void AssertHelper::Abort() {
unw_cursor_t cursor;
unw_context_t context;
// Init
unw_getcontext(&context);
unw_init_local(&cursor, &context);
// Unwind
while (unw_step(&cursor) > 0) {
unw_word_t offset, pc;
unw_get_reg(&cursor, UNW_REG_IP, &pc);
if (pc == 0) break;
char sym[1024];
if (unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) {
std::cerr << std::hex << "0x" << pc << ": " << sym << " (+0x" << offset
<< ")\n";
} else {
std::cerr << std::hex << "0x" << pc << ": -- no symbol info\n";
}
}
std::cerr << "to unmangle append ` |& c++filt ` to command\n";
MyAbortHandler();
}
#else
#include <execinfo.h>
void AssertHelper::Abort() {
void* buffer[1024];
int count = backtrace(buffer, 1024);
backtrace_symbols_fd(buffer, count, 2);
MyAbortHandler();
}
#endif
AssertHelper::~AssertHelper() {
std::cerr << "Failure at " << file_ << "::" << std::dec << line_ << ": "
<< ss_.str() << "\n";
Abort();
}