1 | /* $Id: assert.cpp 1190 2007-03-04 20:42:13Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * InnoTek Portable Runtime - Assertion Workers.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #include <iprt/assert.h>
|
---|
27 | #include <iprt/log.h>
|
---|
28 | #include <iprt/string.h>
|
---|
29 | #include <iprt/stdarg.h>
|
---|
30 | #ifdef IN_RING3
|
---|
31 | # include <stdio.h>
|
---|
32 | #endif
|
---|
33 |
|
---|
34 |
|
---|
35 | #ifdef IN_GUEST_R0
|
---|
36 | #include <VBox/log.h>
|
---|
37 |
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * The 1st part of an assert message.
|
---|
41 | *
|
---|
42 | * @param pszExpr Expression. Can be NULL.
|
---|
43 | * @param uLine Location line number.
|
---|
44 | * @param pszFile Location file name.
|
---|
45 | * @param pszFunction Location function name.
|
---|
46 | * @remark This API exists in HC Ring-3 and GC.
|
---|
47 | */
|
---|
48 | RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
|
---|
49 | {
|
---|
50 | RTLogBackdoorPrintf("\n!!Assertion Failed!!\n"
|
---|
51 | "Expression: %s\n"
|
---|
52 | "Location : %s(%d) %s\n",
|
---|
53 | pszExpr, pszFile, uLine, pszFunction);
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * The 2nd (optional) part of an assert message.
|
---|
59 | *
|
---|
60 | * @param pszFormat Printf like format string.
|
---|
61 | * @param ... Arguments to that string.
|
---|
62 | * @remark This API exists in HC Ring-3 and GC.
|
---|
63 | */
|
---|
64 | RTDECL(void) AssertMsg2(const char *pszFormat, ...)
|
---|
65 | { /* forwarder. */
|
---|
66 | va_list args;
|
---|
67 | va_start(args, pszFormat);
|
---|
68 | RTLogBackdoorPrintfV(pszFormat, args);
|
---|
69 | va_end(args);
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | #elif defined(IN_RING0)
|
---|
74 |
|
---|
75 | /* OS specific. */
|
---|
76 |
|
---|
77 | #else /* !IN_RING0 */
|
---|
78 |
|
---|
79 |
|
---|
80 | /** The last assert message, 1st part. */
|
---|
81 | RTDATADECL(char) g_szRTAssertMsg1[1024];
|
---|
82 | /** The last assert message, 2nd part. */
|
---|
83 | RTDATADECL(char) g_szRTAssertMsg2[2048];
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * The 1st part of an assert message.
|
---|
87 | *
|
---|
88 | * @param pszExpr Expression. Can be NULL.
|
---|
89 | * @param uLine Location line number.
|
---|
90 | * @param pszFile Location file name.
|
---|
91 | * @param pszFunction Location function name.
|
---|
92 | * @remark This API exists in HC Ring-3 and GC.
|
---|
93 | */
|
---|
94 | RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
|
---|
95 | {
|
---|
96 | #if !defined(IN_RING3) && !defined(LOG_NO_COM)
|
---|
97 | RTLogComPrintf("\n!!Assertion Failed!!\n"
|
---|
98 | "Expression: %s\n"
|
---|
99 | "Location : %s(%d) %s\n",
|
---|
100 | pszExpr, pszFile, uLine, pszFunction);
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | PRTLOGGER pLog = RTLogRelDefaultInstance();
|
---|
104 | if (pLog)
|
---|
105 | {
|
---|
106 | RTLogRelPrintf("\n!!Assertion Failed!!\n"
|
---|
107 | "Expression: %s\n"
|
---|
108 | "Location : %s(%d) %s\n",
|
---|
109 | pszExpr, pszFile, uLine, pszFunction);
|
---|
110 | RTLogFlush(pLog);
|
---|
111 | }
|
---|
112 |
|
---|
113 | pLog = RTLogDefaultInstance();
|
---|
114 | if (pLog)
|
---|
115 | {
|
---|
116 | RTLogPrintf("\n!!Assertion Failed!!\n"
|
---|
117 | "Expression: %s\n"
|
---|
118 | "Location : %s(%d) %s\n",
|
---|
119 | pszExpr, pszFile, uLine, pszFunction);
|
---|
120 | RTLogFlush(pLog);
|
---|
121 | }
|
---|
122 |
|
---|
123 | #ifdef IN_RING3
|
---|
124 | /* print to stderr, helps user and gdb debugging. */
|
---|
125 | fprintf(stderr,
|
---|
126 | "\n!!Assertion Failed!!\n"
|
---|
127 | "Expression: %s\n"
|
---|
128 | "Location : %s(%d) %s\n",
|
---|
129 | pszExpr, pszFile, uLine, pszFunction);
|
---|
130 | fflush(stderr);
|
---|
131 | #endif
|
---|
132 |
|
---|
133 | RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
|
---|
134 | "\n!!Assertion Failed!!\n"
|
---|
135 | "Expression: %s\n"
|
---|
136 | "Location : %s(%d) %s\n",
|
---|
137 | pszExpr, pszFile, uLine, pszFunction);
|
---|
138 | }
|
---|
139 |
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * The 2nd (optional) part of an assert message.
|
---|
143 | *
|
---|
144 | * @param pszFormat Printf like format string.
|
---|
145 | * @param ... Arguments to that string.
|
---|
146 | * @remark This API exists in HC Ring-3 and GC.
|
---|
147 | */
|
---|
148 | RTDECL(void) AssertMsg2(const char *pszFormat, ...)
|
---|
149 | {
|
---|
150 | va_list args;
|
---|
151 |
|
---|
152 | #if !defined(IN_RING3) && !defined(LOG_NO_COM)
|
---|
153 | va_start(args, pszFormat);
|
---|
154 | RTLogComPrintfV(pszFormat, args);
|
---|
155 | va_end(args);
|
---|
156 | #endif
|
---|
157 |
|
---|
158 | PRTLOGGER pLog = RTLogRelDefaultInstance();
|
---|
159 | if (pLog)
|
---|
160 | {
|
---|
161 | va_start(args, pszFormat);
|
---|
162 | RTLogRelPrintfV(pszFormat, args);
|
---|
163 | va_end(args);
|
---|
164 | RTLogFlush(pLog);
|
---|
165 | }
|
---|
166 |
|
---|
167 | pLog = RTLogDefaultInstance();
|
---|
168 | if (pLog)
|
---|
169 | {
|
---|
170 | va_start(args, pszFormat);
|
---|
171 | RTLogPrintfV(pszFormat, args);
|
---|
172 | va_end(args);
|
---|
173 | RTLogFlush(pLog);
|
---|
174 | }
|
---|
175 |
|
---|
176 | #ifdef IN_RING3
|
---|
177 | /* print to stderr, helps user and gdb debugging. */
|
---|
178 | char szMsg[1024];
|
---|
179 | va_start(args, pszFormat);
|
---|
180 | RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, args);
|
---|
181 | va_end(args);
|
---|
182 | fprintf(stderr, "%s", szMsg);
|
---|
183 | fflush(stderr);
|
---|
184 | #endif
|
---|
185 |
|
---|
186 | va_start(args, pszFormat);
|
---|
187 | RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, args);
|
---|
188 | va_end(args);
|
---|
189 | }
|
---|
190 |
|
---|
191 | #endif /* !IN_RING0 */
|
---|
192 |
|
---|