assert.cpp revision 6bd27257a4f996c855391902114c7ac459e929ed
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * IPRT - Assertions, common code.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2009 Oracle Corporation
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * available from http://www.virtualbox.org. This file is free software;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * you can redistribute it and/or modify it under the terms of the GNU
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * General Public License (GPL) as published by the Free Software
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * The contents of this file may alternatively be used under the terms
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * of the Common Development and Distribution License Version 1.0
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * VirtualBox OSE distribution, in which case the provisions of the
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * CDDL are applicable instead of those of the GPL.
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * You may elect to license modified versions of this file under the
a55af63ead2dcca370bfc0dfe49771d9dcc61b93vboxsync * terms and conditions of either the GPL or the CDDL or both.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/*******************************************************************************
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync* Header Files *
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync*******************************************************************************/
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync/*******************************************************************************
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync* Global Variables *
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync*******************************************************************************/
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync/** The last assert message, 1st part. */
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync/** The last assert message, 2nd part. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The length of the g_szRTAssertMsg2 content.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @remarks Race. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The last assert message, expression. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTDATADECL(const char * volatile) g_pszRTAssertExpr;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The last assert message, function name. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTDATADECL(const char * volatile) g_pszRTAssertFunction;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The last assert message, file name. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTDATADECL(const char * volatile) g_pszRTAssertFile;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The last assert message, line number. */
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync/** Set if assertions are quiet. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncstatic bool volatile g_fQuiet = false;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** Set if assertions may panic. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncstatic bool volatile g_fMayPanic = true;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTDECL(void) RTAssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Fill in the globals.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync ASMAtomicUoWritePtr(&g_pszRTAssertFunction, pszFunction);
7bf07b1592dfaab1a4fb6d497fd0ff1302fb7585vboxsync RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
3dd53c06fd54914761cf550503f02fce1ed5a815vboxsync "\n!!Assertion Failed!!\n"
7c1f498692cd2393f8ba68cb62be482495106f93vboxsync "Expression: %s\n"
ffb14f6b8aefea7399c4bf70faab4c9fc26e6cd5vboxsync "Location : %s(%d) %s\n",
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * If not quiet, make noise.
83e0da18877bbce83f52a975d9102fbbdb9727a8vboxsync "Expression: %s\n"
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "Location : %s(%d) %s\n",
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /** @todo fully integrate this with the logger... play safe a bit for now. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync rtR0AssertNativeMsg1(pszExpr, uLine, pszFile, pszFunction);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#else /* !IN_RING0 */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "Expression: %s\n"
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "Location : %s(%d) %s\n",
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync "Expression: %s\n"
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync "Location : %s(%d) %s\n",
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync# ifndef IN_RC /* flushing is done automatically in RC */
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync "Expression: %s\n"
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync "Location : %s(%d) %s\n",
4cf22805d13f50eef86e917f2c7106fe5198a2d8vboxsync# ifndef IN_RC /* flushing is done automatically in RC */
db0ecde8f28fdb4525bc6d94056166c70b02ebb8vboxsync /* print to stderr, helps user and gdb debugging. */
9dfcf62b7a5a289684d46ee55f6042d49509daecvboxsync "\n!!Assertion Failed!!\n"
e2760cdc84c692bc46cfaf5018d313db2f122acavboxsync "Expression: %s\n"
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync "Location : %s(%d) %s\n",
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync#endif /* !IN_RING0 */
8c58249d7f93d82395aa6c8b31526443892bc375vboxsync * Worker for RTAssertMsg2V and RTAssertMsg2AddV
8c58249d7f93d82395aa6c8b31526443892bc375vboxsync * @param fInitial True if it's RTAssertMsg2V, otherwise false.
8c58249d7f93d82395aa6c8b31526443892bc375vboxsync * @param pszFormat The message format string.
8c58249d7f93d82395aa6c8b31526443892bc375vboxsync * @param va The format arguments.
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsyncstatic void rtAssertMsg2Worker(bool fInitial, const char *pszFormat, va_list va)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * The global first.
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync cch = RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, vaCopy);
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync ASMAtomicWriteU32(&g_cchRTAssertMsg2, (uint32_t)cch);
d40a840eecf0146eee47c14edaef7ace1ddfb5a6vboxsync cch += RTStrPrintfV(&g_szRTAssertMsg2[cch], sizeof(g_szRTAssertMsg2) - cch, pszFormat, vaCopy);
8c58249d7f93d82395aa6c8b31526443892bc375vboxsync ASMAtomicWriteU32(&g_cchRTAssertMsg2, (uint32_t)cch);
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync * If not quiet, make some noise.
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync /** @todo fully integrate this with the logger... play safe a bit for now. */
19cb1f8699e352d590c4946caee33863a5157241vboxsync#else /* !IN_RING0 */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync# ifndef IN_RC /* flushing is done automatically in RC */
5704a317c3b6bdf4b59f6a6ebe45d443296b1995vboxsync# ifndef IN_RC /* flushing is done automatically in RC */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* print to stderr, helps user and gdb debugging. */
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, vaCopy);
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync#endif /* !IN_RING0 */
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsyncRTDECL(void) RTAssertMsg2V(const char *pszFormat, va_list va)
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync rtAssertMsg2Worker(true /*fInitial*/, pszFormat, va);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTDECL(void) RTAssertMsg2AddV(const char *pszFormat, va_list va)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync rtAssertMsg2Worker(false /*fInitial*/, pszFormat, va);