VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/util/error.c@ 62814

Last change on this file since 62814 was 62814, checked in by vboxsync, 9 years ago

GuestHost/OpenGL: warnings

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