VirtualBox

source: vbox/trunk/src/VBox/Runtime/assert.cpp@ 5355

Last change on this file since 5355 was 5070, checked in by vboxsync, 17 years ago

Attempt to fix the Linux smoked tests

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