Memosa-FVM  0.2
CException.cpp
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #include "CException.h"
6 
7 #ifdef __GNUC__
8 #include <execinfo.h>
9 #include <cxxabi.h>
10 #include <stdlib.h>
11 #endif
12 
13 using namespace std;
14 
15 
16 
17 CException::CException(const string& what) :
18  runtime_error(what)
19 {
20 #if 1
21 #ifdef __GNUC__
22  void *traces[100];
23  cout << "Backtrace... " << endl;
24  int traceCount = backtrace(traces,20);
25  char **traceStrings = backtrace_symbols(traces, traceCount);
26 
27  if(traceStrings != NULL)
28  {
29  for(int x = 0; x < traceCount; x++)
30  {
31  if (traceStrings[x] == NULL) { break; }
32  int status;
33  string s(traceStrings[x]);
34  size_t funcNameBegin = s.find("(");
35  size_t funcNameEnd = s.find("+");
36  if (funcNameBegin != string::npos &&
37  funcNameEnd != string::npos)
38  {
39  string funcNameMangled(s.begin()+funcNameBegin+1,
40  s.begin()+funcNameEnd);
41 
42  string fileName(s.begin(),s.begin()+funcNameBegin);
43 
44  string offset(s.begin() + funcNameEnd, s.end());
45 
46  char *realName = abi::__cxa_demangle(funcNameMangled.c_str(), 0, 0, &status);
47 
48  std::cout << x << " : " << realName << endl;
49  free(realName);
50  }
51  else
52  std::cout << x << " : " << s << endl;
53  }
54  }
55  cout << "Backtrace...end " << endl;
56  cout << flush;
57  free(traceStrings);
58 #endif
59 #endif
60 
61 }
62 
CException(const string &what)
Definition: CException.cpp:17