Changeset 0afffee


Ignore:
Timestamp:
Oct 30, 2016, 10:28:26 AM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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
Message:

update stack trace on cfa error

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    r65c61ec r0afffee  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 29 17:34:39 2016
    13 // Update Count     : 426
     12// Last Modified On : Sun Oct 30 10:11:38 2016
     13// Update Count     : 435
    1414//
    1515
     
    1818#include <signal.h>                                                                             // signal
    1919#include <getopt.h>                                                                             // getopt
    20 #include <execinfo.h>                                                                   // backtrace, backtrace_symbols_fd
     20#include <execinfo.h>                                                                   // backtrace, backtrace_symbols
    2121#include <cxxabi.h>                                                                             // __cxa_demangle
     22#include <cstring>                                                                              // index
    2223
    2324using namespace std;
     
    7576static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
    7677
    77 void backtrace( int start ) {                                                   // skip first N stack frames
     78static void backtrace( int start ) {                                    // skip first N stack frames
    7879        enum { Frames = 50 };
    7980        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;
    8286
    8387        // skip last 2 stack frames after main
     
    8589                char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr;
    8690                for ( char *p = messages[i]; *p; ++p ) {        // find parantheses and +offset
    87                         if (*p == '(') {
     91                        if ( *p == '(' ) {
    8892                                mangled_name = p;
    89                         } else if (*p == '+') {
     93                        } else if ( *p == '+' ) {
    9094                                offset_begin = p;
    91                         } else if (*p == ')') {
     95                        } else if ( *p == ')' ) {
    9296                                offset_end = p;
    9397                                break;
     
    98102                int frameNo = i - start;
    99103                if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) {
    100                         *mangled_name++ = '\0';
     104                        *mangled_name++ = '\0';                                         // delimit strings
    101105                        *offset_begin++ = '\0';
    102106                        *offset_end++ = '\0';
    103107
    104                         int status, frameNo = i - start;
     108                        int status;
    105109                        char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status );
     110                        // bug in __cxa_demangle for single-character lower-case non-mangled names
    106111                        if ( status == 0 ) {                                            // demangling successful ?
    107112                                cerr << "(" << frameNo << ") " << messages[i] << " : "
    108113                                         << real_name << "+" << offset_begin << offset_end << endl;
    109 
    110114                        } else {                                                                        // otherwise, output mangled name
    111115                                cerr << "(" << frameNo << ") " << messages[i] << " : "
    112                                          << mangled_name << "+" << offset_begin << offset_end << endl;
     116                                         << mangled_name << "(/*unknown*/)+" << offset_begin << offset_end << endl;
    113117                        } // if
     118
    114119                        free( real_name );
    115120                } else {                                                                                // otherwise, print the whole line
     
    124129        cerr << "*CFA runtime error* program cfa-cpp terminated with "
    125130                 <<     (sig_num == SIGSEGV ? "segment fault" : "bus error")
    126                  << " backtrace:" << endl;
     131                 << "." << endl;
    127132        backtrace( 2 );                                                                         // skip first 2 stack frames
    128133        exit( EXIT_FAILURE );
Note: See TracChangeset for help on using the changeset viewer.