VirtualBox

source: vbox/trunk/include/VBox/com/errorprint_legacy.h@ 16857

Last change on this file since 16857 was 16530, checked in by vboxsync, 16 years ago

Main: rework error macros everywhere; make error messages much more readable (esp. with VBoxManage); use shared function to actually print message; reduces size of VBoxManage debug build from 3.4 to 2.3 MB

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1/** @file
2 * MS COM / XPCOM Abstraction Layer:
3 * Legacy error printing macros for COM/XPCOM (used with testcases).
4 *
5 * NOTE: to lighten the load on the compilers, please use the shared
6 * functions in errorprint2.h for new code.
7 */
8
9/*
10 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
11 *
12 * This file is part of VirtualBox Open Source Edition (OSE), as
13 * available from http://www.virtualbox.org. This file is free software;
14 * you can redistribute it and/or modify it under the terms of the GNU
15 * General Public License (GPL) as published by the Free Software
16 * Foundation, in version 2 as it comes in the "COPYING" file of the
17 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19 *
20 * The contents of this file may alternatively be used under the terms
21 * of the Common Development and Distribution License Version 1.0
22 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
23 * VirtualBox OSE distribution, in which case the provisions of the
24 * CDDL are applicable instead of those of the GPL.
25 *
26 * You may elect to license modified versions of this file under the
27 * terms and conditions of either the GPL or the CDDL or both.
28 *
29 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
30 * Clara, CA 95054 USA or visit http://www.sun.com if you need
31 * additional information or have any questions.
32 */
33
34#ifndef ___VBox_com_errorprint_legacy_h
35#define ___VBox_com_errorprint_legacy_h
36
37#include <iprt/assert.h>
38
39/*
40 * A section of helpful macros for error output
41 */
42
43/**
44 * Prints a line describing the given COM result code.
45 * Used by command line tools or for debugging.
46 */
47#define PRINT_RC_MESSAGE(rc) \
48 do { \
49 RTPrintf ("[!] Primary RC = %Rhra\n", rc); \
50 Log (("[!] Primary RC = %Rhra\n", rc)); \
51 } while (0)
52
53/**
54 * Prints the extended error information.
55 * Used by command line tools or for debugging.
56 *
57 * @param info com::ErrorInfo instance
58 */
59#define PRINT_ERROR_INFO(info) \
60 do { \
61 RTPrintf ("[!] Full error info present: %RTbool, basic error info present: %RTbool\n", \
62 info.isFullAvailable(), info.isBasicAvailable()); \
63 Log (("[!] Full error info present: %RTbool, basic error info present: %RTbool\n", \
64 info.isFullAvailable(), info.isBasicAvailable())); \
65 if (info.isFullAvailable() || info.isBasicAvailable()) { \
66 RTPrintf ("[!] Result Code = %Rhra\n", info.getResultCode()); \
67 RTPrintf ("[!] Text = %ls\n", info.getText().raw()); \
68 RTPrintf ("[!] Component = %ls, Interface: %ls, {%RTuuid}\n", \
69 info.getComponent().raw(), info.getInterfaceName().raw(), \
70 info.getInterfaceID().raw()); \
71 RTPrintf ("[!] Callee = %ls, {%RTuuid}\n", \
72 info.getCalleeName().raw(), info.getCalleeIID().raw()); \
73 Log (("[!] Result Code = %Rhra\n", info.getResultCode())); \
74 Log (("[!] Text = %ls\n", info.getText().raw())); \
75 Log (("[!] Component = %ls, Interface: %ls, {%RTuuid}\n", \
76 info.getComponent().raw(), info.getInterfaceName().raw(), \
77 info.getInterfaceID().raw())); \
78 Log (("[!] Callee = %ls, {%RTuuid}\n", \
79 info.getCalleeName().raw(), info.getCalleeIID().raw())); \
80 } \
81 } while (0)
82
83/**
84 * Calls the given interface method and then checks if the return value
85 * (COM result code) indicates a failure. If so, prints the failed
86 * function/line/file and the description of the result code.
87 *
88 * Used by command line tools or for debugging and assumes the |HRESULT rc|
89 * variable is accessible for assigning in the current scope.
90 */
91#define CHECK_RC(method) \
92 do { \
93 rc = method; \
94 if (FAILED (rc)) { \
95 RTPrintf ("[!] FAILED calling " #method " at line %d!\n", __LINE__); \
96 Log (("[!] FAILED calling " #method " at line %d!\n", __LINE__)); \
97 PRINT_RC_MESSAGE(rc); \
98 } \
99 } while (0)
100
101/**
102 * Does the same as CHECK_RC(), but executes the |return rc| statement on
103 * failure.
104 */
105#define CHECK_RC_RET(method) \
106 do { CHECK_RC (method); if (FAILED (rc)) return rc; } while (0)
107
108/**
109 * Does the same as CHECK_RC(), but executes the |break| statement on
110 * failure.
111 */
112#define CHECK_RC_BREAK(method) \
113 if (1) { CHECK_RC (method); if (FAILED (rc)) break; } else do {} while (0)
114
115/**
116 * Calls the given method of the given interface and then checks if the return
117 * value (COM result code) indicates a failure. If so, prints the failed
118 * function/line/file, the description of the result code and attempts to
119 * query the extended error information on the current thread (using
120 * com::ErrorInfo) if the interface reports that it supports error information.
121 *
122 * Used by command line tools or for debugging and assumes the |HRESULT rc|
123 * variable is accessible for assigning in the current scope.
124 */
125#define CHECK_ERROR(iface, method) \
126 do \
127 { \
128 CHECK_RC(iface->method); \
129 if (FAILED(rc)) { \
130 com::ErrorInfo info (iface); \
131 PRINT_ERROR_INFO (info); \
132 } \
133 } while (0)
134
135/**
136 * Does the same as CHECK_ERROR(), but executes the |return ret| statement on
137 * failure.
138 */
139#define CHECK_ERROR_RET(iface, method, ret) \
140 do { CHECK_ERROR (iface, method); if (FAILED (rc)) return (ret); } while (0)
141
142/**
143 * Does the same as CHECK_ERROR(), but executes the |break| statement on
144 * failure.
145 */
146#if defined(__GNUC__)
147 #define CHECK_ERROR_BREAK(iface, method) \
148 ({ CHECK_ERROR (iface, method); if (FAILED (rc)) break; })
149#else
150 #define CHECK_ERROR_BREAK(iface, method) \
151 if (1) { CHECK_ERROR (iface, method); if (FAILED (rc)) break; } else do {} while (0)
152#endif
153
154#define CHECK_ERROR_NOCALL() \
155 do { \
156 com::ErrorInfo info; \
157 PRINT_ERROR_INFO (info); \
158 } while (0)
159
160/**
161 * Does the same as CHECK_ERROR(), but doesn't need the interface pointer
162 * because doesn't do a check whether the interface supports error info or not.
163 */
164#define CHECK_ERROR_NI(method) \
165 do { \
166 CHECK_RC (method); \
167 if (FAILED (rc)) { \
168 com::ErrorInfo info; \
169 PRINT_ERROR_INFO (info); \
170 } \
171 } while (0)
172
173/**
174 * Does the same as CHECK_ERROR_NI(), but executes the |return rc| statement
175 * on failure.
176 */
177#define CHECK_ERROR_NI_RET(method) \
178 do { CHECK_ERROR_NI (method); if (FAILED (rc)) return rc; } while (0)
179
180/**
181 * Does the same as CHECK_ERROR_NI(), but executes the |break| statement
182 * on failure.
183 */
184#define CHECK_ERROR_NI_BREAK(method) \
185 if (1) { CHECK_ERROR_NI (method); if (FAILED (rc)) break; } else do {} while (0)
186
187
188/**
189 * Asserts the given expression is true. When the expression is false, prints
190 * a line containing the failed function/line/file; otherwise does nothing.
191 */
192#define ASSERT(expr) \
193 do { \
194 if (!(expr)) \
195 { \
196 RTPrintf ("[!] ASSERTION FAILED at line %d: %s\n", __LINE__, #expr); \
197 Log (("[!] ASSERTION FAILED at line %d: %s\n", __LINE__, #expr)); \
198 } \
199 } while (0)
200
201/**
202 * Does the same as ASSERT(), but executes the |return ret| statement if the
203 * expression to assert is false.
204 */
205#define ASSERT_RET(expr, ret) \
206 do { ASSERT (expr); if (!(expr)) return (ret); } while (0)
207
208/**
209 * Does the same as ASSERT(), but executes the |break| statement if the
210 * expression to assert is false.
211 */
212#define ASSERT_BREAK(expr) \
213 if (1) { ASSERT (expr); if (!(expr)) break; } else do {} while (0)
214
215
216#endif
217
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