forked from pgRouting/pgrouting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert.cpp
More file actions
75 lines (54 loc) · 2.03 KB
/
Copy pathassert.cpp
File metadata and controls
75 lines (54 loc) · 2.03 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
65
66
67
68
69
70
71
72
73
74
/*PGR-GNU*****************************************************************
File: assert.cpp
Copyright (c) 2015-2026 pgRouting developers
Mail: project@pgrouting.org
Copyright 2015~ Vicky Vergara <vicky_vergara@hotmail.com>
Copyright 2014 Stephen Woodbridge <woodbri@imaptools.com>
Mail: project@pgrouting.org
------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
********************************************************************PGR-GNU*/
#include "cpp_common/assert.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#ifdef __GLIBC__
#include <execinfo.h>
#endif
#include <string>
#include <exception>
#include <iterator>
std::string get_backtrace() {
#ifdef __GLIBC__
void *trace[16];
int i = 0, trace_size = 0;
trace_size = backtrace(std::data(trace), 16);
char** funcNames = backtrace_symbols(std::data(trace), trace_size);
std::string message = "\n*** Execution path***\n";
for (i = 0; i < trace_size; ++i) {
message += "[bt]" + static_cast<std::string>(funcNames[i]) + "\n";
}
free(funcNames);
return message;
#else
return "";
#endif
}
std::string get_backtrace(const std::string &msg) {
return std::string("\n") + msg + "\n" + get_backtrace();
}
const char* AssertFailedException::what() const throw() {
return str.c_str();
}
AssertFailedException::AssertFailedException(std::string msg) :
str(msg) {}