00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef EXCTRACE_H__
00054 #define EXCTRACE_H__
00055
00056 #include <stdio.h>
00057 #include <stdlib.h>
00058 #include <iostream>
00059 #include <fstream>
00060 #ifndef GCC_295
00061 #include <ostream>
00062 #endif
00063 #include <string.h>
00064 #include <time.h>
00065 #include <iostream>
00066 #include <strstream>
00067 #ifdef UNIX_SRC
00068 #include <typeinfo>
00069 #else
00070 #include <typeinfo.h>
00071 #endif
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 #ifndef UNIX_SRC
00094
00095
00096 #define DEBUG
00097 #endif
00098
00099 #define EXC throw 1;
00100
00101
00102 #ifdef NORMAL
00103 #define Guard(function)
00104 #define UnGuard
00105 #define Trace
00106 #define Error
00107 #else
00108 #ifdef LOG
00109 static std::ofstream logfile("callstack.log",std::ios::app);\
00110 std::cout=logfile;
00111 #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
00112 try {
00113 #define UnGuard } catch (...) {\
00114 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
00115 std::cout<<"*********************CALL STACK*********************"<<std::endl;\
00116 std::cout<<"* Date : "<<asctime(ttb);\
00117 std::cout<<"* Module : "<<__FUNCTION_NAME__<<std::endl;\
00118 std::cout<<"* Line : "<<__LINE__<<std::endl;\
00119 std::cout<<"* File : "<<__FILE__<<std::endl;\
00120 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
00121 std::cout<<"***************************************************"<<std::endl;\
00122 throw; }
00123 #elif defined DEBUG
00124 #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
00125 try {
00126 #define UnGuard } catch (...) {\
00127 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
00128 std::cout<<"*********************CALL STACK*********************"<<std::endl;\
00129 std::cout<<"* Date : "<<asctime(ttb);\
00130 std::cout<<"* Module : "<<__FUNCTION_NAME__<<std::endl;\
00131 std::cout<<"* Line : "<<__LINE__<<std::endl;\
00132 std::cout<<"* File : "<<__FILE__<<std::endl;\
00133 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
00134 std::cout<<"***************************************************"<<std::endl;\
00135 throw; }
00136 #elif defined TRACE
00137 #ifdef UNIX_SRC
00138 #include <pthread.h>
00139 extern pthread_mutex_t mutex;
00140 extern int trace_level;
00141 #define Guard(fct) if (&mutex == NULL) pthread_mutex_init(&mutex, NULL);\
00142 static char* __FUNCTION_NAME__ = #fct;\
00143 pthread_mutex_lock (&mutex);\
00144 trace_level++;\
00145 pthread_mutex_unlock (&mutex);\
00146 std::cout<<">>>> " << trace_level << " Module : "<<__FUNCTION_NAME__<<std::endl;
00147 #define UnGuard std::cout<<"<<<< " << trace_level << " Module : "<<__FUNCTION_NAME__<<std::endl;\
00148 pthread_mutex_lock (&mutex);\
00149 trace_level--;\
00150 pthread_mutex_unlock (&mutex);
00151 #else
00152 #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
00153 std::cout<<">>>> Module : "<<__FUNCTION_NAME__<<std::endl;
00154 #define UnGuard std::cout<<"<<<< Module : "<<__FUNCTION_NAME__<<std::endl;
00155 #endif // !UNIX_SRC
00156 #endif //TRACE
00157
00158 #define Trace(why) static char * __WHY__ = #why;\
00159 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
00160 std::cout<<"***********************TRACE***********************"<<std::endl;\
00161 std::cout<<"* Date : "<<asctime(ttb);\
00162 std::cout<<"* Module : "<<__FUNCTION_NAME__<<std::endl;\
00163 std::cout<<"* Line : "<<__LINE__<<std::endl;\
00164 std::cout<<"* File : "<<__FILE__<<std::endl;\
00165 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
00166 std::cout<<"* Cause : "<<__WHY__<<std::endl;\
00167 std::cout<<"* Error : "<<errno<<std::endl;\
00168 std::cout<<"***************************************************"<<std::endl;
00169
00170 #endif // !NORMAL
00171
00172
00173 #endif // EXCTRACE_H__