Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

dbtrace.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006 
00007 #ifndef _MCW_DEBUGTRACE_
00008 #define _MCW_DEBUGTRACE_
00009 
00010 /** inputs:
00011      USE_TRACING ==> if set, include tracing information in AFNI **/
00012 
00013 /*** Modified 23 Aug 1998 to eliminate PRINT_TRACING.
00014      Now, if DBG_trace > 1, will print STATUS messages. ***/
00015 
00016 /*** Modified 06 Mar 1999 to eliminate GNU malloc stuff,
00017      and replace it with mcw_malloc stuff.              ***/
00018 
00019 /*********************************************************************/
00020 #ifdef USE_TRACING
00021 
00022 #define DEBUG_MAX_DEPTH 256  /* way too big, but who cares? */
00023 
00024 #define DBG_label DBG_labels[DBG_trace]
00025 
00026 /*---------------------------------------------------------------*/
00027 
00028 #ifdef DONT_USE_MCW_MALLOC
00029 
00030 # define MCHECK /* nada */
00031 # define MPROBE /* nada */
00032 
00033 #else
00034 
00035 # define MCHECK                                            \
00036    do{ char * mc = mcw_malloc_status(__LINE__,__FILE__) ;  \
00037         if( mc != NULL ) printf("** Memory usage: %s\n",mc) ; } while(0)
00038 
00039 # define MPROBE do{ if( !DBG_trace ) mcw_malloc_status(__FILE__,__LINE__) ; } while(0)
00040 
00041 #endif
00042 
00043 /*---------------------------------------------------------------*/
00044 #ifdef MAIN
00045    char * DBG_rout[DEBUG_MAX_DEPTH] = { "Bottom of Debug Stack" } ;
00046    int DBG_num   = 1 ;
00047    int DBG_trace = 0 ;   /* turn off at start */
00048 
00049    char * DBG_labels[3] = { "Debug=OFF " , "Debug=LOW " , "Debug=HIGH" } ;
00050 
00051 #include <signal.h>
00052 void DBG_sigfunc(int sig)   /** signal handler for fatal errors **/
00053 {
00054    char * sname ; int ii ;
00055    switch(sig){
00056       default:      sname = "unknown" ; break ;
00057 /*    case -1:      sname = "malloc"  ; break ; */
00058       case SIGPIPE: sname = "SIGPIPE" ; break ;
00059       case SIGSEGV: sname = "SIGSEGV" ; break ;
00060       case SIGBUS:  sname = "SIGBUS"  ; break ;
00061       case SIGINT:  sname = "SIGINT"  ; break ;
00062    }
00063    fprintf(stderr,"\nFatal Signal %d (%s) received\n",sig,sname) ;
00064    if( DBG_num >= 0 ){
00065       for( ii=DBG_num-1; ii >= 0 ; ii-- )
00066          fprintf(stderr,"%*.*s%s\n",ii+1,ii+1," ",DBG_rout[ii]) ;
00067    } else {
00068       fprintf(stderr,"[No debug tracing stack: DBG_num=%d]\n",DBG_num) ;
00069    }
00070    fprintf(stderr,"*** Program Abort ***\n") ; fflush(stderr) ;
00071    MPROBE ; exit(1) ;
00072 }
00073 #define DBG_SIGNALS ( signal(SIGPIPE,DBG_sigfunc) , \
00074                       signal(SIGSEGV,DBG_sigfunc) , \
00075                       signal(SIGINT ,DBG_sigfunc) , \
00076                       signal(SIGBUS ,DBG_sigfunc)  )
00077 /*---------------------------------------------------------------*/
00078 #else /* not MAIN */
00079    extern char * DBG_rout[DEBUG_MAX_DEPTH] ;
00080    extern int DBG_num ;
00081    extern int DBG_trace ;
00082    extern char * DBG_labels[3] ;
00083 #endif /* MAIN */
00084 /*---------------------------------------------------------------*/
00085 
00086 /* macros for entering and exiting a function */
00087 
00088 #define DBG_LEADER_IN  "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
00089 #define DBG_LEADER_OUT "-----------------------------------------------------------"
00090 
00091 #define ENTRY(rout) do{ static char * rrr = (rout) ;  DBG_rout[DBG_num++] = rrr ; \
00092                         if( DBG_trace ){                                         \
00093                           printf("%*.*s%s [%d]: ENTRY (file=%s line=%d)\n",     \
00094                                  DBG_num,DBG_num,DBG_LEADER_IN,rrr,DBG_num,    \
00095                                  __FILE__ , __LINE__ ) ;                      \
00096                           MCHECK ; fflush(stdout) ; } } while(0)
00097 
00098 #define DBROUT      DBG_rout[DBG_num-1]
00099 
00100 #define DBEXIT      do{ if( DBG_trace ){                                      \
00101                           printf("%*.*s%s [%d]: EXIT (file=%s line=%d)\n",     \
00102                                  DBG_num,DBG_num,DBG_LEADER_OUT,DBROUT,DBG_num, \
00103                                  __FILE__ , __LINE__ );                        \
00104                           MCHECK ; fflush(stdout) ; }                         \
00105                         DBG_num = (DBG_num>1) ? DBG_num-1 : 1 ; } while(0)
00106 
00107 #define PRINT_TRACING (DBG_trace > 1)
00108 
00109 #define STATUS(str)                                               \
00110   do{ if(PRINT_TRACING){                                           \
00111         printf("%*.*s%s -- %s\n",DBG_num,DBG_num," ",DBROUT,(str)); \
00112         fflush(stdout) ; } } while(0)
00113 
00114 /*********************************************************************/
00115 #else /* don't USE_TRACING */
00116 
00117 #  define ENTRY(rout)   /* nada */
00118 #  define DBEXIT        /* nada */
00119 #  define DBROUT        /* nada */
00120 #  define STATUS(str)   /* nada */
00121 #  define DBG_SIGNALS   /* nada */
00122 #  define MCHECK        /* nada */
00123 #  define MPROBE        /* nada */
00124 #  define PRINT_TRACING 0
00125 #  define DBG_trace     0          /* 09 Dec 1999 */
00126 
00127 #endif /* USE_TRACING */
00128 /*********************************************************************/
00129 
00130 #define RETURN(val) do{ DBEXIT ; return (val) ; } while(0)
00131 #define EXRETURN    do{ DBEXIT ; return ; } while(0)
00132 
00133 /*---------------------------------------------------------------*/
00134 
00135 #ifndef MCHECK
00136 # define MCHECK /* nada */
00137 # define MPROBE /* nada */
00138 #endif
00139 /*---------------------------------------------------------------*/
00140 
00141 #endif /* _MCW_DEBUGTRACE_ */
 

Powered by Plone

This site conforms to the following standards: