VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/glue/nsDebug.h@ 44770

最後變更 在這個檔案從44770是 1,由 vboxsync 提交於 55 年 前

import

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 9.8 KB
 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#ifndef nsDebug_h___
39#define nsDebug_h___
40
41#ifndef nscore_h___
42#include "nscore.h"
43#endif
44
45#ifndef nsError_h__
46#include "nsError.h"
47#endif
48
49#ifdef DEBUG
50#define NS_DEBUG
51#endif
52
53/**
54 * Namespace for debugging methods. Note that your code must use the
55 * macros defined later in this file so that the debug code can be
56 * conditionally compiled out.
57 */
58
59/* in case this is included by a C file */
60#ifdef __cplusplus
61
62class nsDebug {
63public:
64
65 /**
66 * Log a warning message to the debug log.
67 */
68 static NS_COM void Warning(const char* aMessage,
69 const char* aFile, PRIntn aLine);
70
71 /**
72 * Abort the executing program. This works on all architectures.
73 */
74 static NS_COM void Abort(const char* aFile, PRIntn aLine);
75
76 /**
77 * Break the executing program into the debugger.
78 */
79 static NS_COM void Break(const char* aFile, PRIntn aLine);
80
81 /**
82 * Log an assertion message to the debug log
83 */
84 static NS_COM void Assertion(const char* aStr, const char* aExpr,
85 const char* aFile, PRIntn aLine);
86};
87
88#ifdef DEBUG
89
90/**
91 * Abort the execution of the program if the expression evaluates to
92 * false.
93 *
94 * There is no status value returned from the macro.
95 *
96 * Note that the non-debug version of this macro does <b>not</b>
97 * evaluate the expression argument. Hence side effect statements
98 * as arguments to the macro will yield improper execution in a
99 * non-debug build. For example:
100 *
101 * NS_ABORT_IF_FALSE(0 == foo++, "yikes foo should be zero");
102 *
103 * Note also that the non-debug version of this macro does <b>not</b>
104 * evaluate the message argument.
105 */
106#define NS_ABORT_IF_FALSE(_expr, _msg) \
107 PR_BEGIN_MACRO \
108 if (!(_expr)) { \
109 nsDebug::Assertion(_msg, #_expr, __FILE__, __LINE__); \
110 } \
111 PR_END_MACRO
112
113/**
114 * Warn if a given condition is false.
115 *
116 * Program execution continues past the usage of this macro.
117 *
118 * Note also that the non-debug version of this macro does <b>not</b>
119 * evaluate the message argument.
120 */
121#define NS_WARN_IF_FALSE(_expr,_msg) \
122 PR_BEGIN_MACRO \
123 if (!(_expr)) { \
124 nsDebug::Assertion(_msg, #_expr, __FILE__, __LINE__); \
125 } \
126 PR_END_MACRO
127
128/**
129 * Test a precondition for truth. If the expression is not true then
130 * trigger a program failure.
131 */
132#define NS_PRECONDITION(expr, str) \
133 PR_BEGIN_MACRO \
134 if (!(expr)) { \
135 nsDebug::Assertion(str, #expr, __FILE__, __LINE__); \
136 } \
137 PR_END_MACRO
138
139/**
140 * Test an assertion for truth. If the expression is not true then
141 * trigger a program failure.
142 */
143#define NS_ASSERTION(expr, str) \
144 PR_BEGIN_MACRO \
145 if (!(expr)) { \
146 nsDebug::Assertion(str, #expr, __FILE__, __LINE__); \
147 } \
148 PR_END_MACRO
149
150/**
151 * Test a post-condition for truth. If the expression is not true then
152 * trigger a program failure.
153 */
154#define NS_POSTCONDITION(expr, str) \
155 PR_BEGIN_MACRO \
156 if (!(expr)) { \
157 nsDebug::Assertion(str, #expr, __FILE__, __LINE__); \
158 } \
159 PR_END_MACRO
160
161/**
162 * This macros triggers a program failure if executed. It indicates that
163 * an attempt was made to execute some unimplimented functionality.
164 */
165#define NS_NOTYETIMPLEMENTED(str) \
166 nsDebug::Assertion(str, "NotYetImplemented", __FILE__, __LINE__)
167
168/**
169 * This macros triggers a program failure if executed. It indicates that
170 * an attempt was made to execute some unimplimented functionality.
171 */
172#define NS_NOTREACHED(str) \
173 nsDebug::Assertion(str, "Not Reached", __FILE__, __LINE__)
174
175/**
176 * Log an error message.
177 */
178#define NS_ERROR(str) \
179 nsDebug::Assertion(str, "Error", __FILE__, __LINE__)
180
181/**
182 * Log a warning message.
183 */
184#define NS_WARNING(str) \
185 nsDebug::Warning(str, __FILE__, __LINE__)
186
187/**
188 * Trigger an abort
189 */
190#define NS_ABORT() \
191 nsDebug::Abort(__FILE__, __LINE__)
192
193/**
194 * Cause a break
195 */
196#define NS_BREAK() \
197 nsDebug::Break(__FILE__, __LINE__)
198
199#else /* NS_DEBUG */
200
201/**
202 * The non-debug version of these macros do not evaluate the
203 * expression or the message arguments to the macro.
204 */
205#define NS_ABORT_IF_FALSE(_expr, _msg) /* nothing */
206#define NS_WARN_IF_FALSE(_expr, _msg) /* nothing */
207#define NS_PRECONDITION(expr, str) /* nothing */
208#define NS_ASSERTION(expr, str) /* nothing */
209#define NS_POSTCONDITION(expr, str) /* nothing */
210#define NS_NOTYETIMPLEMENTED(str) /* nothing */
211#define NS_NOTREACHED(str) /* nothing */
212#define NS_ERROR(str) /* nothing */
213#define NS_WARNING(str) /* nothing */
214#define NS_ABORT() /* nothing */
215#define NS_BREAK() /* nothing */
216
217#endif /* ! NS_DEBUG */
218#endif /* __cplusplus */
219
220// Macros for checking the trueness of an expression passed in within an
221// interface implementation. These need to be compiled regardless of the
222// NS_DEBUG flag
223///////////////////////////////////////////////////////////////////////////////
224
225#define NS_ENSURE_TRUE(x, ret) \
226 PR_BEGIN_MACRO \
227 if (NS_UNLIKELY(!(x))) { \
228 NS_WARNING("NS_ENSURE_TRUE(" #x ") failed"); \
229 return ret; \
230 } \
231 PR_END_MACRO
232
233#define NS_ENSURE_FALSE(x, ret) \
234 NS_ENSURE_TRUE(!(x), ret)
235
236///////////////////////////////////////////////////////////////////////////////
237// Macros for checking results
238///////////////////////////////////////////////////////////////////////////////
239
240#define NS_ENSURE_SUCCESS(res, ret) \
241 NS_ENSURE_TRUE(NS_SUCCEEDED(res), ret)
242
243///////////////////////////////////////////////////////////////////////////////
244// Macros for checking state and arguments upon entering interface boundaries
245///////////////////////////////////////////////////////////////////////////////
246
247#define NS_ENSURE_ARG(arg) \
248 NS_ENSURE_TRUE(arg, NS_ERROR_INVALID_ARG)
249
250#define NS_ENSURE_ARG_POINTER(arg) \
251 NS_ENSURE_TRUE(arg, NS_ERROR_INVALID_POINTER)
252
253#define NS_ENSURE_ARG_MIN(arg, min) \
254 NS_ENSURE_TRUE((arg) >= min, NS_ERROR_INVALID_ARG)
255
256#define NS_ENSURE_ARG_MAX(arg, max) \
257 NS_ENSURE_TRUE((arg) <= max, NS_ERROR_INVALID_ARG)
258
259#define NS_ENSURE_ARG_RANGE(arg, min, max) \
260 NS_ENSURE_TRUE(((arg) >= min) && ((arg) <= max), NS_ERROR_INVALID_ARG)
261
262#define NS_ENSURE_STATE(state) \
263 NS_ENSURE_TRUE(state, NS_ERROR_UNEXPECTED)
264
265#define NS_ENSURE_NO_AGGREGATION(outer) \
266 NS_ENSURE_FALSE(outer, NS_ERROR_NO_AGGREGATION)
267
268#define NS_ENSURE_PROPER_AGGREGATION(outer, iid) \
269 NS_ENSURE_FALSE(outer && !iid.Equals(NS_GET_IID(nsISupports)), NS_ERROR_INVALID_ARG)
270
271///////////////////////////////////////////////////////////////////////////////
272
273#define NS_CheckThreadSafe(owningThread, msg) \
274 NS_ASSERTION(owningThread == PR_GetCurrentThread(), msg)
275
276#endif /* nsDebug_h___ */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette