Changeset b542bfb for src/main.cc
- Timestamp:
- Aug 29, 2016, 5:38:09 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, 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:
- 8f6f47d7
- Parents:
- 46f6134
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
r46f6134 rb542bfb 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Aug 20 12:52:22201613 // Update Count : 4 0312 // Last Modified On : Mon Aug 29 17:34:39 2016 13 // Update Count : 426 14 14 // 15 15 … … 75 75 static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); 76 76 77 void sigSegvBusHandler( int sig_num ) {77 void backtrace( int start ) { // skip first N stack frames 78 78 enum { Frames = 50 }; 79 79 void * array[Frames]; 80 80 int size = backtrace( array, Frames ); 81 82 cerr << "*CFA runtime error* program cfa-cpp terminated with "83 << (sig_num == SIGSEGV ? "segment fault" : "bus error")84 << " backtrace:" << endl;85 86 81 char ** messages = backtrace_symbols( array, size ); 87 82 88 // skip first stack frame (points here)89 for ( int i = 2; i < size - 2 && messages != nullptr; i += 1 ) {83 // skip last 2 stack frames after main 84 for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) { 90 85 char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr; 91 86 for ( char *p = messages[i]; *p; ++p ) { // find parantheses and +offset … … 101 96 102 97 // if line contains symbol, attempt to demangle 98 int frameNo = i - start; 103 99 if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) { 104 100 *mangled_name++ = '\0'; … … 106 102 *offset_end++ = '\0'; 107 103 108 int status ;104 int status, frameNo = i - start; 109 105 char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status ); 110 106 if ( status == 0 ) { // demangling successful ? 111 cerr << "(" << i - 2<< ") " << messages[i] << " : "107 cerr << "(" << frameNo << ") " << messages[i] << " : " 112 108 << real_name << "+" << offset_begin << offset_end << endl; 113 109 114 110 } else { // otherwise, output mangled name 115 cerr << "(" << i - 2<< ") " << messages[i] << " : "111 cerr << "(" << frameNo << ") " << messages[i] << " : " 116 112 << mangled_name << "+" << offset_begin << offset_end << endl; 117 113 } // if 118 114 free( real_name ); 119 115 } else { // otherwise, print the whole line 120 cerr << "(" << i - 2<< ") " << messages[i] << endl;116 cerr << "(" << frameNo << ") " << messages[i] << endl; 121 117 } // if 122 118 } // for 119 123 120 free( messages ); 121 } // backtrace 122 123 void sigSegvBusHandler( int sig_num ) { 124 cerr << "*CFA runtime error* program cfa-cpp terminated with " 125 << (sig_num == SIGSEGV ? "segment fault" : "bus error") 126 << " backtrace:" << endl; 127 backtrace( 2 ); // skip first 2 stack frames 124 128 exit( EXIT_FAILURE ); 125 129 } // sigSegvBusHandler 130 131 void sigAbortHandler( int sig_num ) { 132 backtrace( 6 ); // skip first 6 stack frames 133 signal( SIGABRT, SIG_DFL); // reset default signal handler 134 raise( SIGABRT ); // reraise SIGABRT 135 } // sigAbortHandler 136 126 137 127 138 int main( int argc, char * argv[] ) { … … 133 144 signal( SIGSEGV, sigSegvBusHandler ); 134 145 signal( SIGBUS, sigSegvBusHandler ); 146 signal( SIGABRT, sigAbortHandler ); 135 147 136 148 parse_cmdline( argc, argv, filename ); // process command-line arguments
Note: See TracChangeset
for help on using the changeset viewer.