VirtualBox

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

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

Export AssertMsg1 and 2 in Linux kernel modules

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1/* $Id: assert.cpp 4995 2007-09-24 09:29:27Z 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)
69EXPORT_SYMBOL(AssertMsg1);
70EXPORT_SYMBOL(AssertMsg2);
71#endif
72
73#elif defined(IN_RING0)
74
75/* OS specific. */
76
77#else /* !IN_RING0 */
78
79
80/** The last assert message, 1st part. */
81RTDATADECL(char) g_szRTAssertMsg1[1024];
82/** The last assert message, 2nd part. */
83RTDATADECL(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 */
94RTDECL(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 VALID_PTR(pszExpr) ? pszExpr : "<none>",
130 VALID_PTR(pszFile) ? pszFile : "<none>",
131 uLine,
132 VALID_PTR(pszFunction) ? pszFunction : "");
133 fflush(stderr);
134#endif
135
136 RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
137 "\n!!Assertion Failed!!\n"
138 "Expression: %s\n"
139 "Location : %s(%d) %s\n",
140 pszExpr, pszFile, uLine, pszFunction);
141}
142
143
144/**
145 * The 2nd (optional) part of an assert message.
146 *
147 * @param pszFormat Printf like format string.
148 * @param ... Arguments to that string.
149 * @remark This API exists in HC Ring-3 and GC.
150 */
151RTDECL(void) AssertMsg2(const char *pszFormat, ...)
152{
153 va_list args;
154
155#if !defined(IN_RING3) && !defined(LOG_NO_COM)
156 va_start(args, pszFormat);
157 RTLogComPrintfV(pszFormat, args);
158 va_end(args);
159#endif
160
161 PRTLOGGER pLog = RTLogRelDefaultInstance();
162 if (pLog)
163 {
164 va_start(args, pszFormat);
165 RTLogRelPrintfV(pszFormat, args);
166 va_end(args);
167 RTLogFlush(pLog);
168 }
169
170 pLog = RTLogDefaultInstance();
171 if (pLog)
172 {
173 va_start(args, pszFormat);
174 RTLogPrintfV(pszFormat, args);
175 va_end(args);
176 RTLogFlush(pLog);
177 }
178
179#ifdef IN_RING3
180 /* print to stderr, helps user and gdb debugging. */
181 char szMsg[1024];
182 va_start(args, pszFormat);
183 RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, args);
184 va_end(args);
185 fprintf(stderr, "%s", szMsg);
186 fflush(stderr);
187#endif
188
189 va_start(args, pszFormat);
190 RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, args);
191 va_end(args);
192}
193
194#endif /* !IN_RING0 */
195
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