1 | /* $Id: error.c 78408 2019-05-06 21:31:01Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox crOpenGL error logging
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2014-2019 Oracle Corporation
|
---|
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 |
|
---|
18 | #define LOG_GROUP LOG_GROUP_SHARED_CROPENGL
|
---|
19 |
|
---|
20 | #include <iprt/string.h>
|
---|
21 | #include <iprt/stream.h>
|
---|
22 | #include <iprt/initterm.h>
|
---|
23 | #include <iprt/asm.h>
|
---|
24 | #include <iprt/assert.h>
|
---|
25 | #include <iprt/buildconfig.h>
|
---|
26 |
|
---|
27 |
|
---|
28 | #include <VBox/log.h>
|
---|
29 | #include <iprt/env.h>
|
---|
30 |
|
---|
31 | #ifdef RT_OS_WINDOWS
|
---|
32 | # include <iprt/win/windows.h>
|
---|
33 | #endif
|
---|
34 | #include "cr_error.h"
|
---|
35 |
|
---|
36 | #include <signal.h>
|
---|
37 | #include <stdlib.h>
|
---|
38 |
|
---|
39 |
|
---|
40 | /*
|
---|
41 | * Stuff that needs to be dragged into the link because other DLLs needs it.
|
---|
42 | * See also VBoxDeps.cpp in iprt and xpcom.
|
---|
43 | */
|
---|
44 | #ifdef _MSC_VER
|
---|
45 | # pragma warning(push)
|
---|
46 | # pragma warning(disable:4232) /* nonstandard extension used: 'g_VBoxRTDeps' : address of dllimport 'RTBldCfgRevision' is not static, identiy not guaranteed */
|
---|
47 | #endif
|
---|
48 | PFNRT g_VBoxRTDeps[] =
|
---|
49 | {
|
---|
50 | (PFNRT)RTAssertShouldPanic,
|
---|
51 | (PFNRT)ASMAtomicReadU64,
|
---|
52 | (PFNRT)ASMAtomicCmpXchgU64,
|
---|
53 | (PFNRT)ASMBitFirstSet,
|
---|
54 | (PFNRT)RTBldCfgRevision,
|
---|
55 | };
|
---|
56 | #ifdef _MSC_VER
|
---|
57 | # pragma warning(pop)
|
---|
58 | #endif
|
---|
59 |
|
---|
60 |
|
---|
61 | static void logMessageV(const char *pszPrefix, const char *pszFormat, va_list va)
|
---|
62 | {
|
---|
63 | va_list vaCopy;
|
---|
64 | if (RTR3InitIsInitialized())
|
---|
65 | {
|
---|
66 | va_copy(vaCopy, va);
|
---|
67 | LogRel(("%s%N\n", pszPrefix, pszFormat, &vaCopy));
|
---|
68 | va_end(vaCopy);
|
---|
69 | }
|
---|
70 |
|
---|
71 | #ifdef IN_GUEST /** @todo Could be subject to pre-iprt-init issues, but hopefully not... */
|
---|
72 | va_copy(vaCopy, va);
|
---|
73 | RTStrmPrintf(g_pStdErr, "%s%N\n", pszPrefix, pszFormat, &vaCopy);
|
---|
74 | va_end(vaCopy);
|
---|
75 | #endif
|
---|
76 | }
|
---|
77 |
|
---|
78 | #ifdef WINDOWS
|
---|
79 | static void logMessage(const char *pszPrefix, const char *pszFormat, ...)
|
---|
80 | {
|
---|
81 | va_list va;
|
---|
82 |
|
---|
83 | va_start(va, pszFormat);
|
---|
84 | logMessageV(pszPrefix, pszFormat, va);
|
---|
85 | va_end(va);
|
---|
86 | }
|
---|
87 | #endif
|
---|
88 |
|
---|
89 | DECLEXPORT(void) crError(const char *pszFormat, ...)
|
---|
90 | {
|
---|
91 | va_list va;
|
---|
92 | #ifdef WINDOWS
|
---|
93 | DWORD dwLastErr;
|
---|
94 | #endif
|
---|
95 |
|
---|
96 | #ifdef WINDOWS
|
---|
97 | /* Log last error on windows. */
|
---|
98 | dwLastErr = GetLastError();
|
---|
99 | if (dwLastErr != 0 && RTEnvGet("CR_WINDOWS_ERRORS") != NULL)
|
---|
100 | {
|
---|
101 | LPTSTR pszWindowsMessage;
|
---|
102 |
|
---|
103 | SetLastError(0);
|
---|
104 | FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER
|
---|
105 | | FORMAT_MESSAGE_FROM_SYSTEM
|
---|
106 | | FORMAT_MESSAGE_MAX_WIDTH_MASK,
|
---|
107 | NULL, dwLastErr,
|
---|
108 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
---|
109 | (LPTSTR)&pszWindowsMessage, 0, NULL);
|
---|
110 | if (pszWindowsMessage)
|
---|
111 | {
|
---|
112 | logMessage("OpenGL, Windows error: ", "%u\n%s", dwLastErr, pszWindowsMessage);
|
---|
113 | LocalFree(pszWindowsMessage);
|
---|
114 | }
|
---|
115 | else
|
---|
116 | logMessage("OpenGL, Windows error: ", "%u", dwLastErr);
|
---|
117 | }
|
---|
118 | #endif
|
---|
119 |
|
---|
120 | /* The message. */
|
---|
121 | va_start(va, pszFormat);
|
---|
122 | logMessageV("OpenGL Error: ", pszFormat, va);
|
---|
123 | va_end(va);
|
---|
124 |
|
---|
125 | #ifdef DEBUG
|
---|
126 | /* Let's interrupt App execution only on debug builds and return
|
---|
127 | * bad status to upper level on release ones. */
|
---|
128 | # ifdef IN_GUEST
|
---|
129 | /* Trigger debugger's breakpoint handler. */
|
---|
130 | ASMBreakpoint();
|
---|
131 | # else
|
---|
132 | /* Dump core or activate the debugger in debug builds. */
|
---|
133 | AssertFailed();
|
---|
134 | # endif
|
---|
135 | #endif /* DEBUG */
|
---|
136 | }
|
---|
137 |
|
---|
138 | DECLEXPORT(void) crWarning(const char *pszFormat, ...)
|
---|
139 | {
|
---|
140 | if (RTR3InitIsInitialized())
|
---|
141 | {
|
---|
142 | va_list va;
|
---|
143 |
|
---|
144 | va_start(va, pszFormat);
|
---|
145 | logMessageV("OpenGL Warning: ", pszFormat, va);
|
---|
146 | va_end(va);
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 | DECLEXPORT(void) crInfo(const char *pszFormat, ...)
|
---|
151 | {
|
---|
152 | if (RTR3InitIsInitialized())
|
---|
153 | {
|
---|
154 | va_list va;
|
---|
155 |
|
---|
156 | va_start(va, pszFormat);
|
---|
157 | logMessageV("OpenGL Info: ", pszFormat, va);
|
---|
158 | va_end(va);
|
---|
159 | }
|
---|
160 | }
|
---|
161 |
|
---|
162 | DECLEXPORT(void) crDebug(const char *pszFormat, ...)
|
---|
163 | {
|
---|
164 | if (RTR3InitIsInitialized())
|
---|
165 | {
|
---|
166 | va_list va;
|
---|
167 |
|
---|
168 | va_start(va, pszFormat);
|
---|
169 | #if defined(DEBUG_vgalitsy) || defined(DEBUG_galitsyn)
|
---|
170 | LogRel(("OpenGL Debug: %N\n", pszFormat, &va));
|
---|
171 | #else
|
---|
172 | Log(("OpenGL Debug: %N\n", pszFormat, &va));
|
---|
173 | #endif
|
---|
174 | va_end(va);
|
---|
175 | }
|
---|
176 | }
|
---|