VirtualBox

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

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

Solaris doesn't seem to check for null string pointers in *printfv (%s).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1/* $Id: assert.cpp 4856 2007-09-17 14:55:39Z 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
69#elif defined(IN_RING0)
70
71/* OS specific. */
72
73#else /* !IN_RING0 */
74
75
76/** The last assert message, 1st part. */
77RTDATADECL(char) g_szRTAssertMsg1[1024];
78/** The last assert message, 2nd part. */
79RTDATADECL(char) g_szRTAssertMsg2[2048];
80
81/**
82 * The 1st part of an assert message.
83 *
84 * @param pszExpr Expression. Can be NULL.
85 * @param uLine Location line number.
86 * @param pszFile Location file name.
87 * @param pszFunction Location function name.
88 * @remark This API exists in HC Ring-3 and GC.
89 */
90RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
91{
92#if !defined(IN_RING3) && !defined(LOG_NO_COM)
93 RTLogComPrintf("\n!!Assertion Failed!!\n"
94 "Expression: %s\n"
95 "Location : %s(%d) %s\n",
96 pszExpr, pszFile, uLine, pszFunction);
97#endif
98
99 PRTLOGGER pLog = RTLogRelDefaultInstance();
100 if (pLog)
101 {
102 RTLogRelPrintf("\n!!Assertion Failed!!\n"
103 "Expression: %s\n"
104 "Location : %s(%d) %s\n",
105 pszExpr, pszFile, uLine, pszFunction);
106 RTLogFlush(pLog);
107 }
108
109 pLog = RTLogDefaultInstance();
110 if (pLog)
111 {
112 RTLogPrintf("\n!!Assertion Failed!!\n"
113 "Expression: %s\n"
114 "Location : %s(%d) %s\n",
115 pszExpr, pszFile, uLine, pszFunction);
116 RTLogFlush(pLog);
117 }
118
119#ifdef IN_RING3
120 /* print to stderr, helps user and gdb debugging. */
121 fprintf(stderr,
122 "\n!!Assertion Failed!!\n"
123 "Expression: %s\n"
124 "Location : %s(%d) %s\n",
125 VALID_PTR(pszExpr) ? pszExpr : "<none>",
126 VALID_PTR(pszFile) ? pszFile : "<none>",
127 uLine,
128 VALID_PTR(pszFunction) ? pszFunction : "");
129 fflush(stderr);
130#endif
131
132 RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
133 "\n!!Assertion Failed!!\n"
134 "Expression: %s\n"
135 "Location : %s(%d) %s\n",
136 pszExpr, pszFile, uLine, pszFunction);
137}
138
139
140/**
141 * The 2nd (optional) part of an assert message.
142 *
143 * @param pszFormat Printf like format string.
144 * @param ... Arguments to that string.
145 * @remark This API exists in HC Ring-3 and GC.
146 */
147RTDECL(void) AssertMsg2(const char *pszFormat, ...)
148{
149 va_list args;
150
151#if !defined(IN_RING3) && !defined(LOG_NO_COM)
152 va_start(args, pszFormat);
153 RTLogComPrintfV(pszFormat, args);
154 va_end(args);
155#endif
156
157 PRTLOGGER pLog = RTLogRelDefaultInstance();
158 if (pLog)
159 {
160 va_start(args, pszFormat);
161 RTLogRelPrintfV(pszFormat, args);
162 va_end(args);
163 RTLogFlush(pLog);
164 }
165
166 pLog = RTLogDefaultInstance();
167 if (pLog)
168 {
169 va_start(args, pszFormat);
170 RTLogPrintfV(pszFormat, args);
171 va_end(args);
172 RTLogFlush(pLog);
173 }
174
175#ifdef IN_RING3
176 /* print to stderr, helps user and gdb debugging. */
177 char szMsg[1024];
178 va_start(args, pszFormat);
179 RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, args);
180 va_end(args);
181 fprintf(stderr, "%s", szMsg);
182 fflush(stderr);
183#endif
184
185 va_start(args, pszFormat);
186 RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, args);
187 va_end(args);
188}
189
190#endif /* !IN_RING0 */
191
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