VirtualBox

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

Last change on this file since 7389 was 6657, checked in by vboxsync, 17 years ago

Use the generic templates for building the OS/2 guest additions. Removed all the OS/2 specific targets and templates.

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