Game Accessibility Library logo SourceForge.net Logo
Game Accessibility Suite: CAT/CATDebug.cpp Source File

CATDebug.cpp

Go to the documentation of this file.
00001 /// \file CATDebug.cpp
00002 /// \brief Debugging utility functions
00003 /// \ingroup CAT
00004 ///
00005 /// Copyright (c) 2003-2007 by Michael Ellison.
00006 /// See COPYING.txt for the \ref gaslicense License (MIT License).
00007 ///
00008 // $Author: mikeellison $
00009 // $Date: 2008-01-19 19:19:35 -0600 (Sat, 19 Jan 2008) $
00010 // $Revision:   $
00011 // $NoKeywords: $
00012 #include "CATDebug.h"
00013 
00014 #include <stdio.h>
00015 #include <time.h>
00016 
00017 // Right now, these are win32 only.
00018 #ifdef CAT_CONFIG_WIN32
00019     
00020     // _CATAssert() is the root implementation of the CATASSERT() macro.
00021     // Do not use this directly - instead use CATASSERT().
00022     void _CATAssert(   const char*   expression,
00023                        const char*   file,
00024                        CATUInt32     lineNumber,
00025                        const char*   msg)
00026     {
00027        DWORD lastError = ::GetLastError();
00028 
00029        _CATTrace(msg,file,lineNumber);
00030 
00031        char* msgString = new char[_MAX_PATH + 100 + strlen(expression) + strlen(msg)];
00032        sprintf(msgString,"%s(%d) :%s\nExpression: %s",file,lineNumber,msg,expression);
00033        DWORD result = ::MessageBoxA(NULL,msgString,"Assertion Failed",MB_ABORTRETRYIGNORE);
00034        delete [] msgString;
00035 
00036        switch (result)
00037        {
00038           case IDRETRY:
00039              // If you hit here, an assertion occurred.  Check the tracelogs for the reason.
00040              // You should be able to trace back to the location of the assertion by stepping
00041              // out of this function in your debugger.
00042              _asm {int 3};
00043              break;
00044           case IDIGNORE:
00045              // Ignoring assertion and continuing.
00046              break;
00047           
00048           default:
00049           case IDABORT:
00050              // Halt program.
00051              _exit(-1);
00052              break;
00053        }
00054        
00055        SetLastError(lastError);
00056     }
00057 
00058 
00059     // _CATTrace() is the root implementation of the CATTrace() macro.
00060     // Do not use this directly - instead use CATTrace()
00061     void _CATTrace(    const char*     msg, 
00062                        const char*     file, 
00063                        CATUInt32       lineNumber)
00064     {
00065        DWORD lastError = ::GetLastError();      
00066        
00067        char* msgString = new char[_MAX_PATH + 100 + strlen(msg)];
00068        sprintf(msgString,"%s(%d) :%s\n",file,lineNumber,msg);
00069 
00070        ::OutputDebugStringA(msgString);
00071        
00072        delete [] msgString;
00073        SetLastError(lastError);
00074     }
00075 #else
00076 
00077 #endif

Generated on Mon Feb 11 04:09:42 2008 for Game Accessibility Suite by doxygen 1.5.4