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 <string>
00057 #include <iostream>
00058 #include <fstream>
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 #ifndef UNIX_SRC
00083
00084
00085 #define DEBUG
00086 #endif
00087 #define EXC throw 1;
00088
00089
00090 #ifdef NORMAL
00091 #define Guard(function)
00092 #define UnGuard
00093 #define Trace
00094 #define Error
00095 #else
00096 #ifdef LOG
00097 static ofstream logfile("callstack.log",ios::app);\
00098 std::cout=logfile;
00099 #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
00100 try {
00101 #define UnGuard } catch (...) {\
00102 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
00103 std::cout<<"*********************CALL STACK*********************"<<std::endl;\
00104 std::cout<<"* Date : "<<asctime(ttb);\
00105 std::cout<<"* Module : "<<__FUNCTION_NAME__<<std::endl;\
00106 std::cout<<"* Line : "<<__LINE__<<std::endl;\
00107 std::cout<<"* File : "<<__FILE__<<std::endl;\
00108 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
00109 std::cout<<"***************************************************"<<std::endl;\
00110 throw; }
00111 #elif defined DEBUG
00112 #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
00113 try {
00114 #define UnGuard } catch (...) {\
00115 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
00116 std::cout<<"*********************CALL STACK*********************"<<std::endl;\
00117 std::cout<<"* Date : "<<asctime(ttb);\
00118 std::cout<<"* Module : "<<__FUNCTION_NAME__<<std::endl;\
00119 std::cout<<"* Line : "<<__LINE__<<std::endl;\
00120 std::cout<<"* File : "<<__FILE__<<std::endl;\
00121 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
00122 std::cout<<"***************************************************"<<std::endl;\
00123 throw; }
00124 #elif defined TRACE
00125 #ifdef UNIX_SRC
00126 #include <pthread.h>
00127 extern pthread_mutex_t mutex;
00128 extern int trace_level;
00129 #define Guard(fct) if (&mutex == NULL) pthread_mutex_init(&mutex, NULL);\
00130 static char* __FUNCTION_NAME__ = #fct;\
00131 pthread_mutex_lock (&mutex);\
00132 trace_level++;\
00133 pthread_mutex_unlock (&mutex);\
00134 std::cout<<">>>> " << trace_level << " Module : "<<__FUNCTION_NAME__<<std::endl;
00135 #define UnGuard std::cout<<"<<<< " << trace_level << " Module : "<<__FUNCTION_NAME__<<std::endl;\
00136 pthread_mutex_lock (&mutex);\
00137 trace_level--;\
00138 pthread_mutex_unlock (&mutex);
00139 #else
00140 #define Guard(function) static char * __FUNCTION_NAME__ = #function;\
00141 std::cout<<">>>> Module : "<<__FUNCTION_NAME__<<std::endl;
00142 #define UnGuard std::cout<<"<<<< Module : "<<__FUNCTION_NAME__<<std::endl;
00143 #endif // !UNIX_SRC
00144 #endif //TRACE
00145
00146 #define Trace(why) static char * __WHY__ = #why;\
00147 time_t tt;struct tm *ttb;tt = time(NULL);ttb = localtime(&tt);\
00148 std::cout<<"***********************TRACE***********************"<<std::endl;\
00149 std::cout<<"* Date : "<<asctime(ttb);\
00150 std::cout<<"* Module : "<<__FUNCTION_NAME__<<std::endl;\
00151 std::cout<<"* Line : "<<__LINE__<<std::endl;\
00152 std::cout<<"* File : "<<__FILE__<<std::endl;\
00153 std::cout<<"* Make date : "<<__DATE__<<" "<<__TIME__<<std::endl;\
00154 std::cout<<"* Cause : "<<__WHY__<<std::endl;\
00155 std::cout<<"* Error : "<<errno<<std::endl;\
00156 std::cout<<"***************************************************"<<std::endl;
00157
00158 #endif // !NORMAL
00159
00160
00161 #endif // EXCTRACE_H__