assert.cpp revision e5f80827969997629cbafe4bdb3c5969a322fed5
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/* $Id$ */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** @file
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * IPRT - Assertions, common code.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2011 Oracle Corporation
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync *
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 *
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 *
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 */
e0778e583cb4a0bdc9bcc48f5957e00a01108388vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
a55af63ead2dcca370bfc0dfe49771d9dcc61b93vboxsync/*******************************************************************************
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync* Header Files *
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync*******************************************************************************/
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#include <iprt/assert.h>
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#include "internal/iprt.h"
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync#include <iprt/asm.h>
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#include <iprt/err.h>
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#include <iprt/log.h>
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#include <iprt/string.h>
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#include <iprt/stdarg.h>
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#ifdef IN_RING3
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync# include <stdio.h>
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#endif
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#include "internal/assert.h"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync/*******************************************************************************
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync* Global Variables *
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync*******************************************************************************/
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync/** The last assert message, 1st part. */
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsyncRTDATADECL(char) g_szRTAssertMsg1[1024];
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRT_EXPORT_SYMBOL(g_szRTAssertMsg1);
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync/** The last assert message, 2nd part. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTDATADECL(char) g_szRTAssertMsg2[4096];
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRT_EXPORT_SYMBOL(g_szRTAssertMsg2);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The length of the g_szRTAssertMsg2 content.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @remarks Race. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncstatic uint32_t volatile g_cchRTAssertMsg2;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The last assert message, expression. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTDATADECL(const char * volatile) g_pszRTAssertExpr;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRT_EXPORT_SYMBOL(g_pszRTAssertExpr);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The last assert message, function name. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTDATADECL(const char * volatile) g_pszRTAssertFunction;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRT_EXPORT_SYMBOL(g_pszRTAssertFunction);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The last assert message, file name. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTDATADECL(const char * volatile) g_pszRTAssertFile;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRT_EXPORT_SYMBOL(g_pszRTAssertFile);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** The last assert message, line number. */
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsyncRTDATADECL(uint32_t volatile) g_u32RTAssertLine;
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsyncRT_EXPORT_SYMBOL(g_u32RTAssertLine);
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync/** Set if assertions are quiet. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncstatic bool volatile g_fQuiet = false;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** Set if assertions may panic. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncstatic bool volatile g_fMayPanic = true;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsyncRTDECL(bool) RTAssertSetQuiet(bool fQuiet)
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync{
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync return ASMAtomicXchgBool(&g_fQuiet, fQuiet);
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync}
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsyncRT_EXPORT_SYMBOL(RTAssertSetQuiet);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTDECL(bool) RTAssertAreQuiet(void)
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync{
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync return ASMAtomicUoReadBool(&g_fQuiet);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync}
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRT_EXPORT_SYMBOL(RTAssertAreQuiet);
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsyncRTDECL(bool) RTAssertSetMayPanic(bool fMayPanic)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync{
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync return ASMAtomicXchgBool(&g_fMayPanic, fMayPanic);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync}
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsyncRT_EXPORT_SYMBOL(RTAssertSetMayPanic);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTDECL(bool) RTAssertMayPanic(void)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync{
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync return ASMAtomicUoReadBool(&g_fMayPanic);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync}
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncRT_EXPORT_SYMBOL(RTAssertMayPanic);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTDECL(void) RTAssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync{
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /*
7bf07b1592dfaab1a4fb6d497fd0ff1302fb7585vboxsync * Fill in the globals.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync */
7c1f498692cd2393f8ba68cb62be482495106f93vboxsync ASMAtomicUoWritePtr(&g_pszRTAssertExpr, pszExpr);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync ASMAtomicUoWritePtr(&g_pszRTAssertFile, pszFile);
7c1f498692cd2393f8ba68cb62be482495106f93vboxsync ASMAtomicUoWritePtr(&g_pszRTAssertFunction, pszFunction);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync ASMAtomicUoWriteU32(&g_u32RTAssertLine, uLine);
4c8907a420ed66a42f729eb08cddf9c1e57f25eavboxsync RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "\n!!Assertion Failed!!\n"
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "Expression: %s\n"
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "Location : %s(%d) %s\n",
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync pszExpr, pszFile, uLine, pszFunction);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /*
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * If not quiet, make noise.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync if (!RTAssertAreQuiet())
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync {
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync RTERRVARS SavedErrVars;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync RTErrVarsSave(&SavedErrVars);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#ifdef IN_RING0
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync# ifdef IN_GUEST_R0
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync RTLogBackdoorPrintf("\n!!Assertion Failed!!\n"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Expression: %s\n"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Location : %s(%d) %s\n",
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync pszExpr, pszFile, uLine, pszFunction);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync# endif
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync /** @todo fully integrate this with the logger... play safe a bit for now. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync rtR0AssertNativeMsg1(pszExpr, uLine, pszFile, pszFunction);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#else /* !IN_RING0 */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync# if !defined(IN_RING3) && !defined(LOG_NO_COM)
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync# if 0 /* Enable this iff you have a COM port and really want this debug info. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync RTLogComPrintf("\n!!Assertion Failed!!\n"
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "Expression: %s\n"
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "Location : %s(%d) %s\n",
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync pszExpr, pszFile, uLine, pszFunction);
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync# endif
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync# endif
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync PRTLOGGER pLog = RTLogRelDefaultInstance();
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync if (pLog)
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync RTLogRelPrintf("\n!!Assertion Failed!!\n"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Expression: %s\n"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Location : %s(%d) %s\n",
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync pszExpr, pszFile, uLine, pszFunction);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync# ifndef IN_RC /* flushing is done automatically in RC */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync RTLogFlush(pLog);
85bc82f92f4d7a7b95e96d133c4847b2847703dfvboxsync# endif
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync# ifndef LOG_ENABLED
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync if (!pLog)
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync# endif
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync pLog = RTLogDefaultInstance();
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync if (pLog)
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync RTLogPrintf("\n!!Assertion Failed!!\n"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Expression: %s\n"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Location : %s(%d) %s\n",
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync pszExpr, pszFile, uLine, pszFunction);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync# ifndef IN_RC /* flushing is done automatically in RC */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync RTLogFlush(pLog);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync# endif
49e54e2ffe0c10864d06e9d1ebe24a8eb1327a6bvboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
49e54e2ffe0c10864d06e9d1ebe24a8eb1327a6bvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync# ifdef IN_RING3
7a29aa5ce149ccd344a2929d2815b8e212690b92vboxsync /* print to stderr, helps user and gdb debugging. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync fprintf(stderr,
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "\n!!Assertion Failed!!\n"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Expression: %s\n"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync "Location : %s(%d) %s\n",
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync VALID_PTR(pszExpr) ? pszExpr : "<none>",
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync VALID_PTR(pszFile) ? pszFile : "<none>",
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync uLine,
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync VALID_PTR(pszFunction) ? pszFunction : "");
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync fflush(stderr);
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync# endif
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#endif /* !IN_RING0 */
8c58249d7f93d82395aa6c8b31526443892bc375vboxsync
8c58249d7f93d82395aa6c8b31526443892bc375vboxsync RTErrVarsRestore(&SavedErrVars);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync}
8c58249d7f93d82395aa6c8b31526443892bc375vboxsyncRT_EXPORT_SYMBOL(RTAssertMsg1);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/**
5453eb2f2719bf3895ac3daeec4c26e0b6e2eb4avboxsync * Worker for RTAssertMsg2V and RTAssertMsg2AddV
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync *
9bb98d54790a98dad0ad6d9bdc5d319b6fdf0bffvboxsync * @param fInitial True if it's RTAssertMsg2V, otherwise false.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * @param pszFormat The message format string.
9bb98d54790a98dad0ad6d9bdc5d319b6fdf0bffvboxsync * @param va The format arguments.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncstatic void rtAssertMsg2Worker(bool fInitial, const char *pszFormat, va_list va)
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync{
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync va_list vaCopy;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync size_t cch;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /*
629e8f58c569e4c51a98284c41754fd9f0b973f8vboxsync * The global first.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync */
7c1f498692cd2393f8ba68cb62be482495106f93vboxsync if (fInitial)
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync va_copy(vaCopy, va);
8c58249d7f93d82395aa6c8b31526443892bc375vboxsync cch = RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, vaCopy);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync ASMAtomicWriteU32(&g_cchRTAssertMsg2, (uint32_t)cch);
8c58249d7f93d82395aa6c8b31526443892bc375vboxsync va_end(vaCopy);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync else
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync cch = ASMAtomicReadU32(&g_cchRTAssertMsg2);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync if (cch < sizeof(g_szRTAssertMsg2) - 4)
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync va_copy(vaCopy, va);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync cch += RTStrPrintfV(&g_szRTAssertMsg2[cch], sizeof(g_szRTAssertMsg2) - cch, pszFormat, vaCopy);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync ASMAtomicWriteU32(&g_cchRTAssertMsg2, (uint32_t)cch);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync va_end(vaCopy);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /*
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * If not quiet, make some noise.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync if (!RTAssertAreQuiet())
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync {
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync RTERRVARS SavedErrVars;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync RTErrVarsSave(&SavedErrVars);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync#ifdef IN_RING0
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync# ifdef IN_GUEST_R0
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync va_copy(vaCopy, va);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync RTLogBackdoorPrintfV(pszFormat, vaCopy);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync va_end(vaCopy);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync# endif
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /** @todo fully integrate this with the logger... play safe a bit for now. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync rtR0AssertNativeMsg2V(fInitial, pszFormat, va);
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#else /* !IN_RING0 */
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync# if !defined(IN_RING3) && !defined(LOG_NO_COM)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync# if 0 /* Enable this iff you have a COM port and really want this debug info. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync va_copy(vaCopy, va);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync RTLogComPrintfV(pszFormat, vaCopy);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync va_end(vaCopy);
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync# endif
5704a317c3b6bdf4b59f6a6ebe45d443296b1995vboxsync# endif
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
5704a317c3b6bdf4b59f6a6ebe45d443296b1995vboxsync PRTLOGGER pLog = RTLogRelDefaultInstance();
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync if (pLog)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync {
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync va_copy(vaCopy, va);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync RTLogRelPrintfV(pszFormat, vaCopy);
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync va_end(vaCopy);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync# ifndef IN_RC /* flushing is done automatically in RC */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync RTLogFlush(pLog);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync# endif
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync pLog = RTLogDefaultInstance();
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync if (pLog)
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync {
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync va_copy(vaCopy, va);
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync RTLogPrintfV(pszFormat, vaCopy);
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync va_end(vaCopy);
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync# ifndef IN_RC /* flushing is done automatically in RC */
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync RTLogFlush(pLog);
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync#endif
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync# ifdef IN_RING3
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync /* print to stderr, helps user and gdb debugging. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync char szMsg[sizeof(g_szRTAssertMsg2)];
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync va_copy(vaCopy, va);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, vaCopy);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync va_end(vaCopy);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync fprintf(stderr, "%s", szMsg);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync fflush(stderr);
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync# endif
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#endif /* !IN_RING0 */
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync RTErrVarsRestore(&SavedErrVars);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync }
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync}
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
cc74f15083bf80fbc96723a89faa06c15d0dead8vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsyncRTDECL(void) RTAssertMsg2V(const char *pszFormat, va_list va)
9ca017ceee656f9d33f2cb6652e401b5f17fcfb7vboxsync{
cc74f15083bf80fbc96723a89faa06c15d0dead8vboxsync rtAssertMsg2Worker(true /*fInitial*/, pszFormat, va);
36a04912b64bea8318327fe0723535f1b3f041b0vboxsync}
36a04912b64bea8318327fe0723535f1b3f041b0vboxsyncRT_EXPORT_SYMBOL(RTAssertMsg2V);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync
6e25221ce8ef8e656d1e15eb7ec5cf8ae758ceb2vboxsync
3933885bc0c2c93436d858a14564c6179ec72872vboxsyncRTDECL(void) RTAssertMsg2AddV(const char *pszFormat, va_list va)
3933885bc0c2c93436d858a14564c6179ec72872vboxsync{
3933885bc0c2c93436d858a14564c6179ec72872vboxsync rtAssertMsg2Worker(false /*fInitial*/, pszFormat, va);
3933885bc0c2c93436d858a14564c6179ec72872vboxsync}
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsyncRT_EXPORT_SYMBOL(RTAssertMsg2AddV);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync