-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdbc.cpp
More file actions
64 lines (56 loc) · 1.53 KB
/
Copy pathdbc.cpp
File metadata and controls
64 lines (56 loc) · 1.53 KB
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
64
#include "util/dbc.hpp"
#include <cstdlib>
#include <csignal>
#ifndef _WIN64
#include <execinfo.h>
#endif
namespace henhouse::util
{
namespace
{
const size_t TRACE_SIZE = 16;
dialog_callback DIALOG_CALLBACK = [](const char*){};
}
#ifdef _WIN64
void trace(std::ostream&) {}
#else
void trace(std::ostream& o)
{
void *t[TRACE_SIZE];
auto size = backtrace(t, TRACE_SIZE);
auto s = backtrace_symbols (t, size);
for (int i = 0; i < size; i++)
o << s[i] << std::endl;
std::free(s);
}
#endif
void set_assert_dialog_callback(dialog_callback c)
{
DIALOG_CALLBACK = c;
}
void raise(const char * msg)
{
std::stringstream s;
s << msg << std::endl;
trace(s);
std::cerr << s.str() << std::endl;
DIALOG_CALLBACK(s.str().c_str());
exit(1);
}
void raise1(
const char * file,
const char * func,
const int line,
const char * dbc,
const char * expr)
{
std::stringstream s;
s << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
s << "!! " << dbc << " failed" << std::endl;
s << "!! expr: " << expr << std::endl;
s << "!! func: " << func << std::endl;
s << "!! file: " << file << " (" << line << ")" << std::endl;
s << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
raise(s.str().c_str());
}
}