PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pgr_assert.cpp
Go to the documentation of this file.
1 /*PGR-MIT******************************************************************
2  *
3  * file pgr_assert.cpp
4  *
5  * Copyright 2014 Stephen Woodbridge <woodbri@imaptools.com>
6  * Copyright 2014 Vicky Vergara <vicky_vergara@hotmail.com>
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the MIT License. Please file MIT-LICENSE for details.
10  *
11  *****************************************************************PGR-MIT*/
12 #include "./pgr_assert.h"
13 
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <stddef.h>
17 
18 #ifdef __linux__
19 #include <execinfo.h>
20 #endif
21 
22 #include <string>
23 #include <exception>
24 
25 
26 std::string get_backtrace() {
27 #ifdef __linux__
28  void *trace[16];
29  int i, trace_size = 0;
30 
31  trace_size = backtrace(trace, 16);
32  char** funcNames = backtrace_symbols(trace, trace_size);
33 
34 
35  std::string message = "\n*** Execution path***\n";
36  for (i = 0; i < trace_size; ++i) {
37  message += "[bt]" + static_cast<std::string>(funcNames[i]) + "\n";
38  }
39 
40  free(funcNames);
41  return message;
42 #else
43  return "";
44 #endif
45 }
46 
47 std::string get_backtrace(const std::string &msg) {
48  return std::string("\n") + msg + "\n" + get_backtrace();
49 }
50 
51 
52 
53 const char* AssertFailedException::what() const throw() {
54  return str.c_str();
55 }
56 
58  str(msg) {}
59 
std::string get_backtrace()
returns the execution path of the trace
Definition: pgr_assert.cpp:26
AssertFailedException(std::string msg)
Definition: pgr_assert.cpp:57
const std::string str
Holds what() we got as message.
Definition: pgr_assert.h:128
Assertions Handling.
virtual const char * what() const
Definition: pgr_assert.cpp:53