VirtualBox

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

Last change on this file since 55573 was 55573, checked in by vboxsync, 10 years ago

3D: inaddition to r99944: do not exit guest/host process on crError, but trigger debugger to catch a breakpoint instead.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/* $Id: error.c 55573 2015-04-30 18:06:07Z 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
37static 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
54static 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
63DECLEXPORT(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 IN_GUEST
100 /* Give things a chance to close down. */
101 ASMBreakpoint();
102#else
103 /* Dump core or activate the debugger in debug builds. */
104 AssertFailed();
105#endif
106}
107
108DECLEXPORT(void) crWarning(const char *pszFormat, ...)
109{
110 if (RTR3InitIsInitialized())
111 {
112 va_list va;
113
114 va_start(va, pszFormat);
115 logMessageV("OpenGL Warning: ", pszFormat, va);
116 va_end(va);
117 }
118}
119
120DECLEXPORT(void) crInfo(const char *pszFormat, ...)
121{
122 if (RTR3InitIsInitialized())
123 {
124 va_list va;
125
126 va_start(va, pszFormat);
127 logMessageV("OpenGL Info: ", pszFormat, va);
128 va_end(va);
129 }
130}
131
132DECLEXPORT(void) crDebug(const char *pszFormat, ...)
133{
134 if (RTR3InitIsInitialized())
135 {
136 va_list va;
137
138 va_start(va, pszFormat);
139#if defined(DEBUG_vgalitsy) || defined(DEBUG_galitsyn)
140 LogRel(("OpenGL Debug: %N\n", pszFormat, &va));
141#else
142 Log(("OpenGL Debug: %N\n", pszFormat, &va));
143#endif
144 va_end(va);
145 }
146}
147
148#if defined(RT_OS_WINDOWS)
149BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
150{
151 (void) lpvReserved;
152
153 switch (fdwReason)
154 {
155 case DLL_PROCESS_ATTACH:
156 {
157 int rc;
158 rc = RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE); CRASSERT(rc);
159 rc = VbglR3Init();
160 LogRel(("crUtill DLL loaded.\n"));
161# if defined(DEBUG_misha)
162 char aName[MAX_PATH];
163 GetModuleFileNameA(hDLLInst, aName, RT_ELEMENTS(aName));
164 crDbgCmdSymLoadPrint(aName, hDLLInst);
165# endif
166 break;
167 }
168
169 case DLL_PROCESS_DETACH:
170 {
171 LogRel(("crUtill DLL unloaded."));
172 VbglR3Term();
173 }
174
175 default:
176 break;
177 }
178
179 return TRUE;
180}
181#endif
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