-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdebug.h
More file actions
141 lines (114 loc) · 3.99 KB
/
debug.h
File metadata and controls
141 lines (114 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/** @file Debug.h
*
* Common debugging macros. Many of these macros are similar to those provided
* by MFC and are designed to allow for "MFC neutral" code (code than can be
* compiled with or without MFC support). Other macros add even more debugging
* facilities.
*
* Description of available macros:
*
* ASSERT : Identical to the MFC macro of the same name.
* VERIFY : Identical to the MFC macro of the same name.
* TRACE : Identical to the MFC macro of the same name.
* INFO : Similar to TRACE but includes a preamble specifying the
* file name and line number where the INFO is called as
* well as forces a line break at the end.
* DBG : Code contained within this macro is included only in
* _DEBUG builds.
* BREAK : Forces a break in _DEBUG builds via DebugBreak.
* DECL_DOG_TAG : Declares a "dog tag" within a class definition (see the
* discussion on dog tags below) in _DEBUG builds.
* CHECK_DOG_TAG : Checks the validity of a "dog tag" in _DEBUG builds.
*
*
* Dog Tags
*
* Dog tags are a technique that can be used to verify that an object has
* not been stepped on by a memory overrun. To use them you simply use the
* DECL_DOG_TAG macro to declare a dog tag at the beginning and ending of
* the class definition. After this, you can check the validity of an
* object by using the CHECK_DOG_TAG macro. For example:
*
* class MyClass
* {
* public:
* DECL_DOG_TAG(tagBegin);
* // code removed for brevity...
* DECL_DOG_TAG(tagEnd);
* };
*
* and later:
*
* MyClass obj;
* // code removed for brevity...
* CHECK_DOG_TAG(obj.tagBegin);
* CHECK_DOG_TAG(obj.tagEnd);
*
* @author William E. Kempf
* @version 2.0
*
* Copyright © 2000 NEWare Software.
*
* This code may be used in compiled form in any way you desire (including
* commercial use). The code may be redistributed unmodified by any means providing
* it is not sold for profit without the authors written consent, and providing that
* this notice and the authors name and all copyright notices remains intact. However,
* this file and the accompanying source code may not be hosted on a website or bulletin
* board without the authors written permission.
*
* <b><i>This software is provided "as is" without express or implied warranty. Use it
* at your own risk!</i></b>
*/
#if !defined(_DEBUG_H_0DBFB267_B244_11D3_A459_000629B2F85_INCLUDED_)
#define _DEBUG_H_0DBFB267_B244_11D3_A459_000629B2F85_INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#ifndef _MFC_VER
#include <crtdbg.h>
#define ASSERT _ASSERT
#ifdef _DEBUG
#define VERIFY(f) ASSERT(f)
inline void _cdecl Trace0DBFB266_B244_11D3_A459_000629B2F85(char* lpszFormat, ...)
{
va_list args;
va_start(args, lpszFormat);
int nBuf;
char szBuffer[512];
nBuf = _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(WCHAR), lpszFormat, args);
ASSERT(nBuf < sizeof(szBuffer));//Output truncated as it was > sizeof(szBuffer)
OutputDebugStringA(szBuffer);
va_end(args);
}
#define TRACE Trace0DBFB266_B244_11D3_A459_000629B2F85
#else // !_DEBUG
#define VERIFY(f) ((void)(f))
#define TRACE 1 ? (void)0 : Trace0DBFB266_B244_11D3_A459_000629B2F85
#endif // _DEBUG
#endif // _MFC_VER
#ifdef _DEBUG
#define DBG(f) (f)
#define BREAK() DebugBreak()
#define INFO(f) TRACE("%s (%d): ", __FILE__, __LINE__); TRACE(f); TRACE("\n")
class CDogTag
{
public:
CDogTag() { _this = this; }
CDogTag(const CDogTag& copy) { _this = this; ASSERT(copy.IsValid()); }
~CDogTag() { ASSERT(IsValid()); _this = 0; }
CDogTag& operator=(const CDogTag& rhs)
{ ASSERT(IsValid() && rhs.IsValid()); return *this; }
bool IsValid() const { return _this == this; }
private:
const CDogTag *_this;
};
#define DECL_DOG_TAG(dogTag) CDogTag dogTag;
#define CHECK_DOG_TAG(dogTag) ASSERT((dogTag).IsValid());
#else // !_DEBUG
#define DBG(f)
#define BREAK()
#define INFO(f)
#define DECL_DOG_TAG(dogTag)
#define CHECK_DOG_TAG(dogTag) ((void)0)
#endif // _DEBUG
#endif // !defined(_DEBUG_H_0DBFB267_B244_11D3_A459_000629B2F85_INCLUDED_)