assert.cpp revision e5f80827969997629cbafe4bdb3c5969a322fed5
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * IPRT - Assertions, common code.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2011 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
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync * terms and conditions of either the GPL or the CDDL or both.
a55af63ead2dcca370bfc0dfe49771d9dcc61b93vboxsync/*******************************************************************************
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)
7bf07b1592dfaab1a4fb6d497fd0ff1302fb7585vboxsync * Fill in the globals.
7c1f498692cd2393f8ba68cb62be482495106f93vboxsync ASMAtomicUoWritePtr(&g_pszRTAssertFunction, pszFunction);
4c8907a420ed66a42f729eb08cddf9c1e57f25eavboxsync RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "\n!!Assertion Failed!!\n"
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "Expression: %s\n"
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "Location : %s(%d) %s\n",
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * If not quiet, make noise.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Expression: %s\n"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Location : %s(%d) %s\n",
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync /** @todo fully integrate this with the logger... play safe a bit for now. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync rtR0AssertNativeMsg1(pszExpr, uLine, pszFile, pszFunction);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#else /* !IN_RING0 */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync# if 0 /* Enable this iff you have a COM port and really want this debug info. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "Expression: %s\n"
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "Location : %s(%d) %s\n",
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Expression: %s\n"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Location : %s(%d) %s\n",
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync# ifndef IN_RC /* flushing is done automatically in RC */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Expression: %s\n"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Location : %s(%d) %s\n",
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync# ifndef IN_RC /* flushing is done automatically in RC */
7a29aa5ce149ccd344a2929d2815b8e212690b92vboxsync /* print to stderr, helps user and gdb debugging. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "\n!!Assertion Failed!!\n"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Expression: %s\n"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Location : %s(%d) %s\n",
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#endif /* !IN_RING0 */
5453eb2f2719bf3895ac3daeec4c26e0b6e2eb4avboxsync * Worker for RTAssertMsg2V and RTAssertMsg2AddV
9bb98d54790a98dad0ad6d9bdc5d319b6fdf0bffvboxsync * @param fInitial True if it's RTAssertMsg2V, otherwise false.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * @param pszFormat The message format string.
9bb98d54790a98dad0ad6d9bdc5d319b6fdf0bffvboxsync * @param va The format arguments.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncstatic void rtAssertMsg2Worker(bool fInitial, const char *pszFormat, va_list va)
629e8f58c569e4c51a98284c41754fd9f0b973f8vboxsync * The global first.
8c58249d7f93d82395aa6c8b31526443892bc375vboxsync cch = RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, vaCopy);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync ASMAtomicWriteU32(&g_cchRTAssertMsg2, (uint32_t)cch);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync cch += RTStrPrintfV(&g_szRTAssertMsg2[cch], sizeof(g_szRTAssertMsg2) - cch, pszFormat, vaCopy);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync ASMAtomicWriteU32(&g_cchRTAssertMsg2, (uint32_t)cch);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * If not quiet, make some noise.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /** @todo fully integrate this with the logger... play safe a bit for now. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#else /* !IN_RING0 */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync# if 0 /* Enable this iff you have a COM port and really want this debug info. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync# ifndef IN_RC /* flushing is done automatically in RC */
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync# ifndef IN_RC /* flushing is done automatically in RC */
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync /* print to stderr, helps user and gdb debugging. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, vaCopy);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#endif /* !IN_RING0 */
3933885bc0c2c93436d858a14564c6179ec72872vboxsyncRTDECL(void) RTAssertMsg2V(const char *pszFormat, va_list va)
cc74f15083bf80fbc96723a89faa06c15d0dead8vboxsync rtAssertMsg2Worker(true /*fInitial*/, pszFormat, va);
3933885bc0c2c93436d858a14564c6179ec72872vboxsyncRTDECL(void) RTAssertMsg2AddV(const char *pszFormat, va_list va)
3933885bc0c2c93436d858a14564c6179ec72872vboxsync rtAssertMsg2Worker(false /*fInitial*/, pszFormat, va);