Changeset bffcd66
- Timestamp:
- Dec 16, 2019, 2:31:10 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 6f9cc13
- Parents:
- 07de76b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
r07de76b rbffcd66 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 23 06:50:08201913 // Update Count : 6 0712 // Last Modified On : Fri Dec 13 23:47:06 2019 13 // Update Count : 626 14 14 // 15 15 … … 20 20 #include <cstdio> // for fopen, FILE, fclose, stdin 21 21 #include <cstdlib> // for exit, free, abort, EXIT_F... 22 #include <csignal> // for signal, SIGABRT, SIGSEGV22 #include <csignal> // for signal, SIGABRT, SIGSEGV 23 23 #include <cstring> // for index 24 24 #include <fstream> // for ofstream … … 28 28 #include <list> // for list 29 29 #include <string> // for char_traits, operator<< 30 31 using namespace std; 32 30 33 31 34 #include "CompilationState.h" … … 53 56 #include "InitTweak/GenInit.h" // for genInit 54 57 #include "MakeLibCfa.h" // for makeLibCfa 55 #include "Parser/LinkageSpec.h" // for Spec, Cforall, Intrinsic56 58 #include "Parser/ParseNode.h" // for DeclarationNode, buildList 57 59 #include "Parser/TypedefTable.h" // for TypedefTable … … 59 61 #include "ResolvExpr/Resolver.h" // for resolve 60 62 #include "SymTab/Validate.h" // for validate 63 #include "SynTree/LinkageSpec.h" // for Spec, Cforall, Intrinsic 61 64 #include "SynTree/Declaration.h" // for Declaration 62 65 #include "SynTree/Visitor.h" // for acceptAll … … 64 67 #include "Virtual/ExpandCasts.h" // for expandCasts 65 68 66 67 using namespace std;68 69 69 70 static void NewPass( const char * const name ) { … … 97 98 static bool waiting_for_gdb = false; // flag to set cfa-cpp to wait for gdb on start 98 99 99 static st d::string PreludeDirector = "";100 static string PreludeDirector = ""; 100 101 101 102 static void parse_cmdline( int argc, char *argv[] ); … … 153 154 } // backtrace 154 155 155 static void sigSegvBusHandler( int sig_num ) { 156 cerr << "*CFA runtime error* program cfa-cpp terminated with " 157 << (sig_num == SIGSEGV ? "segment fault" : "bus error") 158 << "." << endl; 156 #define SIGPARMS int sig __attribute__(( unused )), siginfo_t * sfp __attribute__(( unused )), ucontext_t * cxt __attribute__(( unused )) 157 158 static void Signal( int sig, void (*handler)(SIGPARMS), int flags ) { 159 struct sigaction act; 160 161 act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler; 162 sigemptyset( &act.sa_mask ); 163 sigaddset( &act.sa_mask, SIGALRM ); // disabled during signal handler 164 sigaddset( &act.sa_mask, SIGUSR1 ); 165 act.sa_flags = flags; 166 167 if ( sigaction( sig, &act, nullptr ) == -1 ) { 168 cerr << "*CFA runtime error* problem installing signal handler, error(" << errno << ") " << strerror( errno ) << endl; 169 _exit( EXIT_FAILURE ); 170 } // if 171 } // Signal 172 173 static void sigSegvBusHandler( SIGPARMS ) { 174 if ( sfp->si_addr == nullptr ) { 175 cerr << "Null pointer (nullptr) dereference." << endl; 176 } else { 177 cerr << (sig == SIGSEGV ? "Segment fault" : "Bus error") << " at memory location " << sfp->si_addr << "." << endl 178 << "Possible cause is reading outside the address space or writing to a protected area within the address space with an invalid pointer or subscript." << endl; 179 } // if 159 180 backtrace( 2 ); // skip first 2 stack frames 160 //_exit( EXIT_FAILURE );161 181 abort(); // cause core dump for debugging 162 182 } // sigSegvBusHandler 163 183 164 static void sigAbortHandler( __attribute__((unused)) int sig_num) {184 static void sigAbortHandler( SIGPARMS ) { 165 185 backtrace( 6 ); // skip first 6 stack frames 166 signal( SIGABRT, SIG_DFL);// reset default signal handler186 Signal( SIGABRT, (void (*)(SIGPARMS))SIG_DFL, SA_SIGINFO ); // reset default signal handler 167 187 raise( SIGABRT ); // reraise SIGABRT 168 188 } // sigAbortHandler … … 173 193 list< Declaration * > translationUnit; 174 194 175 signal( SIGSEGV, sigSegvBusHandler);176 signal( SIGBUS, sigSegvBusHandler);177 signal( SIGABRT, sigAbortHandler);178 179 // std::cout << "main" << std::endl;195 Signal( SIGSEGV, sigSegvBusHandler, SA_SIGINFO ); 196 Signal( SIGBUS, sigSegvBusHandler, SA_SIGINFO ); 197 Signal( SIGABRT, sigAbortHandler, SA_SIGINFO ); 198 199 // cout << "main" << endl; 180 200 // for ( int i = 0; i < argc; i += 1 ) { 181 // std::cout << '\t' << argv[i] << std::endl;201 // cout << '\t' << argv[i] << endl; 182 202 // } // for 183 203 … … 186 206 187 207 if ( waiting_for_gdb ) { 188 std::cerr << "Waiting for gdb" << std::endl;189 std::cerr << "run :" << std::endl;190 std::cerr << " gdb attach " << getpid() << std::endl;208 cerr << "Waiting for gdb" << endl; 209 cerr << "run :" << endl; 210 cerr << " gdb attach " << getpid() << endl; 191 211 raise(SIGSTOP); 192 212 } // if … … 388 408 return EXIT_FAILURE; 389 409 } catch ( ... ) { 390 std::exception_ptr eptr = std::current_exception();410 exception_ptr eptr = current_exception(); 391 411 try { 392 412 if (eptr) { 393 std::rethrow_exception(eptr);413 rethrow_exception(eptr); 394 414 } else { 395 std::cerr << "Exception Uncaught and Unknown" << std::endl;396 } // if 397 } catch(const std::exception& e) {398 std::cerr << "Uncaught Exception \"" << e.what() << "\"\n";415 cerr << "Exception Uncaught and Unknown" << endl; 416 } // if 417 } catch(const exception& e) { 418 cerr << "Uncaught Exception \"" << e.what() << "\"\n"; 399 419 } // try 400 420 return EXIT_FAILURE;
Note: See TracChangeset
for help on using the changeset viewer.