assert.cpp revision a7aa94e0115a73841f34ebbfa00f63fa1904e51f
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * IPRT - Assertions, common code.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * Copyright (C) 2006-2009 Sun Microsystems, Inc.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * available from http://www.virtualbox.org. This file is free software;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * you can redistribute it and/or modify it under the terms of the GNU
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * General Public License (GPL) as published by the Free Software
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * The contents of this file may alternatively be used under the terms
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * of the Common Development and Distribution License Version 1.0
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * VirtualBox OSE distribution, in which case the provisions of the
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * CDDL are applicable instead of those of the GPL.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * You may elect to license modified versions of this file under the
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * terms and conditions of either the GPL or the CDDL or both.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * additional information or have any questions.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/*******************************************************************************
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* Header Files *
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*******************************************************************************/
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/*******************************************************************************
f78b12e570284aa8291f4ca1add24937fd107403vboxsync* Global Variables *
f78b12e570284aa8291f4ca1add24937fd107403vboxsync*******************************************************************************/
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/** The last assert message, 1st part. */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/** The last assert message, 2nd part. */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/** The last assert message, expression. */
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncRTDATADECL(const char * volatile) g_pszRTAssertExpr;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/** The last assert message, function name. */
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncRTDATADECL(const char * volatile) g_pszRTAssertFunction;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/** The last assert message, file name. */
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncRTDATADECL(const char * volatile) g_pszRTAssertFile;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/** The last assert message, line number. */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/** Set if assertions are quiet. */
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic bool volatile g_fQuiet = false;
f78b12e570284aa8291f4ca1add24937fd107403vboxsync/** Set if assertions may panic. */
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncstatic bool volatile g_fMayPanic = true;
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncRTDECL(void) RTAssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * Fill in the globals.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ASMAtomicUoWritePtr((void * volatile *)&g_pszRTAssertExpr, (void *)pszExpr);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ASMAtomicUoWritePtr((void * volatile *)&g_pszRTAssertFile, (void *)pszFile);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync ASMAtomicUoWritePtr((void * volatile *)&g_pszRTAssertFunction, (void *)pszFunction);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "\n!!Assertion Failed!!\n"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "Expression: %s\n"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "Location : %s(%d) %s\n",
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * If not quiet, make noise.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "Expression: %s\n"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "Location : %s(%d) %s\n",
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /** @todo fully integrate this with the logger... play safe a bit for now. */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync rtR0AssertNativeMsg1(pszExpr, uLine, pszFile, pszFunction);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#else /* !IN_RING0 */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "Expression: %s\n"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "Location : %s(%d) %s\n",
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "Expression: %s\n"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "Location : %s(%d) %s\n",
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# ifndef IN_RC /* flushing is done automatically in RC */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "Expression: %s\n"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "Location : %s(%d) %s\n",
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# ifndef IN_RC /* flushing is done automatically in RC */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* print to stderr, helps user and gdb debugging. */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "\n!!Assertion Failed!!\n"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "Expression: %s\n"
f78b12e570284aa8291f4ca1add24937fd107403vboxsync "Location : %s(%d) %s\n",
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif /* !IN_RING0 */
f78b12e570284aa8291f4ca1add24937fd107403vboxsyncRTDECL(void) RTAssertMsg2V(const char *pszFormat, va_list va)
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * The global first.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, vaCopy);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync * If not quiet, make some noise.
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /** @todo fully integrate this with the logger... play safe a bit for now. */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#else /* !IN_RING0 */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# ifndef IN_RC /* flushing is done automatically in RC */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync# ifndef IN_RC /* flushing is done automatically in RC */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync /* print to stderr, helps user and gdb debugging. */
f78b12e570284aa8291f4ca1add24937fd107403vboxsync RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, vaCopy);
f78b12e570284aa8291f4ca1add24937fd107403vboxsync#endif /* !IN_RING0 */