Changeset 596fc4ad for src/main.cc


Ignore:
Timestamp:
Dec 29, 2019, 4:27:09 PM (6 years ago)
Author:
Dmitry Kobets <dkobets@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
0b3cdad
Parents:
1712f542 (diff), 3c67255 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into vector-generic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    r1712f542 r596fc4ad  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Aug 23 06:50:08 2019
    13 // Update Count     : 607
     12// Last Modified On : Mon Dec 16 17:55:53 2019
     13// Update Count     : 627
    1414//
    1515
     
    2020#include <cstdio>                           // for fopen, FILE, fclose, stdin
    2121#include <cstdlib>                          // for exit, free, abort, EXIT_F...
    22 #include <csignal>                         // for signal, SIGABRT, SIGSEGV
     22#include <csignal>                          // for signal, SIGABRT, SIGSEGV
    2323#include <cstring>                          // for index
    2424#include <fstream>                          // for ofstream
     
    2828#include <list>                             // for list
    2929#include <string>                           // for char_traits, operator<<
     30
     31using namespace std;
     32
    3033
    3134#include "CompilationState.h"
     
    5356#include "InitTweak/GenInit.h"              // for genInit
    5457#include "MakeLibCfa.h"                     // for makeLibCfa
    55 #include "Parser/LinkageSpec.h"             // for Spec, Cforall, Intrinsic
    5658#include "Parser/ParseNode.h"               // for DeclarationNode, buildList
    5759#include "Parser/TypedefTable.h"            // for TypedefTable
     
    5961#include "ResolvExpr/Resolver.h"            // for resolve
    6062#include "SymTab/Validate.h"                // for validate
     63#include "SynTree/LinkageSpec.h"            // for Spec, Cforall, Intrinsic
    6164#include "SynTree/Declaration.h"            // for Declaration
    6265#include "SynTree/Visitor.h"                // for acceptAll
     
    6467#include "Virtual/ExpandCasts.h"            // for expandCasts
    6568
    66 
    67 using namespace std;
    6869
    6970static void NewPass( const char * const name ) {
     
    9798static bool waiting_for_gdb = false;                                    // flag to set cfa-cpp to wait for gdb on start
    9899
    99 static std::string PreludeDirector = "";
     100static string PreludeDirector = "";
    100101
    101102static void parse_cmdline( int argc, char *argv[] );
     
    115116        for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) {
    116117                char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr;
    117                 for ( char *p = messages[i]; *p; ++p ) {        // find parantheses and +offset
     118
     119                for ( char * p = messages[i]; *p; p += 1 ) {    // find parantheses and +offset
    118120                        if ( *p == '(' ) {
    119121                                mangled_name = p;
     
    153155} // backtrace
    154156
    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;
     157#define SIGPARMS int sig __attribute__(( unused )), siginfo_t * sfp __attribute__(( unused )), ucontext_t * cxt __attribute__(( unused ))
     158
     159static void Signal( int sig, void (*handler)(SIGPARMS), int flags ) {
     160        struct sigaction act;
     161
     162        act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler;
     163        act.sa_flags = flags;
     164
     165        if ( sigaction( sig, &act, nullptr ) == -1 ) {
     166            cerr << "*CFA runtime error* problem installing signal handler, error(" << errno << ") " << strerror( errno ) << endl;
     167            _exit( EXIT_FAILURE );
     168        } // if
     169} // Signal
     170
     171static void sigSegvBusHandler( SIGPARMS ) {
     172        if ( sfp->si_addr == nullptr ) {
     173                cerr << "Null pointer (nullptr) dereference." << endl;
     174        } else {
     175                cerr << (sig == SIGSEGV ? "Segment fault" : "Bus error") << " at memory location " << sfp->si_addr << "." << endl
     176                         << "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;
     177        } // if
    159178        backtrace( 2 );                                                                         // skip first 2 stack frames
    160         //_exit( EXIT_FAILURE );
    161179        abort();                                                                                        // cause core dump for debugging
    162180} // sigSegvBusHandler
    163181
    164 static void sigAbortHandler( __attribute__((unused)) int sig_num ) {
     182static void sigAbortHandler( SIGPARMS ) {
    165183        backtrace( 6 );                                                                         // skip first 6 stack frames
    166         signal( SIGABRT, SIG_DFL);                                                      // reset default signal handler
     184        Signal( SIGABRT, (void (*)(SIGPARMS))SIG_DFL, SA_SIGINFO );     // reset default signal handler
    167185        raise( SIGABRT );                                                                       // reraise SIGABRT
    168186} // sigAbortHandler
     
    173191        list< Declaration * > translationUnit;
    174192
    175         signal( SIGSEGV, sigSegvBusHandler );
    176         signal( SIGBUS, sigSegvBusHandler );
    177         signal( SIGABRT, sigAbortHandler );
    178 
    179         // std::cout << "main" << std::endl;
     193        Signal( SIGSEGV, sigSegvBusHandler, SA_SIGINFO );
     194        Signal( SIGBUS, sigSegvBusHandler, SA_SIGINFO );
     195        Signal( SIGABRT, sigAbortHandler, SA_SIGINFO );
     196
     197        // cout << "main" << endl;
    180198        // for ( int i = 0; i < argc; i += 1 ) {
    181         //      std::cout << '\t' << argv[i] << std::endl;
     199        //      cout << '\t' << argv[i] << endl;
    182200        // } // for
    183201
     
    186204
    187205        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;
     206                cerr << "Waiting for gdb" << endl;
     207                cerr << "run :" << endl;
     208                cerr << "  gdb attach " << getpid() << endl;
    191209                raise(SIGSTOP);
    192210        } // if
     
    388406                return EXIT_FAILURE;
    389407        } catch ( ... ) {
    390                 std::exception_ptr eptr = std::current_exception();
     408                exception_ptr eptr = current_exception();
    391409                try {
    392410                        if (eptr) {
    393                                 std::rethrow_exception(eptr);
     411                                rethrow_exception(eptr);
    394412                        } 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";
     413                                cerr << "Exception Uncaught and Unknown" << endl;
     414                        } // if
     415                } catch(const exception& e) {
     416                        cerr << "Uncaught Exception \"" << e.what() << "\"\n";
    399417                } // try
    400418                return EXIT_FAILURE;
Note: See TracChangeset for help on using the changeset viewer.