Changeset 0afffee
- Timestamp:
- Oct 30, 2016, 10:28:26 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 3a2128f, 955d9e43, f51aefb
- Parents:
- 65c61ec
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
r65c61ec r0afffee 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 29 17:34:39201613 // Update Count : 4 2612 // Last Modified On : Sun Oct 30 10:11:38 2016 13 // Update Count : 435 14 14 // 15 15 … … 18 18 #include <signal.h> // signal 19 19 #include <getopt.h> // getopt 20 #include <execinfo.h> // backtrace, backtrace_symbols _fd20 #include <execinfo.h> // backtrace, backtrace_symbols 21 21 #include <cxxabi.h> // __cxa_demangle 22 #include <cstring> // index 22 23 23 24 using namespace std; … … 75 76 static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); 76 77 77 void backtrace( int start ) {// skip first N stack frames78 static void backtrace( int start ) { // skip first N stack frames 78 79 enum { Frames = 50 }; 79 80 void * array[Frames]; 80 int size = backtrace( array, Frames ); 81 char ** messages = backtrace_symbols( array, size ); 81 int size = ::backtrace( array, Frames ); 82 char ** messages = ::backtrace_symbols( array, size ); // does not demangle names 83 84 *index( messages[0], '(' ) = '\0'; // find executable name 85 cerr << "Stack back trace for: " << messages[0] << endl; 82 86 83 87 // skip last 2 stack frames after main … … 85 89 char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr; 86 90 for ( char *p = messages[i]; *p; ++p ) { // find parantheses and +offset 87 if ( *p == '(') {91 if ( *p == '(' ) { 88 92 mangled_name = p; 89 } else if ( *p == '+') {93 } else if ( *p == '+' ) { 90 94 offset_begin = p; 91 } else if ( *p == ')') {95 } else if ( *p == ')' ) { 92 96 offset_end = p; 93 97 break; … … 98 102 int frameNo = i - start; 99 103 if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) { 100 *mangled_name++ = '\0'; 104 *mangled_name++ = '\0'; // delimit strings 101 105 *offset_begin++ = '\0'; 102 106 *offset_end++ = '\0'; 103 107 104 int status , frameNo = i - start;108 int status; 105 109 char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status ); 110 // bug in __cxa_demangle for single-character lower-case non-mangled names 106 111 if ( status == 0 ) { // demangling successful ? 107 112 cerr << "(" << frameNo << ") " << messages[i] << " : " 108 113 << real_name << "+" << offset_begin << offset_end << endl; 109 110 114 } else { // otherwise, output mangled name 111 115 cerr << "(" << frameNo << ") " << messages[i] << " : " 112 << mangled_name << " +" << offset_begin << offset_end << endl;116 << mangled_name << "(/*unknown*/)+" << offset_begin << offset_end << endl; 113 117 } // if 118 114 119 free( real_name ); 115 120 } else { // otherwise, print the whole line … … 124 129 cerr << "*CFA runtime error* program cfa-cpp terminated with " 125 130 << (sig_num == SIGSEGV ? "segment fault" : "bus error") 126 << " backtrace:" << endl;131 << "." << endl; 127 132 backtrace( 2 ); // skip first 2 stack frames 128 133 exit( EXIT_FAILURE );
Note: See TracChangeset
for help on using the changeset viewer.