VirtualBox

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

Last change on this file was 106112, checked in by vboxsync, 3 months ago

libs/xpcom: Fix building code using the XPCOM SDK bindings outside of VirtualBox, ticketref:22714 bugref:10773

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.8 KB
Line 
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#ifdef VBOX
42# include <iprt/thread.h>
43#endif
44
45#ifndef nscore_h___
46#include "nscore.h"
47#endif
48
49#ifndef nsError_h__
50#include "nsError.h"
51#endif
52
53#ifdef DEBUG
54#define NS_DEBUG
55#endif
56
57/**
58 * Namespace for debugging methods. Note that your code must use the
59 * macros defined later in this file so that the debug code can be
60 * conditionally compiled out.
61 */
62
63/* in case this is included by a C file */
64#ifdef __cplusplus
65
66class nsDebug {
67public:
68
69 /**
70 * Log a warning message to the debug log.
71 */
72 static NS_COM void Warning(const char* aMessage,
73 const char* aFile, PRIntn aLine);
74
75 /**
76 * Abort the executing program. This works on all architectures.
77 */
78 static NS_COM void Abort(const char* aFile, PRIntn aLine);
79
80 /**
81 * Break the executing program into the debugger.
82 */
83 static NS_COM void Break(const char* aFile, PRIntn aLine);
84
85 /**
86 * Log an assertion message to the debug log
87 */
88 static NS_COM void Assertion(const char* aStr, const char* aExpr,
89 const char* aFile, PRIntn aLine);
90};
91
92#ifdef DEBUG
93
94/**
95 * Abort the execution of the program if the expression evaluates to
96 * false.
97 *
98 * There is no status value returned from the macro.
99 *
100 * Note that the non-debug version of this macro does <b>not</b>
101 * evaluate the expression argument. Hence side effect statements
102 * as arguments to the macro will yield improper execution in a
103 * non-debug build. For example:
104 *
105 * NS_ABORT_IF_FALSE(0 == foo++, "yikes foo should be zero");
106 *
107 * Note also that the non-debug version of this macro does <b>not</b>
108 * evaluate the message argument.
109 */
110#define NS_ABORT_IF_FALSE(_expr, _msg) \
111 PR_BEGIN_MACRO \
112 if (!(_expr)) { \
113 nsDebug::Assertion(_msg, #_expr, __FILE__, __LINE__); \
114 } \
115 PR_END_MACRO
116
117/**
118 * Warn if a given condition is false.
119 *
120 * Program execution continues past the usage of this macro.
121 *
122 * Note also that the non-debug version of this macro does <b>not</b>
123 * evaluate the message argument.
124 */
125#define NS_WARN_IF_FALSE(_expr,_msg) \
126 PR_BEGIN_MACRO \
127 if (!(_expr)) { \
128 nsDebug::Assertion(_msg, #_expr, __FILE__, __LINE__); \
129 } \
130 PR_END_MACRO
131
132/**
133 * Test a precondition for truth. If the expression is not true then
134 * trigger a program failure.
135 */
136#define NS_PRECONDITION(expr, str) \
137 PR_BEGIN_MACRO \
138 if (!(expr)) { \
139 nsDebug::Assertion(str, #expr, __FILE__, __LINE__); \
140 } \
141 PR_END_MACRO
142
143/**
144 * Test an assertion for truth. If the expression is not true then
145 * trigger a program failure.
146 */
147#define NS_ASSERTION(expr, str) \
148 PR_BEGIN_MACRO \
149 if (!(expr)) { \
150 nsDebug::Assertion(str, #expr, __FILE__, __LINE__); \
151 } \
152 PR_END_MACRO
153
154/**
155 * Test a post-condition for truth. If the expression is not true then
156 * trigger a program failure.
157 */
158#define NS_POSTCONDITION(expr, str) \
159 PR_BEGIN_MACRO \
160 if (!(expr)) { \
161 nsDebug::Assertion(str, #expr, __FILE__, __LINE__); \
162 } \
163 PR_END_MACRO
164
165/**
166 * This macros triggers a program failure if executed. It indicates that
167 * an attempt was made to execute some unimplimented functionality.
168 */
169#define NS_NOTYETIMPLEMENTED(str) \
170 nsDebug::Assertion(str, "NotYetImplemented", __FILE__, __LINE__)
171
172/**
173 * This macros triggers a program failure if executed. It indicates that
174 * an attempt was made to execute some unimplimented functionality.
175 */
176#define NS_NOTREACHED(str) \
177 nsDebug::Assertion(str, "Not Reached", __FILE__, __LINE__)
178
179/**
180 * Log an error message.
181 */
182#define NS_ERROR(str) \
183 nsDebug::Assertion(str, "Error", __FILE__, __LINE__)
184
185/**
186 * Log a warning message.
187 */
188#define NS_WARNING(str) \
189 nsDebug::Warning(str, __FILE__, __LINE__)
190
191/**
192 * Trigger an abort
193 */
194#define NS_ABORT() \
195 nsDebug::Abort(__FILE__, __LINE__)
196
197/**
198 * Cause a break
199 */
200#define NS_BREAK() \
201 nsDebug::Break(__FILE__, __LINE__)
202
203#else /* NS_DEBUG */
204
205/**
206 * The non-debug version of these macros do not evaluate the
207 * expression or the message arguments to the macro.
208 */
209#define NS_ABORT_IF_FALSE(_expr, _msg) /* nothing */
210#define NS_WARN_IF_FALSE(_expr, _msg) /* nothing */
211#define NS_PRECONDITION(expr, str) /* nothing */
212#define NS_ASSERTION(expr, str) /* nothing */
213#define NS_POSTCONDITION(expr, str) /* nothing */
214#define NS_NOTYETIMPLEMENTED(str) /* nothing */
215#define NS_NOTREACHED(str) /* nothing */
216#define NS_ERROR(str) /* nothing */
217#define NS_WARNING(str) /* nothing */
218#define NS_ABORT() /* nothing */
219#define NS_BREAK() /* nothing */
220
221#endif /* ! NS_DEBUG */
222#endif /* __cplusplus */
223
224// Macros for checking the trueness of an expression passed in within an
225// interface implementation. These need to be compiled regardless of the
226// NS_DEBUG flag
227///////////////////////////////////////////////////////////////////////////////
228
229#define NS_ENSURE_TRUE(x, ret) \
230 PR_BEGIN_MACRO \
231 if (NS_UNLIKELY(!(x))) { \
232 NS_WARNING("NS_ENSURE_TRUE(" #x ") failed"); \
233 return ret; \
234 } \
235 PR_END_MACRO
236
237#define NS_ENSURE_FALSE(x, ret) \
238 NS_ENSURE_TRUE(!(x), ret)
239
240///////////////////////////////////////////////////////////////////////////////
241// Macros for checking results
242///////////////////////////////////////////////////////////////////////////////
243
244#define NS_ENSURE_SUCCESS(res, ret) \
245 NS_ENSURE_TRUE(NS_SUCCEEDED(res), ret)
246
247///////////////////////////////////////////////////////////////////////////////
248// Macros for checking state and arguments upon entering interface boundaries
249///////////////////////////////////////////////////////////////////////////////
250
251#define NS_ENSURE_ARG(arg) \
252 NS_ENSURE_TRUE(arg, NS_ERROR_INVALID_ARG)
253
254#define NS_ENSURE_ARG_POINTER(arg) \
255 NS_ENSURE_TRUE(arg, NS_ERROR_INVALID_POINTER)
256
257#define NS_ENSURE_ARG_MIN(arg, min) \
258 NS_ENSURE_TRUE((arg) >= min, NS_ERROR_INVALID_ARG)
259
260#define NS_ENSURE_ARG_MAX(arg, max) \
261 NS_ENSURE_TRUE((arg) <= max, NS_ERROR_INVALID_ARG)
262
263#define NS_ENSURE_ARG_RANGE(arg, min, max) \
264 NS_ENSURE_TRUE(((arg) >= min) && ((arg) <= max), NS_ERROR_INVALID_ARG)
265
266#define NS_ENSURE_STATE(state) \
267 NS_ENSURE_TRUE(state, NS_ERROR_UNEXPECTED)
268
269#define NS_ENSURE_NO_AGGREGATION(outer) \
270 NS_ENSURE_FALSE(outer, NS_ERROR_NO_AGGREGATION)
271
272#define NS_ENSURE_PROPER_AGGREGATION(outer, iid) \
273 NS_ENSURE_FALSE(outer && !iid.Equals(NS_GET_IID(nsISupports)), NS_ERROR_INVALID_ARG)
274
275///////////////////////////////////////////////////////////////////////////////
276
277#ifdef VBOX
278#define NS_CheckThreadSafe(owningThread, msg) \
279 NS_ASSERTION(owningThread == RTThreadSelf(), msg)
280#endif
281
282#endif /* nsDebug_h___ */
Note: See TracBrowser for help on using the repository browser.

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