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