VirtualBox

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

Last change on this file since 6372 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.0 KB
Line 
1/* $Id: assert.cpp 5999 2007-12-07 15:05:06Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Assertion Workers.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek 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 (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
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <iprt/assert.h>
32#include <iprt/log.h>
33#include <iprt/string.h>
34#include <iprt/stdarg.h>
35#ifdef IN_RING3
36# include <stdio.h>
37#endif
38
39
40#ifdef IN_GUEST_R0
41#include <VBox/log.h>
42
43
44/**
45 * The 1st part of an assert message.
46 *
47 * @param pszExpr Expression. Can be NULL.
48 * @param uLine Location line number.
49 * @param pszFile Location file name.
50 * @param pszFunction Location function name.
51 * @remark This API exists in HC Ring-3 and GC.
52 */
53RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
54{
55 RTLogBackdoorPrintf("\n!!Assertion Failed!!\n"
56 "Expression: %s\n"
57 "Location : %s(%d) %s\n",
58 pszExpr, pszFile, uLine, pszFunction);
59}
60
61
62/**
63 * The 2nd (optional) part of an assert message.
64 *
65 * @param pszFormat Printf like format string.
66 * @param ... Arguments to that string.
67 * @remark This API exists in HC Ring-3 and GC.
68 */
69RTDECL(void) AssertMsg2(const char *pszFormat, ...)
70{ /* forwarder. */
71 va_list args;
72 va_start(args, pszFormat);
73 RTLogBackdoorPrintfV(pszFormat, args);
74 va_end(args);
75}
76
77#if defined(RT_OS_LINUX) && defined(IN_MODULE)
78/*
79 * When we build this in the Linux kernel module, we wish to make the
80 * symbols available to other modules as well.
81 */
82# include "the-linux-kernel.h"
83EXPORT_SYMBOL(AssertMsg1);
84EXPORT_SYMBOL(AssertMsg2);
85#endif
86
87#elif defined(IN_RING0)
88
89/* OS specific. */
90
91#else /* !IN_RING0 */
92
93
94/** The last assert message, 1st part. */
95RTDATADECL(char) g_szRTAssertMsg1[1024];
96/** The last assert message, 2nd part. */
97RTDATADECL(char) g_szRTAssertMsg2[2048];
98
99/**
100 * The 1st part of an assert message.
101 *
102 * @param pszExpr Expression. Can be NULL.
103 * @param uLine Location line number.
104 * @param pszFile Location file name.
105 * @param pszFunction Location function name.
106 * @remark This API exists in HC Ring-3 and GC.
107 */
108RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
109{
110#if !defined(IN_RING3) && !defined(LOG_NO_COM)
111 RTLogComPrintf("\n!!Assertion Failed!!\n"
112 "Expression: %s\n"
113 "Location : %s(%d) %s\n",
114 pszExpr, pszFile, uLine, pszFunction);
115#endif
116
117 PRTLOGGER pLog = RTLogRelDefaultInstance();
118 if (pLog)
119 {
120 RTLogRelPrintf("\n!!Assertion Failed!!\n"
121 "Expression: %s\n"
122 "Location : %s(%d) %s\n",
123 pszExpr, pszFile, uLine, pszFunction);
124 RTLogFlush(pLog);
125 }
126
127 pLog = RTLogDefaultInstance();
128 if (pLog)
129 {
130 RTLogPrintf("\n!!Assertion Failed!!\n"
131 "Expression: %s\n"
132 "Location : %s(%d) %s\n",
133 pszExpr, pszFile, uLine, pszFunction);
134 RTLogFlush(pLog);
135 }
136
137#ifdef IN_RING3
138 /* print to stderr, helps user and gdb debugging. */
139 fprintf(stderr,
140 "\n!!Assertion Failed!!\n"
141 "Expression: %s\n"
142 "Location : %s(%d) %s\n",
143 VALID_PTR(pszExpr) ? pszExpr : "<none>",
144 VALID_PTR(pszFile) ? pszFile : "<none>",
145 uLine,
146 VALID_PTR(pszFunction) ? pszFunction : "");
147 fflush(stderr);
148#endif
149
150 RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
151 "\n!!Assertion Failed!!\n"
152 "Expression: %s\n"
153 "Location : %s(%d) %s\n",
154 pszExpr, pszFile, uLine, pszFunction);
155}
156
157
158/**
159 * The 2nd (optional) part of an assert message.
160 *
161 * @param pszFormat Printf like format string.
162 * @param ... Arguments to that string.
163 * @remark This API exists in HC Ring-3 and GC.
164 */
165RTDECL(void) AssertMsg2(const char *pszFormat, ...)
166{
167 va_list args;
168
169#if !defined(IN_RING3) && !defined(LOG_NO_COM)
170 va_start(args, pszFormat);
171 RTLogComPrintfV(pszFormat, args);
172 va_end(args);
173#endif
174
175 PRTLOGGER pLog = RTLogRelDefaultInstance();
176 if (pLog)
177 {
178 va_start(args, pszFormat);
179 RTLogRelPrintfV(pszFormat, args);
180 va_end(args);
181 RTLogFlush(pLog);
182 }
183
184 pLog = RTLogDefaultInstance();
185 if (pLog)
186 {
187 va_start(args, pszFormat);
188 RTLogPrintfV(pszFormat, args);
189 va_end(args);
190 RTLogFlush(pLog);
191 }
192
193#ifdef IN_RING3
194 /* print to stderr, helps user and gdb debugging. */
195 char szMsg[1024];
196 va_start(args, pszFormat);
197 RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, args);
198 va_end(args);
199 fprintf(stderr, "%s", szMsg);
200 fflush(stderr);
201#endif
202
203 va_start(args, pszFormat);
204 RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, args);
205 va_end(args);
206}
207
208#endif /* !IN_RING0 */
209
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