1 | /* $Id: error.c 78190 2019-04-18 00:07:07Z 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 | # include "cr_error.h"
|
---|
34 | # include "VBox/VBoxGuestLib.h"
|
---|
35 | # include "iprt/initterm.h"
|
---|
36 | #else
|
---|
37 | # include "cr_error.h"
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | #include <signal.h>
|
---|
41 | #include <stdlib.h>
|
---|
42 |
|
---|
43 |
|
---|
44 | /*
|
---|
45 | * Stuff that needs to be dragged into the link because other DLLs needs it.
|
---|
46 | * See also VBoxDeps.cpp in iprt and xpcom.
|
---|
47 | */
|
---|
48 | #ifdef _MSC_VER
|
---|
49 | # pragma warning(push)
|
---|
50 | # pragma warning(disable:4232) /* nonstandard extension used: 'g_VBoxRTDeps' : address of dllimport 'RTBldCfgRevision' is not static, identiy not guaranteed */
|
---|
51 | #endif
|
---|
52 | PFNRT g_VBoxRTDeps[] =
|
---|
53 | {
|
---|
54 | (PFNRT)RTAssertShouldPanic,
|
---|
55 | (PFNRT)ASMAtomicReadU64,
|
---|
56 | (PFNRT)ASMAtomicCmpXchgU64,
|
---|
57 | (PFNRT)ASMBitFirstSet,
|
---|
58 | (PFNRT)RTBldCfgRevision,
|
---|
59 | };
|
---|
60 | #ifdef _MSC_VER
|
---|
61 | # pragma warning(pop)
|
---|
62 | #endif
|
---|
63 |
|
---|
64 |
|
---|
65 | static void logMessageV(const char *pszPrefix, const char *pszFormat, va_list va)
|
---|
66 | {
|
---|
67 | va_list vaCopy;
|
---|
68 | if (RTR3InitIsInitialized())
|
---|
69 | {
|
---|
70 | va_copy(vaCopy, va);
|
---|
71 | LogRel(("%s%N\n", pszPrefix, pszFormat, &vaCopy));
|
---|
72 | va_end(vaCopy);
|
---|
73 | }
|
---|
74 |
|
---|
75 | #ifdef IN_GUEST /** @todo Could be subject to pre-iprt-init issues, but hopefully not... */
|
---|
76 | va_copy(vaCopy, va);
|
---|
77 | RTStrmPrintf(g_pStdErr, "%s%N\n", pszPrefix, pszFormat, &vaCopy);
|
---|
78 | va_end(vaCopy);
|
---|
79 | #endif
|
---|
80 | }
|
---|
81 |
|
---|
82 | #ifdef WINDOWS
|
---|
83 | static void logMessage(const char *pszPrefix, const char *pszFormat, ...)
|
---|
84 | {
|
---|
85 | va_list va;
|
---|
86 |
|
---|
87 | va_start(va, pszFormat);
|
---|
88 | logMessageV(pszPrefix, pszFormat, va);
|
---|
89 | va_end(va);
|
---|
90 | }
|
---|
91 | #endif
|
---|
92 |
|
---|
93 | DECLEXPORT(void) crError(const char *pszFormat, ...)
|
---|
94 | {
|
---|
95 | va_list va;
|
---|
96 | #ifdef WINDOWS
|
---|
97 | DWORD dwLastErr;
|
---|
98 | #endif
|
---|
99 |
|
---|
100 | #ifdef WINDOWS
|
---|
101 | /* Log last error on windows. */
|
---|
102 | dwLastErr = GetLastError();
|
---|
103 | if (dwLastErr != 0 && RTEnvGet("CR_WINDOWS_ERRORS") != NULL)
|
---|
104 | {
|
---|
105 | LPTSTR pszWindowsMessage;
|
---|
106 |
|
---|
107 | SetLastError(0);
|
---|
108 | FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER
|
---|
109 | | FORMAT_MESSAGE_FROM_SYSTEM
|
---|
110 | | FORMAT_MESSAGE_MAX_WIDTH_MASK,
|
---|
111 | NULL, dwLastErr,
|
---|
112 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
---|
113 | (LPTSTR)&pszWindowsMessage, 0, NULL);
|
---|
114 | if (pszWindowsMessage)
|
---|
115 | {
|
---|
116 | logMessage("OpenGL, Windows error: ", "%u\n%s", dwLastErr, pszWindowsMessage);
|
---|
117 | LocalFree(pszWindowsMessage);
|
---|
118 | }
|
---|
119 | else
|
---|
120 | logMessage("OpenGL, Windows error: ", "%u", dwLastErr);
|
---|
121 | }
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | /* The message. */
|
---|
125 | va_start(va, pszFormat);
|
---|
126 | logMessageV("OpenGL Error: ", pszFormat, va);
|
---|
127 | va_end(va);
|
---|
128 |
|
---|
129 | #ifdef DEBUG
|
---|
130 | /* Let's interrupt App execution only on debug builds and return
|
---|
131 | * bad status to upper level on release ones. */
|
---|
132 | # ifdef IN_GUEST
|
---|
133 | /* Trigger debugger's breakpoint handler. */
|
---|
134 | ASMBreakpoint();
|
---|
135 | # else
|
---|
136 | /* Dump core or activate the debugger in debug builds. */
|
---|
137 | AssertFailed();
|
---|
138 | # endif
|
---|
139 | #endif /* DEBUG */
|
---|
140 | }
|
---|
141 |
|
---|
142 | DECLEXPORT(void) crWarning(const char *pszFormat, ...)
|
---|
143 | {
|
---|
144 | if (RTR3InitIsInitialized())
|
---|
145 | {
|
---|
146 | va_list va;
|
---|
147 |
|
---|
148 | va_start(va, pszFormat);
|
---|
149 | logMessageV("OpenGL Warning: ", pszFormat, va);
|
---|
150 | va_end(va);
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | DECLEXPORT(void) crInfo(const char *pszFormat, ...)
|
---|
155 | {
|
---|
156 | if (RTR3InitIsInitialized())
|
---|
157 | {
|
---|
158 | va_list va;
|
---|
159 |
|
---|
160 | va_start(va, pszFormat);
|
---|
161 | logMessageV("OpenGL Info: ", pszFormat, va);
|
---|
162 | va_end(va);
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | DECLEXPORT(void) crDebug(const char *pszFormat, ...)
|
---|
167 | {
|
---|
168 | if (RTR3InitIsInitialized())
|
---|
169 | {
|
---|
170 | va_list va;
|
---|
171 |
|
---|
172 | va_start(va, pszFormat);
|
---|
173 | #if defined(DEBUG_vgalitsy) || defined(DEBUG_galitsyn)
|
---|
174 | LogRel(("OpenGL Debug: %N\n", pszFormat, &va));
|
---|
175 | #else
|
---|
176 | Log(("OpenGL Debug: %N\n", pszFormat, &va));
|
---|
177 | #endif
|
---|
178 | va_end(va);
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | #if defined(RT_OS_WINDOWS)
|
---|
183 | BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
|
---|
184 | {
|
---|
185 | (void) lpvReserved; (void) hDLLInst;
|
---|
186 |
|
---|
187 | switch (fdwReason)
|
---|
188 | {
|
---|
189 | case DLL_PROCESS_ATTACH:
|
---|
190 | {
|
---|
191 | int rc;
|
---|
192 | rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE); CRASSERT(rc==0);
|
---|
193 | # ifdef IN_GUEST
|
---|
194 | rc = VbglR3Init();
|
---|
195 | # endif
|
---|
196 | LogRel(("crUtil DLL loaded.\n"));
|
---|
197 | # if defined(DEBUG_misha)
|
---|
198 | char aName[MAX_PATH];
|
---|
199 | GetModuleFileNameA(hDLLInst, aName, RT_ELEMENTS(aName));
|
---|
200 | crDbgCmdSymLoadPrint(aName, hDLLInst);
|
---|
201 | # endif
|
---|
202 | break;
|
---|
203 | }
|
---|
204 |
|
---|
205 | case DLL_PROCESS_DETACH:
|
---|
206 | {
|
---|
207 | LogRel(("crUtil DLL unloaded."));
|
---|
208 | # ifdef IN_GUEST
|
---|
209 | VbglR3Term();
|
---|
210 | # endif
|
---|
211 | }
|
---|
212 |
|
---|
213 | default:
|
---|
214 | break;
|
---|
215 | }
|
---|
216 |
|
---|
217 | return TRUE;
|
---|
218 | }
|
---|
219 | #endif
|
---|
220 |
|
---|