00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #pragma once
00019
00020 #ifndef _WIN32
00021 #include <signal.h>
00022 #endif
00023
00024 namespace mongo {
00025
00026
00027 typedef struct _Ints {
00028 int i[100];
00029 } *Ints;
00030 typedef struct _Chars {
00031 char c[200];
00032 } *Chars;
00033
00034 typedef char CHARS[400];
00035
00036 typedef struct _OWS {
00037 int size;
00038 char type;
00039 char string[400];
00040 } *OWS;
00041
00042 #if defined(_DEBUG)
00043 enum {DEBUG_BUILD = 1};
00044 #else
00045 enum {DEBUG_BUILD = 0};
00046 #endif
00047
00048 #define MONGO_DEV if( DEBUG_BUILD )
00049 #define DEV MONGO_DEV
00050
00051 #define MONGO_DEBUGGING if( 0 )
00052 #define DEBUGGING MONGO_DEBUGGING
00053
00054
00055
00056 #define MONGO_SOMETIMES( occasion, howOften ) for( static unsigned occasion = 0; ++occasion % howOften == 0; )
00057 #define SOMETIMES MONGO_SOMETIMES
00058
00059 #define MONGO_OCCASIONALLY SOMETIMES( occasionally, 16 )
00060 #define OCCASIONALLY MONGO_OCCASIONALLY
00061
00062 #define MONGO_RARELY SOMETIMES( rarely, 128 )
00063 #define RARELY MONGO_RARELY
00064
00065 #define MONGO_ONCE for( static bool undone = true; undone; undone = false )
00066 #define ONCE MONGO_ONCE
00067
00068 #if defined(_WIN32)
00069 inline int strcasecmp(const char* s1, const char* s2) {return _stricmp(s1, s2);}
00070 #endif
00071
00072
00073
00074 void setupSIGTRAPforGDB();
00075
00076 extern int tlogLevel;
00077
00078 inline void breakpoint() {
00079 if ( tlogLevel < 0 )
00080 return;
00081 #ifdef _WIN32
00082
00083 #endif
00084 #ifndef _WIN32
00085
00086 ONCE {
00087
00088 struct sigaction current;
00089 sigaction(SIGTRAP, NULL, ¤t);
00090 if (current.sa_handler == SIG_DFL) {
00091 signal(SIGTRAP, SIG_IGN);
00092 }
00093 }
00094
00095 raise(SIGTRAP);
00096 #endif
00097 }
00098
00099
00100
00101 inline void breakif(bool test) {
00102 if (test)
00103 breakpoint();
00104 }
00105
00106 }