MongoDB  2.7.0
debug_util.h
1 // debug_util.h
2 
3 /* Copyright 2009 10gen Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 
21 namespace mongo {
22 
23 #if defined(_DEBUG)
24  enum {DEBUG_BUILD = 1};
25  const bool debug=true;
26 #else
27  enum {DEBUG_BUILD = 0};
28  const bool debug=false;
29 #endif
30 
31 #define MONGO_DEV if( DEBUG_BUILD )
32 #define DEV MONGO_DEV
33 
34 #define MONGO_DEBUGGING if( 0 )
35 #define DEBUGGING MONGO_DEBUGGING
36 
37 // The following declare one unique counter per enclosing function.
38 // NOTE The implementation double-increments on a match, but we don't really care.
39 #define MONGO_SOMETIMES( occasion, howOften ) for( static unsigned occasion = 0; ++occasion % howOften == 0; )
40 #define SOMETIMES MONGO_SOMETIMES
41 
42 #define MONGO_OCCASIONALLY SOMETIMES( occasionally, 16 )
43 #define OCCASIONALLY MONGO_OCCASIONALLY
44 
45 #define MONGO_RARELY SOMETIMES( rarely, 128 )
46 #define RARELY MONGO_RARELY
47 
48 #define MONGO_ONCE for( static bool undone = true; undone; undone = false )
49 #define ONCE MONGO_ONCE
50 
51 #if defined(_WIN32)
52  inline int strcasecmp(const char* s1, const char* s2) {return _stricmp(s1, s2);}
53 #endif
54 
55  // Sets SIGTRAP handler to launch GDB
56  // Noop unless on *NIX and compiled with _DEBUG
57  void setupSIGTRAPforGDB();
58 
59  extern int tlogLevel;
60  void mongo_breakpoint();
61  inline void breakpoint() {
62  if ( tlogLevel < 0 )
63  return;
64  mongo_breakpoint();
65  }
66 } // namespace mongo
int tlogLevel
For logging which we may not want during unit tests (dbtests) runs.
Definition: log.cpp:57