VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/os2/assert-r0drv-os2.cpp@ 1191

Last change on this file since 1191 was 1191, checked in by vboxsync, 18 years ago

svn properties.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1/* $Id: assert-r0drv-os2.cpp 1191 2007-03-04 20:46:04Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime - Assertion Workers, Ring-0 Drivers, OS/2.
4 */
5
6
7/*******************************************************************************
8* Header Files *
9*******************************************************************************/
10#include <iprt/assert.h>
11#include <iprt/log.h>
12#include <iprt/string.h>
13#include <iprt/stdarg.h>
14
15#include <VBox/log.h>
16
17
18/*******************************************************************************
19* Global Variables *
20*******************************************************************************/
21/** The last assert message. (in DATA16) */
22extern char g_szRTAssertMsg[2048];
23/** The length of the last assert message. (in DATA16) */
24extern size_t g_cchRTAssertMsg;
25
26/*******************************************************************************
27* Internal Functions *
28*******************************************************************************/
29static DECLCALLBACK(size_t) rtR0Os2AssertOutputCB(void *pvArg, const char *pachChars, size_t cbChars);
30
31
32/**
33 * The 1st part of an assert message.
34 *
35 * @param pszExpr Expression. Can be NULL.
36 * @param uLine Location line number.
37 * @param pszFile Location file name.
38 * @param pszFunction Location function name.
39 * @remark This API exists in HC Ring-3 and GC.
40 */
41RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
42{
43#ifdef IN_GUEST_R0
44 RTLogBackdoorPrintf("\n!!Assertion Failed!!\n"
45 "Expression: %s\n"
46 "Location : %s(%d) %s\n",
47 pszExpr, pszFile, uLine, pszFunction);
48#endif
49
50#if defined(DEBUG_bird)
51 RTLogComPrintf("\n!!Assertion Failed!!\n"
52 "Expression: %s\n"
53 "Location : %s(%d) %s\n",
54 pszExpr, pszFile, uLine, pszFunction);
55#endif
56
57 g_cchRTAssertMsg = RTStrPrintf(g_szRTAssertMsg, sizeof(g_szRTAssertMsg),
58 "\r\n!!Assertion Failed!!\r\n"
59 "Expression: %s\r\n"
60 "Location : %s(%d) %s\r\n",
61 pszExpr, pszFile, uLine, pszFunction);
62}
63
64
65/**
66 * The 2nd (optional) part of an assert message.
67 *
68 * @param pszFormat Printf like format string.
69 * @param ... Arguments to that string.
70 * @remark This API exists in HC Ring-3 and GC.
71 */
72RTDECL(void) AssertMsg2(const char *pszFormat, ...)
73{
74 va_list va;
75
76#ifdef IN_GUEST_R0
77 va_start(va, pszFormat);
78 RTLogBackdoorPrintfV(pszFormat, va);
79 va_end(va);
80#endif
81
82#if defined(DEBUG_bird)
83 va_start(va, pszFormat);
84 RTLogComPrintfV(pszFormat, va);
85 va_end(va);
86#endif
87
88 va_start(va, pszFormat);
89 size_t cch = g_cchRTAssertMsg;
90 char *pch = &g_szRTAssertMsg[cch];
91 cch += RTStrFormatV(rtR0Os2AssertOutputCB, &pch, NULL, NULL, pszFormat, va);
92 g_cchRTAssertMsg = cch;
93 va_end(va);
94}
95
96
97/**
98 * Output callback.
99 *
100 * @returns number of bytes written.
101 * @param pvArg Pointer to a char pointer with the current output position.
102 * @param pachChars Pointer to an array of utf-8 characters.
103 * @param cbChars Number of bytes in the character array pointed to by pachChars.
104 */
105static DECLCALLBACK(size_t) rtR0Os2AssertOutputCB(void *pvArg, const char *pachChars, size_t cbChars)
106{
107 char **ppch = (char **)pvArg;
108 char *pch = *ppch;
109
110 while (cbChars-- > 0)
111 {
112 const char ch = *pachChars++;
113 if (ch == '\r')
114 continue;
115 if (ch == '\n')
116 {
117 if (pch + 1 >= &g_szRTAssertMsg[sizeof(g_szRTAssertMsg)])
118 break;
119 *pch++ = '\r';
120 }
121 if (pch + 1 >= &g_szRTAssertMsg[sizeof(g_szRTAssertMsg)])
122 break;
123 *pch++ = ch;
124 }
125 *pch = '\0';
126
127 size_t cbWritten = pch - *ppch;
128 *ppch = pch;
129 return cbWritten;
130}
131
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette