📄 hxassert.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: hxassert.cpp,v 1.14.2.6 2004/07/09 01:46:18 hubbe Exp $ * * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. * * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks. You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL. Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. * * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. * * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. * * Technology Compatibility Kit Test Suite(s) Location: * http://www.helixcommunity.org/content/tck * * Contributor(s): * * ***** END LICENSE BLOCK ***** *//////////////////////////////////////////////////////////////////////////////// HXASSERT.CPP//// Debugging support implementation.//// HX_ASSERT() - asserts an expression is TRUE. Compiles to no-ops in// retail builds. Provides message box or other UI when // expression fails.//// HX_ASSERT_VALID_PTR() - asserts that a pointer is valid. Performs more// rigid verification specifically appropriate for pointers.//// HX_VERIFY() - verifies an expression is TRUE. Expression or code DOES NOT // compile away in retail builds, but UI of failure is removed.// In debug builds provides message box or other UI when // expression fails.//// HX_TRACE() - Similar to DEBUGPRINTF() but no buffer is required. // Compiles to no-ops in retail builds.//#include "hxtypes.h"#include "hlxclib/stdio.h"#include "hlxclib/stdlib.h"#if defined(_WIN32) || defined(_WINDOWS)#include "hlxclib/windows.h"#if !defined(_WIN32) && !defined(WIN32)#include <shellapi.h>#include "string.h"#endif#endif#include "hxassert.h"#include "hxstrutl.h"#include "debugout.h"#include "hxtypes.h"#include "hxresult.h"#if defined (DEBUG) || defined (_DEBUG)#ifdef _MACINTOSH#include <stdarg.h>#include <string.h>#include "platform/mac/hxcrt_assert.h"#define IDIGNORE 2#define IDRETRY 1#endif#ifdef _UNIX#include <stdarg.h>#define IDIGNORE 0#define IDRETRY 1#include <errno.h>#include <string.h>#include <sys/types.h>#include <sys/wait.h>#endif#if defined(_SYMBIAN)#include "avkon.rsg"#include <aknglobalmsgquery.h> #endif#if defined(_SYMBIAN) || defined(_OPENWAVE)#include "hlxclib/stdarg.h"#define IDIGNORE 0#define IDRETRY 1#endif#if defined(_WIN32)#include <tchar.h>#endif#include "hxheap.h"#ifdef DEBUG#undef HX_THIS_FILE static const char HX_THIS_FILE[] = __FILE__;#endif///////////////////////////////////////////////////////////////////////////////// HXOutputDebugString: // Helper function used by DEBUGOUTSTR(). This is better than // OutputDebugString, because it will check to see if output// tracing is turned off in the registry. This prevents the massive// slew of output messages.//void STDMETHODCALLTYPE HXOutputDebugString(const char* pString){ if (HXWantTraceMessages()) {#if _MACINTOSH Str255 pstr = {0x00}; char *p = (char*)pString; while (*p && pstr[0] < 253) // interrupt safe c2pstr, and we don't mess with pString pstr[++pstr[0]] = *p++; pstr[++pstr[0]] = ';'; // add go command so we don't stay in MacsBug pstr[++pstr[0]] = 'g'; DebugStr(pstr);#elif defined( DEBUG ) && (defined( _WIN32 ) || defined( _WINDOWS )) // This is the Windows/Win 95 version OutputDebugString(OS_STRING(pString));#elif defined( DEBUG) && defined(_LINUX) fprintf( stderr, "%s", pString);#else // Any other platforms.... Undefine it to be safe.#endif } // end if};///////////////////////////////////////////////////////////////////////////////// HXDebugOptionEnabled: // Determine if the given debug option is enabled.// A lookup is done to the registry key, and if it's present// and set to '1', TRUE is returned otherwise FALSE//#ifdef _WIN16BOOL far _cdecl HXDebugOptionEnabled(const char* szOption)#elseBOOL STDMETHODCALLTYPE HXDebugOptionEnabled(const char* szOption)#endif{#if defined( DEBUG ) && (defined( _WIN32 ) || defined( _WINDOWS )) HKEY RootKey = HKEY_CLASSES_ROOT; TCHAR szBuffer[10] = TEXT(""); /* Flawfinder: ignore */ HKEY hKey; BOOL bEnabled = FALSE; HX_RESULT hRes; DWORD bufSize = sizeof(szBuffer); if( RegOpenKey(RootKey, szOption, &hKey) == ERROR_SUCCESS ) { hRes = RegQueryValue(hKey, "", (char*)szBuffer, (long *)&bufSize); if (hRes == ERROR_SUCCESS && bufSize != 0) { if (strcmp(szBuffer,"1") == 0) { bEnabled = TRUE; } } RegCloseKey(hKey); } return bEnabled;#else return FALSE; // Any other platforms.... Undefine it to be safe.#endif}#if defined(_SYMBIAN)int QueryAssertActionL(const char* pAssertText){ // Allocate assertion text TPtrC8 ptr8((const TUint8*)pAssertText); HBufC* pText = HBufC::NewLC(ptr8.Length()); pText->Des().Copy(ptr8); // Show message TRequestStatus status = KRequestPending; CAknGlobalMsgQuery * pDlg = CAknGlobalMsgQuery::NewL(); CleanupStack::PushL(pDlg); pDlg->ShowMsgQueryL(status, *pText, R_AVKON_SOFTKEYS_OK_DETAILS, _L("Assert failed!"), KNullDesC, 0, -1, CAknQueryDialog::EErrorTone ); User::WaitForRequest(status); CleanupStack::PopAndDestroy(2); //pText, pDlg // Go to debugger if user clicked 'details', otherwise ignore int nCode = (EAknSoftkeyDetails == status.Int() ? IDRETRY : IDIGNORE); return nCode;}#endif///////////////////////////////////////////////////////////////////////////////// HXWantTraceMessages: // Helper function used to determine if the system has asked for trace // messages.//BOOL STDMETHODCALLTYPE HXWantTraceMessages(){#if __MWERKS__ return TRUE;#elif defined( DEBUG ) && (defined( _WIN32 ) || defined( _WINDOWS )) HKEY RootKey = HKEY_CLASSES_ROOT; TCHAR szBuffer[10] = TEXT(""); /* Flawfinder: ignore */ HKEY hKey; BOOL bWantTrace = FALSE; HX_RESULT hRes; DWORD bufSize = sizeof(szBuffer); if( RegOpenKey(RootKey, "HXDebug", &hKey) == ERROR_SUCCESS ) { hRes = RegQueryValue(hKey, "", (char*)szBuffer, (long *)&bufSize); if (hRes == ERROR_SUCCESS && bufSize != 0) { if (strcmp(szBuffer,"1") == 0) { bWantTrace = TRUE; } } RegCloseKey(hKey); } return bWantTrace;#elif defined(_UNIX) && defined( DEBUG) const char* debugOutputOpts = getenv("HX_DEBUG"); if( debugOutputOpts && strlen(debugOutputOpts) != 0) { return TRUE; } return FALSE;#else return FALSE; // Any other platforms.... Undefine it to be safe.#endif}#if !defined(HELIX_CONFIG_NOSTATICS)int g_trace_log_enabled = 0;#endif///////////////////////////////////////////////////////////////////////////////// HXTrace: Helper function used by HX_TRACE()//void STDMETHODVCALLTYPE HXTrace(const char* pszFormat, ...){#if !defined(HELIX_CONFIG_NOSTATICS) if(!g_trace_log_enabled) return; static char z_szDebugBuffer[MAX_TRACE_OUTPUT]; /* Flawfinder: ignore */ va_list vaMarker; va_start( vaMarker, pszFormat ); vsnprintf( z_szDebugBuffer, sizeof(z_szDebugBuffer), pszFormat, vaMarker ); va_end( vaMarker ); DEBUGOUTSTR( z_szDebugBuffer );#endif};///////////////////////////////////////////////////////////////////////////////// HXAssertFailedLine: Helper function used by HX_ASSERT()//#ifdef _WIN16// see comment in hxassert.hBOOL far _cdecl HXAssertFailedLine(const char* pszExpression, const char* pszFileName, int nLine)#elseBOOL STDMETHODCALLTYPE HXAssertFailedLine(const char* pszExpression, const char* pszFileName, int nLine)#endif{#if !defined(HELIX_CONFIG_NOSTATICS) static char z_szAssertMessage[MAX_TRACE_OUTPUT]; /* Flawfinder: ignore */ static BOOL z_nMultiAssertCount = 0;#else char z_szAssertMessage[MAX_TRACE_OUTPUT]; /* Flawfinder: ignore */ BOOL z_nMultiAssertCount = 0;#endif // format message into buffer SafeSprintf(z_szAssertMessage, MAX_TRACE_OUTPUT, "(%s)... File %s, Line %d", pszExpression, pszFileName, nLine); // assume the debugger or auxiliary port // output into MacsBug looks better if it's done in one string, // since MacsBug always breaks the line after each output HX_TRACE("Assertion Failed: %s\n", z_szAssertMessage);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -