error.c revision 72b97769a3c9b22b4fb60fc0f30a1a82f5bbb6f5
/* Copyright (c) 2001, Stanford University
* All rights reserved
*
* See the file LICENSE.txt for information on redistributing this software.
*/
#include "cr_environment.h"
#include "cr_error.h"
#include "cr_string.h"
#include "cr_net.h"
#include "cr_process.h"
#ifdef WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <io.h>
#include <fcntl.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <signal.h>
#ifndef IN_GUEST
#define LOG_GROUP LOG_GROUP_SHARED_CROPENGL
#endif
#if !defined(IN_GUEST) || defined(CR_DEBUG_BACKDOOR_ENABLE)
#endif
#if defined(WINDOWS)
# define CR_DEBUG_CONSOLE_ENABLE
# include "Shlwapi.h"
#endif
# ifndef CR_DEBUG_BACKDOOR_ENABLE
# error "CR_DEBUG_BACKDOOR_ENABLE is expected!"
# endif
#else
# ifdef CR_DEBUG_BACKDOOR_ENABLE
# error "CR_DEBUG_BACKDOOR_ENABLE is NOT expected!"
# endif
#endif
#ifdef CR_DEBUG_BACKDOOR_ENABLE
# include <VBoxDispMpLogger.h>
#endif
static char my_hostname[256];
#ifdef WINDOWS
#else
static int my_pid = 0;
#endif
static int canada = 0;
static int swedish_chef = 0;
static int australia = 0;
static int warnings_enabled = 1;
#ifdef DEBUG_misha
//int g_VBoxFbgFBreakDdi = 0;
#define DebugBreak() Assert(0)
#endif
void __getHostInfo( void )
{
char *temp;
/* on windows guests we're typically get called in a context of VBoxOGL!DllMain ( which calls VBoxOGLcrutil!crNetInit ),
* which may lead to deadlocks..
* Avoid it as it is needed for debugging purposes only */
#if !defined(IN_GUEST) || !defined(RT_OS_WINDOWS)
#endif
{
}
if (temp)
{
*temp = '\0';
}
}
static void __crCheckCanada(void)
{
static int first = 1;
if (first)
{
if (env)
canada = 1;
first = 0;
}
}
static void __crCheckSwedishChef(void)
{
static int first = 1;
if (first)
{
if (env)
swedish_chef = 1;
first = 0;
}
}
static void __crCheckAustralia(void)
{
static int first = 1;
if (first)
{
australia = 1;
first = 0;
}
}
{
);
}
#ifdef WINDOWS
static void crRedirectIOToConsole()
{
int hConHandle;
AllocConsole();
}
#endif
{
static char txt[8092];
int offset;
#ifdef WINDOWS
#endif
if (!my_hostname[0])
#ifdef WINDOWS
{
SetLastError(0);
if ( temp )
{
}
{
*temp = '\0';
temp--;
}
offset = sprintf( txt, "\t-----------------------\n\tWindows ERROR: %s\n\t----------------------\nCR Error(%s:%d): ", buf, my_hostname, my_pid );
}
else
{
}
#else
#endif
#if defined(IN_GUEST)
#else
#endif
#ifdef WINDOWS
{
}
else
{
#endif
#ifdef WINDOWS
}
#endif
{
DebugBreak();
}
#endif
#ifdef IN_GUEST
/* Give chance for things to close down */
exit(1);
#endif
}
void crEnableWarnings(int onOff)
{
}
#ifdef DEBUG_misha
#endif
{
if (warnings_enabled) {
static char txt[8092];
int offset;
if (!my_hostname[0])
#if defined(IN_GUEST)
#else
#endif
DebugBreak();
#endif
}
}
{
static char txt[8092];
int offset;
if (!my_hostname[0])
#if defined(IN_GUEST)
#else
#endif
}
#ifdef CR_DEBUG_BACKDOOR_ENABLE
{
}
{
}
#endif
#if defined(WINDOWS) /* && (!defined(DEBUG_misha) || !defined(IN_GUEST) ) */
# define CR_DEBUG_DBGPRINT_ENABLE
#endif
#ifdef CR_DEBUG_DBGPRINT_ENABLE
static void crDebugDbgPrint(const char *str)
{
OutputDebugString("\n");
}
static void crDebugDbgPrintF(const char * szString, ...)
{
char szBuffer[4096] = {0};
}
{
}
DECLEXPORT(void) crDbgCmdPrint(const char *description1, const char *description2, const char *cmd, ...)
{
char aTxt[8092];
char aCmd[8092];
}
{
static bool fEnable = false;
static bool fInitialized = false;
const char * pszName;
static const char * pszModulePath = NULL;
if (!fInitialized)
{
#ifndef DEBUG_misha
if (crGetenv( "CR_DEBUG_MODULE_ENABLE" ))
#endif
{
fEnable = true;
}
fInitialized = true;
}
if (!fEnable)
return;
if (!pszModulePath)
if (!pszModulePath)
pszModulePath = "c:\\Users\\senmk\\Downloads\\Data\\Data";
crDbgCmdPrint("load modules for ", pszName, ".reload /i /f %s\\%s=%#p", pszModulePath, pszName, pvAddress);
}
#endif
{
static char txt[8092];
int offset;
#ifdef WINDOWS
#endif
static int first_time = 1;
static int silent = 0;
#ifdef CR_DEBUG_BACKDOOR_ENABLE
typedef FNCRGEDUGBACKDOOR *PFNCRGEDUGBACKDOOR;
#endif
#ifdef CR_DEBUG_DBGPRINT_ENABLE
static int dbgPrintEnable = 0;
#endif
if (first_time)
{
char str[2048];
#ifdef CR_DEBUG_CONSOLE_ENABLE
int logToConsole = 0;
#endif
#ifdef CR_DEBUG_BACKDOOR_ENABLE
if (crGetenv( "CR_DEBUG_BACKDOOR" ))
{
int rc = VBoxDispMpLoggerInit();
if (RT_SUCCESS(rc))
else
}
#endif
#ifdef CR_DEBUG_DBGPRINT_ENABLE
if (crGetenv( "CR_DEBUG_DBGPRINT" ))
{
dbgPrintEnable = 1;
}
#endif
if (!fname && fnamePrefix)
{
char pname[1024];
{
#ifdef RT_OS_WINDOWS
#else
#endif
);
}
}
first_time = 0;
if (fname)
{
char debugFile[2048], *p;
if (p) {
/* replace %p with process number */
unsigned long n = (unsigned long) crGetPID();
sprintf(p, "%lu", n);
}
if (!output)
{
}
}
else
{
#ifdef CR_DEBUG_CONSOLE_ENABLE
if (crGetenv( "CR_DEBUG_CONSOLE" ))
{
logToConsole = 1;
}
#endif
}
#if !defined(DEBUG)/* || defined(DEBUG_misha)*/
/* Release mode: only emit crDebug messages if CR_DEBUG
* or CR_DEBUG_FILE is set.
*/
#ifdef CR_DEBUG_CONSOLE_ENABLE
&& !logToConsole
#endif
#ifdef CR_DEBUG_BACKDOOR_ENABLE
&& !pfnLogBackdoor
#endif
#ifdef CR_DEBUG_DBGPRINT_ENABLE
&& !dbgPrintEnable
#endif
)
silent = 1;
#endif
}
if (silent)
return;
if (!my_hostname[0])
#ifdef WINDOWS
{
SetLastError(0);
if ( temp )
{
}
{
*temp = '\0';
temp--;
}
offset = sprintf( txt, "\t-----------------------\n\tWindows ERROR: %s\n\t-----------------\nCR Debug(%s:%d): ", buf, my_hostname, my_pid );
}
else
{
}
#else
#endif
#ifdef CR_DEBUG_BACKDOOR_ENABLE
if (pfnLogBackdoor)
{
}
#endif
#ifdef CR_DEBUG_DBGPRINT_ENABLE
if (dbgPrintEnable)
{
}
#endif
#if defined(IN_GUEST)
#else
if (!output
#ifndef DEBUG_misha
#endif
)
{
}
else
{
}
#endif
}
#if defined(DEBUG_misha) && defined(RT_OS_WINDOWS)
{
(void) lpvReserved;
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
{
break;
}
default:
break;
}
return TRUE;
}
#endif