VirtualBox

Changeset 25528 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Dec 20, 2009 11:24:59 PM (15 years ago)
Author:
vboxsync
Message:

IPRT,SUPDrv,++: AssertMsg[12] -> AssertMsg1Weak, AssertMsg1, AssertMsg2Weak, AssertMsg2, AssertMsg2WeakV and AssertMsg2V. Doing more of the assertion machinery in common/misc/assert.cpp to avoid code duplication (ring-0). Major SUPDrv version bump.

Location:
trunk/src/VBox/Runtime/common/misc
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/RTAssertMsg1Weak.cpp

    r21337 r25528  
    3939
    4040
    41 RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
     41RTDECL(void) RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
    4242{
    4343    RTAssertMsg1(pszExpr, uLine, pszFile, pszFunction);
    4444}
    45 RT_EXPORT_SYMBOL(AssertMsg1);
     45RT_EXPORT_SYMBOL(RTAssertMsg1Weak);
    4646
  • trunk/src/VBox/Runtime/common/misc/RTAssertMsg2Weak.cpp

    r21337 r25528  
    55
    66/*
    7  * Copyright (C) 2008 Sun Microsystems, Inc.
     7 * Copyright (C) 2008-2009 Sun Microsystems, Inc.
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3939
    4040
    41 RTDECL(void) AssertMsg2(const char *pszFormat, ...)
     41RTDECL(void) RTAssertMsg2Weak(const char *pszFormat, ...)
    4242{
    4343    va_list va;
    4444    va_start(va, pszFormat);
    45     RTAssertMsg2V(pszFormat, va);
     45    RTAssertMsg2WeakV(pszFormat, va);
    4646    va_end(va);
    4747}
    48 RT_EXPORT_SYMBOL(AssertMsg2);
     48RT_EXPORT_SYMBOL(RTAssertMsg2Weak);
    4949
  • trunk/src/VBox/Runtime/common/misc/assert.cpp

    r25525 r25528  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Assertion Workers.
     3 * IPRT - Assertions, common code.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     7 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4343# include <stdio.h>
    4444#endif
     45#include "internal/assert.h"
    4546
    4647
     
    4849*   Global Variables                                                           *
    4950*******************************************************************************/
     51/** The last assert message, 1st part. */
     52RTDATADECL(char)                    g_szRTAssertMsg1[1024];
     53RT_EXPORT_SYMBOL(g_szRTAssertMsg1);
     54/** The last assert message, 2nd part. */
     55RTDATADECL(char)                    g_szRTAssertMsg2[2048];
     56RT_EXPORT_SYMBOL(g_szRTAssertMsg2);
     57/** The last assert message, expression. */
     58RTDATADECL(const char * volatile)   g_pszRTAssertExpr;
     59RT_EXPORT_SYMBOL(g_pszRTAssertExpr);
     60/** The last assert message, function name. */
     61RTDATADECL(const char *  volatile)  g_pszRTAssertFunction;
     62RT_EXPORT_SYMBOL(g_pszRTAssertFunction);
     63/** The last assert message, file name. */
     64RTDATADECL(const char * volatile)   g_pszRTAssertFile;
     65RT_EXPORT_SYMBOL(g_pszRTAssertFile);
     66/** The last assert message, line number. */
     67RTDATADECL(uint32_t volatile)       g_u32RTAssertLine;
     68RT_EXPORT_SYMBOL(g_u32RTAssertLine);
     69
     70
    5071/** Set if assertions are quiet. */
    51 static bool volatile g_fQuiet = false;
     72static bool volatile                g_fQuiet = false;
    5273/** Set if assertions may panic. */
    53 static bool volatile g_fMayPanic = true;
     74static bool volatile                g_fMayPanic = true;
    5475
    5576
     
    5879    return ASMAtomicXchgBool(&g_fQuiet, fQuiet);
    5980}
     81RT_EXPORT_SYMBOL(RTAssertSetQuiet);
    6082
    6183
     
    6486    return ASMAtomicUoReadBool(&g_fQuiet);
    6587}
     88RT_EXPORT_SYMBOL(RTAssertAreQuiet);
    6689
    6790
     
    7093    return ASMAtomicXchgBool(&g_fMayPanic, fMayPanic);
    7194}
     95RT_EXPORT_SYMBOL(RTAssertSetMayPanic);
    7296
    7397
     
    76100    return ASMAtomicUoReadBool(&g_fMayPanic);
    77101}
    78 
    79 
    80 #ifdef IN_RING0
    81 
    82 /* OS specific.  */
    83 
    84 #else /* !IN_RING0 */
    85 
    86 
    87 /** The last assert message, 1st part. */
    88 RTDATADECL(char) g_szRTAssertMsg1[1024];
    89 /** The last assert message, 2nd part. */
    90 RTDATADECL(char) g_szRTAssertMsg2[2048];
    91 
    92 /**
    93  * The 1st part of an assert message.
    94  *
    95  * @param   pszExpr     Expression. Can be NULL.
    96  * @param   uLine       Location line number.
    97  * @param   pszFile     Location file name.
    98  * @param   pszFunction Location function name.
    99  * @remark  This API exists in HC Ring-3 and GC.
    100  */
    101 RTDECL(void)    AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
    102 {
     102RT_EXPORT_SYMBOL(RTAssertMayPanic);
     103
     104
     105RTDECL(void) RTAssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
     106{
     107    /*
     108     * Fill in the globals.
     109     */
     110    ASMAtomicUoWritePtr((void * volatile *)&g_pszRTAssertExpr, (void *)pszExpr);
     111    ASMAtomicUoWritePtr((void * volatile *)&g_pszRTAssertFile, (void *)pszFile);
     112    ASMAtomicUoWritePtr((void * volatile *)&g_pszRTAssertFunction, (void *)pszFunction);
     113    ASMAtomicUoWriteU32(&g_u32RTAssertLine, uLine);
     114    RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
     115                "\n!!Assertion Failed!!\n"
     116                "Expression: %s\n"
     117                "Location  : %s(%d) %s\n",
     118                pszExpr, pszFile, uLine, pszFunction);
     119
     120    /*
     121     * If not quiet, make noise.
     122     */
    103123    if (!RTAssertAreQuiet())
    104124    {
    105 #if !defined(IN_RING3) && !defined(LOG_NO_COM)
     125#ifdef IN_RING0
     126# ifdef IN_GUEST_R0
     127        RTLogBackdoorPrintf("\n!!Assertion Failed!!\n"
     128                            "Expression: %s\n"
     129                            "Location  : %s(%d) %s\n",
     130                            pszExpr, pszFile, uLine, pszFunction);
     131# endif
     132        /** @todo fully integrate this with the logger... play safe a bit for now.  */
     133        rtR0AssertNativeMsg1(pszExpr, uLine, pszFile, pszFunction);
     134
     135#else  /* !IN_RING0 */
     136# if !defined(IN_RING3) && !defined(LOG_NO_COM)
    106137        RTLogComPrintf("\n!!Assertion Failed!!\n"
    107138                       "Expression: %s\n"
    108139                       "Location  : %s(%d) %s\n",
    109140                       pszExpr, pszFile, uLine, pszFunction);
    110 #endif
     141# endif
    111142
    112143        PRTLOGGER pLog = RTLogRelDefaultInstance();
     
    117148                           "Location  : %s(%d) %s\n",
    118149                           pszExpr, pszFile, uLine, pszFunction);
    119 #ifndef IN_RC /* flushing is done automatically in RC */
     150# ifndef IN_RC /* flushing is done automatically in RC */
    120151            RTLogFlush(pLog);
    121 #endif
    122         }
    123 
    124 #ifndef LOG_ENABLED
     152# endif
     153        }
     154
     155# ifndef LOG_ENABLED
    125156        if (!pLog)
    126 #endif
     157# endif
    127158        {
    128159            pLog = RTLogDefaultInstance();
     
    133164                            "Location  : %s(%d) %s\n",
    134165                            pszExpr, pszFile, uLine, pszFunction);
    135 #ifndef IN_RC /* flushing is done automatically in RC */
     166# ifndef IN_RC /* flushing is done automatically in RC */
    136167                RTLogFlush(pLog);
    137 #endif
     168# endif
    138169            }
    139170        }
    140171
    141 #ifdef IN_RING3
     172# ifdef IN_RING3
    142173        /* print to stderr, helps user and gdb debugging. */
    143174        fprintf(stderr,
     
    150181                VALID_PTR(pszFunction) ? pszFunction : "");
    151182        fflush(stderr);
    152 #endif
     183# endif
     184#endif /* !IN_RING0 */
    153185    }
    154 
    155     RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
    156                 "\n!!Assertion Failed!!\n"
    157                 "Expression: %s\n"
    158                 "Location  : %s(%d) %s\n",
    159                 pszExpr, pszFile, uLine, pszFunction);
    160 }
    161 
    162 
    163 /**
    164  * The 2nd (optional) part of an assert message.
    165  *
    166  * @param   pszFormat   Printf like format string.
    167  * @param   ...         Arguments to that string.
    168  * @remark  This API exists in HC Ring-3 and GC.
    169  */
    170 RTDECL(void)    AssertMsg2(const char *pszFormat, ...)
    171 {
    172     va_list args;
    173 
     186}
     187RT_EXPORT_SYMBOL(RTAssertMsg1);
     188
     189
     190RTDECL(void) RTAssertMsg2V(const char *pszFormat, va_list va)
     191{
     192    va_list vaCopy;
     193
     194    /*
     195     * The global first.
     196     */
     197    va_copy(vaCopy, va);
     198    RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, vaCopy);
     199    va_end(vaCopy);
     200
     201    /*
     202     * If not quiet, make some noise.
     203     */
    174204    if (!RTAssertAreQuiet())
    175205    {
    176 #if !defined(IN_RING3) && !defined(LOG_NO_COM)
    177         va_start(args, pszFormat);
    178         RTLogComPrintfV(pszFormat, args);
    179         va_end(args);
    180 #endif
     206#ifdef IN_RING0
     207# ifdef IN_GUEST_R0
     208        va_copy(vaCopy, va);
     209        RTLogBackdoorPrintfV(pszFormat, vaCopy);
     210        va_end(vaCopy);
     211# endif
     212        /** @todo fully integrate this with the logger... play safe a bit for now.  */
     213        rtR0AssertNativeMsg2V(pszFormat, va);
     214
     215#else  /* !IN_RING0 */
     216# if !defined(IN_RING3) && !defined(LOG_NO_COM)
     217        va_copy(vaCopy, va);
     218        RTLogComPrintfV(pszFormat, vaCopy);
     219        va_end(vaCopy);
     220# endif
    181221
    182222        PRTLOGGER pLog = RTLogRelDefaultInstance();
    183223        if (pLog)
    184224        {
    185             va_start(args, pszFormat);
    186             RTLogRelPrintfV(pszFormat, args);
    187             va_end(args);
    188 #ifndef IN_RC /* flushing is done automatically in RC */
     225            va_copy(vaCopy, va);
     226            RTLogRelPrintfV(pszFormat, vaCopy);
     227            va_end(vaCopy);
     228# ifndef IN_RC /* flushing is done automatically in RC */
     229            RTLogFlush(pLog);
     230# endif
     231        }
     232
     233        pLog = RTLogDefaultInstance();
     234        if (pLog)
     235        {
     236            va_copy(vaCopy, va);
     237            RTLogPrintfV(pszFormat, vaCopy);
     238            va_end(vaCopy);
     239# ifndef IN_RC /* flushing is done automatically in RC */
    189240            RTLogFlush(pLog);
    190241#endif
    191242        }
    192243
    193         pLog = RTLogDefaultInstance();
    194         if (pLog)
    195         {
    196             va_start(args, pszFormat);
    197             RTLogPrintfV(pszFormat, args);
    198             va_end(args);
    199 #ifndef IN_RC /* flushing is done automatically in RC */
    200             RTLogFlush(pLog);
    201 #endif
    202         }
    203 
    204 #ifdef IN_RING3
     244# ifdef IN_RING3
    205245        /* print to stderr, helps user and gdb debugging. */
    206246        char szMsg[1024];
    207         va_start(args, pszFormat);
    208         RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, args);
    209         va_end(args);
     247        va_copy(vaCopy, va);
     248        RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, vaCopy);
     249        va_end(vaCopy);
    210250        fprintf(stderr, "%s", szMsg);
    211251        fflush(stderr);
    212 #endif
     252# endif
     253#endif /* !IN_RING0 */
    213254    }
    214255
    215     va_start(args, pszFormat);
    216     RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, args);
    217     va_end(args);
    218 }
    219 
    220 #endif /* !IN_RING0 */
    221 
     256}
     257RT_EXPORT_SYMBOL(RTAssertMsg2V);
     258
  • trunk/src/VBox/Runtime/common/misc/lockvalidator.cpp

    r25519 r25528  
    819819                                                 PRTTHREADINT pCur, PCRTLOCKVALIDATORSRCPOS pSrcPos)
    820820{
    821     AssertMsg1(pCur == pThread ? "!!Deadlock detected!!" : "!!Deadlock exists!!", pSrcPos->uLine, pSrcPos->pszFile, pSrcPos->pszFunction);
     821    RTAssertMsg1Weak(pCur == pThread ? "!!Deadlock detected!!" : "!!Deadlock exists!!", pSrcPos->uLine, pSrcPos->pszFile, pSrcPos->pszFunction);
    822822
    823823    /*
     
    832832         * Print info on pCur. Determin next while doing so.
    833833         */
    834         AssertMsg2(" #%u: %RTthrd/%RTnthrd %s: %s(%u) %RTptr\n",
    835                    iEntry, pCur, pCur->Core.Key, pCur->szName,
    836                    pCur->LockValidator.SrcPos.pszFile, pCur->LockValidator.SrcPos.uLine,
    837                    pCur->LockValidator.SrcPos.pszFunction, pCur->LockValidator.SrcPos.uId);
     834        RTAssertMsg2Weak(" #%u: %RTthrd/%RTnthrd %s: %s(%u) %RTptr\n",
     835                         iEntry, pCur, pCur->Core.Key, pCur->szName,
     836                         pCur->LockValidator.SrcPos.pszFile, pCur->LockValidator.SrcPos.uLine,
     837                         pCur->LockValidator.SrcPos.pszFunction, pCur->LockValidator.SrcPos.uId);
    838838        PRTTHREADINT  pNext       = NULL;
    839839        RTTHREADSTATE enmCurState = rtThreadGetState(pCur);
     
    853853                if (enmCurState2 != enmCurState)
    854854                {
    855                     AssertMsg2(" Impossible!!! enmState=%s -> %s (%d)\n",
    856                                RTThreadStateName(enmCurState), RTThreadStateName(enmCurState2), enmCurState2);
     855                    RTAssertMsg2Weak(" Impossible!!! enmState=%s -> %s (%d)\n",
     856                                     RTThreadStateName(enmCurState), RTThreadStateName(enmCurState2), enmCurState2);
    857857                    break;
    858858                }
     
    860860                    && pCurRec->u32Magic == RTLOCKVALIDATORREC_MAGIC)
    861861                {
    862                     AssertMsg2("     Waiting on %s %p [%s]: Entered %s(%u) %s %p\n",
    863                                RTThreadStateName(enmCurState), pCurRec->hLock, pCurRec->pszName,
    864                                pCurRec->SrcPos.pszFile, pCurRec->SrcPos.uLine, pCurRec->SrcPos.pszFunction, pCurRec->SrcPos.uId);
     862                    RTAssertMsg2Weak("     Waiting on %s %p [%s]: Entered %s(%u) %s %p\n",
     863                                     RTThreadStateName(enmCurState), pCurRec->hLock, pCurRec->pszName,
     864                                     pCurRec->SrcPos.pszFile, pCurRec->SrcPos.uLine, pCurRec->SrcPos.pszFunction, pCurRec->SrcPos.uId);
    865865                    pNext = pCurRec->hThread;
    866866                }
    867867                else if (VALID_PTR(pCurRec))
    868                     AssertMsg2("     Waiting on %s pCurRec=%p: invalid magic number: %#x\n",
    869                                RTThreadStateName(enmCurState), pCurRec, pCurRec->u32Magic);
     868                    RTAssertMsg2Weak("     Waiting on %s pCurRec=%p: invalid magic number: %#x\n",
     869                                     RTThreadStateName(enmCurState), pCurRec, pCurRec->u32Magic);
    870870                else
    871                     AssertMsg2("     Waiting on %s pCurRec=%p: invalid pointer\n",
    872                                RTThreadStateName(enmCurState), pCurRec);
     871                    RTAssertMsg2Weak("     Waiting on %s pCurRec=%p: invalid pointer\n",
     872                                     RTThreadStateName(enmCurState), pCurRec);
    873873                break;
    874874            }
    875875
    876876            default:
    877                 AssertMsg2(" Impossible!!! enmState=%s (%d)\n", RTThreadStateName(enmCurState), enmCurState);
     877                RTAssertMsg2Weak(" Impossible!!! enmState=%s (%d)\n", RTThreadStateName(enmCurState), enmCurState);
    878878                break;
    879879        }
     
    887887            if (apSeenThreads[i] == pCur)
    888888            {
    889                 AssertMsg2(" Cycle!\n");
     889                RTAssertMsg2Weak(" Cycle!\n");
    890890                pNext = NULL;
    891891                break;
  • trunk/src/VBox/Runtime/common/misc/thread.cpp

    r25436 r25528  
    192192    g_ThreadSpinlock = NIL_RTSPINLOCK;
    193193    if (g_ThreadTree != NULL)
    194         AssertMsg2("WARNING: g_ThreadTree=%p\n", g_ThreadTree);
     194        RTAssertMsg2Weak("WARNING: g_ThreadTree=%p\n", g_ThreadTree);
    195195#endif
    196196}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette