VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/misc/assert.cpp@ 11280

Last change on this file since 11280 was 8245, checked in by vboxsync, 17 years ago

rebranding: IPRT files again.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.4 KB
Line 
1/* $Id: assert.cpp 8245 2008-04-21 17:24:28Z vboxsync $ */
2/** @file
3 * IPRT - Assertion Workers.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <iprt/assert.h>
36#include <iprt/log.h>
37#include <iprt/string.h>
38#include <iprt/stdarg.h>
39#ifdef IN_RING3
40# include <stdio.h>
41#endif
42
43
44#if defined(IN_GUEST_R0) && (defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS))
45/*
46 * This is legacy that should be eliminated. OS specific code deals with
47 * R0 assertions now and it will do the backdoor printfs in addition to
48 * proper OS specific printfs and panics / BSODs / IPEs.
49 */
50#include <VBox/log.h>
51
52
53/**
54 * The 1st part of an assert message.
55 *
56 * @param pszExpr Expression. Can be NULL.
57 * @param uLine Location line number.
58 * @param pszFile Location file name.
59 * @param pszFunction Location function name.
60 * @remark This API exists in HC Ring-3 and GC.
61 */
62RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
63{
64 RTLogBackdoorPrintf("\n!!Assertion Failed!!\n"
65 "Expression: %s\n"
66 "Location : %s(%d) %s\n",
67 pszExpr, pszFile, uLine, pszFunction);
68}
69
70
71/**
72 * The 2nd (optional) part of an assert message.
73 *
74 * @param pszFormat Printf like format string.
75 * @param ... Arguments to that string.
76 * @remark This API exists in HC Ring-3 and GC.
77 */
78RTDECL(void) AssertMsg2(const char *pszFormat, ...)
79{ /* forwarder. */
80 va_list args;
81 va_start(args, pszFormat);
82 RTLogBackdoorPrintfV(pszFormat, args);
83 va_end(args);
84}
85
86# if defined(RT_OS_LINUX) && defined(IN_MODULE)
87/*
88 * When we build this in the Linux kernel module, we wish to make the
89 * symbols available to other modules as well.
90 */
91# include "the-linux-kernel.h"
92EXPORT_SYMBOL(AssertMsg1);
93EXPORT_SYMBOL(AssertMsg2);
94# endif
95
96#elif defined(IN_RING0)
97
98/* OS specific. */
99
100#else /* !IN_RING0 */
101
102
103/** The last assert message, 1st part. */
104RTDATADECL(char) g_szRTAssertMsg1[1024];
105/** The last assert message, 2nd part. */
106RTDATADECL(char) g_szRTAssertMsg2[2048];
107
108/**
109 * The 1st part of an assert message.
110 *
111 * @param pszExpr Expression. Can be NULL.
112 * @param uLine Location line number.
113 * @param pszFile Location file name.
114 * @param pszFunction Location function name.
115 * @remark This API exists in HC Ring-3 and GC.
116 */
117RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
118{
119#if !defined(IN_RING3) && !defined(LOG_NO_COM)
120 RTLogComPrintf("\n!!Assertion Failed!!\n"
121 "Expression: %s\n"
122 "Location : %s(%d) %s\n",
123 pszExpr, pszFile, uLine, pszFunction);
124#endif
125
126 PRTLOGGER pLog = RTLogRelDefaultInstance();
127 if (pLog)
128 {
129 RTLogRelPrintf("\n!!Assertion Failed!!\n"
130 "Expression: %s\n"
131 "Location : %s(%d) %s\n",
132 pszExpr, pszFile, uLine, pszFunction);
133 RTLogFlush(pLog);
134 }
135
136 pLog = RTLogDefaultInstance();
137 if (pLog)
138 {
139 RTLogPrintf("\n!!Assertion Failed!!\n"
140 "Expression: %s\n"
141 "Location : %s(%d) %s\n",
142 pszExpr, pszFile, uLine, pszFunction);
143 RTLogFlush(pLog);
144 }
145
146#ifdef IN_RING3
147 /* print to stderr, helps user and gdb debugging. */
148 fprintf(stderr,
149 "\n!!Assertion Failed!!\n"
150 "Expression: %s\n"
151 "Location : %s(%d) %s\n",
152 VALID_PTR(pszExpr) ? pszExpr : "<none>",
153 VALID_PTR(pszFile) ? pszFile : "<none>",
154 uLine,
155 VALID_PTR(pszFunction) ? pszFunction : "");
156 fflush(stderr);
157#endif
158
159 RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
160 "\n!!Assertion Failed!!\n"
161 "Expression: %s\n"
162 "Location : %s(%d) %s\n",
163 pszExpr, pszFile, uLine, pszFunction);
164}
165
166
167/**
168 * The 2nd (optional) part of an assert message.
169 *
170 * @param pszFormat Printf like format string.
171 * @param ... Arguments to that string.
172 * @remark This API exists in HC Ring-3 and GC.
173 */
174RTDECL(void) AssertMsg2(const char *pszFormat, ...)
175{
176 va_list args;
177
178#if !defined(IN_RING3) && !defined(LOG_NO_COM)
179 va_start(args, pszFormat);
180 RTLogComPrintfV(pszFormat, args);
181 va_end(args);
182#endif
183
184 PRTLOGGER pLog = RTLogRelDefaultInstance();
185 if (pLog)
186 {
187 va_start(args, pszFormat);
188 RTLogRelPrintfV(pszFormat, args);
189 va_end(args);
190 RTLogFlush(pLog);
191 }
192
193 pLog = RTLogDefaultInstance();
194 if (pLog)
195 {
196 va_start(args, pszFormat);
197 RTLogPrintfV(pszFormat, args);
198 va_end(args);
199 RTLogFlush(pLog);
200 }
201
202#ifdef IN_RING3
203 /* print to stderr, helps user and gdb debugging. */
204 char szMsg[1024];
205 va_start(args, pszFormat);
206 RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, args);
207 va_end(args);
208 fprintf(stderr, "%s", szMsg);
209 fflush(stderr);
210#endif
211
212 va_start(args, pszFormat);
213 RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, args);
214 va_end(args);
215}
216
217#endif /* !IN_RING0 */
218
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