1 | /* $Id: error.c 57018 2015-07-20 11:05:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox crOpenGL error logging
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2014 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 <VBox/log.h>
|
---|
25 |
|
---|
26 | #ifdef RT_OS_WINDOWS
|
---|
27 | # include <windows.h>
|
---|
28 | # include "cr_environment.h"
|
---|
29 | # include "cr_error.h"
|
---|
30 | # include "VBox/VBoxGuestLib.h"
|
---|
31 | # include "iprt/initterm.h"
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <signal.h>
|
---|
35 | #include <stdlib.h>
|
---|
36 |
|
---|
37 | static void logMessageV(const char *pszPrefix, const char *pszFormat, va_list va)
|
---|
38 | {
|
---|
39 | va_list vaCopy;
|
---|
40 | if (RTR3InitIsInitialized())
|
---|
41 | {
|
---|
42 | va_copy(vaCopy, va);
|
---|
43 | LogRel(("%s%N\n", pszPrefix, pszFormat, &vaCopy));
|
---|
44 | va_end(vaCopy);
|
---|
45 | }
|
---|
46 |
|
---|
47 | #ifdef IN_GUEST /** @todo Could be subject to pre-iprt-init issues, but hopefully not... */
|
---|
48 | va_copy(vaCopy, va);
|
---|
49 | RTStrmPrintf(g_pStdErr, "%s%N\n", pszPrefix, pszFormat, &vaCopy);
|
---|
50 | va_end(vaCopy);
|
---|
51 | #endif
|
---|
52 | }
|
---|
53 |
|
---|
54 | static void logMessage(const char *pszPrefix, const char *pszFormat, ...)
|
---|
55 | {
|
---|
56 | va_list va;
|
---|
57 |
|
---|
58 | va_start(va, pszFormat);
|
---|
59 | logMessageV(pszPrefix, pszFormat, va);
|
---|
60 | va_end(va);
|
---|
61 | }
|
---|
62 |
|
---|
63 | DECLEXPORT(void) crError(const char *pszFormat, ...)
|
---|
64 | {
|
---|
65 | va_list va;
|
---|
66 | #ifdef WINDOWS
|
---|
67 | DWORD dwLastErr;
|
---|
68 | #endif
|
---|
69 |
|
---|
70 | #ifdef WINDOWS
|
---|
71 | /* Log last error on windows. */
|
---|
72 | dwLastErr = GetLastError();
|
---|
73 | if (dwLastErr != 0 && crGetenv("CR_WINDOWS_ERRORS") != NULL)
|
---|
74 | {
|
---|
75 | LPTSTR pszWindowsMessage;
|
---|
76 |
|
---|
77 | SetLastError(0);
|
---|
78 | FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER
|
---|
79 | | FORMAT_MESSAGE_FROM_SYSTEM
|
---|
80 | | FORMAT_MESSAGE_MAX_WIDTH_MASK,
|
---|
81 | NULL, dwLastErr,
|
---|
82 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
---|
83 | (LPTSTR)&pszWindowsMessage, 0, NULL);
|
---|
84 | if (pszWindowsMessage)
|
---|
85 | {
|
---|
86 | logMessage("OpenGL, Windows error: ", "%u\n%s", dwLastErr, pszWindowsMessage);
|
---|
87 | LocalFree(pszWindowsMessage);
|
---|
88 | }
|
---|
89 | else
|
---|
90 | logMessage("OpenGL, Windows error: ", "%u", dwLastErr);
|
---|
91 | }
|
---|
92 | #endif
|
---|
93 |
|
---|
94 | /* The message. */
|
---|
95 | va_start(va, pszFormat);
|
---|
96 | logMessageV("OpenGL Error: ", pszFormat, va);
|
---|
97 | va_end(va);
|
---|
98 |
|
---|
99 | #ifdef DEBUG
|
---|
100 | /* Let's interrupt App execution only on debug builds and return
|
---|
101 | * bad status to upper level on release ones. */
|
---|
102 | # ifdef IN_GUEST
|
---|
103 | /* Trigger debugger's breakpoint handler. */
|
---|
104 | ASMBreakpoint();
|
---|
105 | # else
|
---|
106 | /* Dump core or activate the debugger in debug builds. */
|
---|
107 | AssertFailed();
|
---|
108 | # endif
|
---|
109 | #endif /* DEBUG */
|
---|
110 | }
|
---|
111 |
|
---|
112 | DECLEXPORT(void) crWarning(const char *pszFormat, ...)
|
---|
113 | {
|
---|
114 | if (RTR3InitIsInitialized())
|
---|
115 | {
|
---|
116 | va_list va;
|
---|
117 |
|
---|
118 | va_start(va, pszFormat);
|
---|
119 | logMessageV("OpenGL Warning: ", pszFormat, va);
|
---|
120 | va_end(va);
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | DECLEXPORT(void) crInfo(const char *pszFormat, ...)
|
---|
125 | {
|
---|
126 | if (RTR3InitIsInitialized())
|
---|
127 | {
|
---|
128 | va_list va;
|
---|
129 |
|
---|
130 | va_start(va, pszFormat);
|
---|
131 | logMessageV("OpenGL Info: ", pszFormat, va);
|
---|
132 | va_end(va);
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | DECLEXPORT(void) crDebug(const char *pszFormat, ...)
|
---|
137 | {
|
---|
138 | if (RTR3InitIsInitialized())
|
---|
139 | {
|
---|
140 | va_list va;
|
---|
141 |
|
---|
142 | va_start(va, pszFormat);
|
---|
143 | #if defined(DEBUG_vgalitsy) || defined(DEBUG_galitsyn)
|
---|
144 | LogRel(("OpenGL Debug: %N\n", pszFormat, &va));
|
---|
145 | #else
|
---|
146 | Log(("OpenGL Debug: %N\n", pszFormat, &va));
|
---|
147 | #endif
|
---|
148 | va_end(va);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | #if defined(RT_OS_WINDOWS)
|
---|
153 | BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
|
---|
154 | {
|
---|
155 | (void) lpvReserved;
|
---|
156 |
|
---|
157 | switch (fdwReason)
|
---|
158 | {
|
---|
159 | case DLL_PROCESS_ATTACH:
|
---|
160 | {
|
---|
161 | int rc;
|
---|
162 | rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE); CRASSERT(rc==0);
|
---|
163 | # ifdef IN_GUEST
|
---|
164 | rc = VbglR3Init();
|
---|
165 | # endif
|
---|
166 | LogRel(("crUtil DLL loaded.\n"));
|
---|
167 | # if defined(DEBUG_misha)
|
---|
168 | char aName[MAX_PATH];
|
---|
169 | GetModuleFileNameA(hDLLInst, aName, RT_ELEMENTS(aName));
|
---|
170 | crDbgCmdSymLoadPrint(aName, hDLLInst);
|
---|
171 | # endif
|
---|
172 | break;
|
---|
173 | }
|
---|
174 |
|
---|
175 | case DLL_PROCESS_DETACH:
|
---|
176 | {
|
---|
177 | LogRel(("crUtil DLL unloaded."));
|
---|
178 | # ifdef IN_GUEST
|
---|
179 | VbglR3Term();
|
---|
180 | # endif
|
---|
181 | }
|
---|
182 |
|
---|
183 | default:
|
---|
184 | break;
|
---|
185 | }
|
---|
186 |
|
---|
187 | return TRUE;
|
---|
188 | }
|
---|
189 | #endif
|
---|