VirtualBox

Changeset 73762 in vbox for trunk


Ignore:
Timestamp:
Aug 19, 2018 1:43:17 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124445
Message:

IPRT/assert: Provide call stack dump on 64-bit windows (ring-3). Experimental.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/assert.h

    r69105 r73762  
    7272RT_C_DECLS_BEGIN
    7373
     74#if  !defined(IPRT_WITHOUT_ASSERT_STACK) \
     75  && defined(IN_RING3) \
     76  && (defined(RT_ARCH_AMD64) /*|| defined(RT_ARCH_X86)*/) \
     77  && (defined(RT_OS_WINDOWS) /*|| ... */)
     78/** @def IPRT_WITH_ASSERT_STACK
     79 * Indicates that we collect a callstack stack on assertion. */
     80# define IPRT_WITH_ASSERT_STACK
     81#endif
     82
    7483/**
    7584 * The 1st part of an assert message.
     
    216225 * @{
    217226 */
    218 /** The last assert message, 1st part. */
     227/** The last assertion message, 1st part. */
    219228extern RTDATADECL(char)                     g_szRTAssertMsg1[1024];
    220 /** The last assert message, 2nd part. */
     229/** The last assertion message, 2nd part. */
    221230extern RTDATADECL(char)                     g_szRTAssertMsg2[4096];
    222 /** The last assert message, expression. */
     231#ifdef IPRT_WITH_ASSERT_STACK
     232/** The last assertion message, stack part. */
     233extern RTDATADECL(char)                     g_szRTAssertStack[4096];
     234#endif
     235/** The last assertion message, expression. */
    223236extern RTDATADECL(const char * volatile)    g_pszRTAssertExpr;
    224 /** The last assert message, file name. */
     237/** The last assertion message, file name. */
    225238extern RTDATADECL(const char * volatile)    g_pszRTAssertFile;
    226 /** The last assert message, line number. */
     239/** The last assertion message, line number. */
    227240extern RTDATADECL(uint32_t volatile)        g_u32RTAssertLine;
    228 /** The last assert message, function name. */
     241/** The last assertion message, function name. */
    229242extern RTDATADECL(const char * volatile)    g_pszRTAssertFunction;
    230243/** @} */
  • trunk/src/VBox/Runtime/common/misc/assert.cpp

    r69111 r73762  
    3333
    3434#include <iprt/asm.h>
     35#ifdef IPRT_WITH_ASSERT_STACK
     36# ifndef IN_RING3
     37#  error "IPRT_WITH_ASSERT_STACK is only for ring-3 at present."
     38# endif
     39# include <iprt/dbg.h>
     40#endif
    3541#include <iprt/err.h>
    3642#include <iprt/log.h>
     
    4652*   Global Variables                                                                                                             *
    4753*********************************************************************************************************************************/
    48 /** The last assert message, 1st part. */
     54/** The last assertion message, 1st part. */
    4955RTDATADECL(char)                    g_szRTAssertMsg1[1024];
    5056RT_EXPORT_SYMBOL(g_szRTAssertMsg1);
    51 /** The last assert message, 2nd part. */
     57/** The last assertion message, 2nd part. */
    5258RTDATADECL(char)                    g_szRTAssertMsg2[4096];
    5359RT_EXPORT_SYMBOL(g_szRTAssertMsg2);
     60#ifdef IPRT_WITH_ASSERT_STACK
     61/** The last assertion message, stack part. */
     62RTDATADECL(char)                    g_szRTAssertStack[4096];
     63RT_EXPORT_SYMBOL(g_szRTAssertStack);
     64#endif
    5465/** The length of the g_szRTAssertMsg2 content.
    5566 * @remarks Race.  */
    5667static uint32_t volatile            g_cchRTAssertMsg2;
    57 /** The last assert message, expression. */
     68/** The last assertion message, expression. */
    5869RTDATADECL(const char * volatile)   g_pszRTAssertExpr;
    5970RT_EXPORT_SYMBOL(g_pszRTAssertExpr);
    60 /** The last assert message, function name. */
     71/** The last assertion message, function name. */
    6172RTDATADECL(const char *  volatile)  g_pszRTAssertFunction;
    6273RT_EXPORT_SYMBOL(g_pszRTAssertFunction);
    63 /** The last assert message, file name. */
     74/** The last assertion message, file name. */
    6475RTDATADECL(const char * volatile)   g_pszRTAssertFile;
    6576RT_EXPORT_SYMBOL(g_pszRTAssertFile);
    66 /** The last assert message, line number. */
     77/** The last assertion message, line number. */
    6778RTDATADECL(uint32_t volatile)       g_u32RTAssertLine;
    6879RT_EXPORT_SYMBOL(g_u32RTAssertLine);
     
    126137        RTErrVarsSave(&SavedErrVars);
    127138
     139#ifdef IPRT_WITH_ASSERT_STACK
     140        /* The stack dump. */
     141        char szStack[sizeof(g_szRTAssertStack)];
     142        size_t cchStack = RTDbgStackDumpSelf(szStack, sizeof(szStack), 0);
     143        memcpy(g_szRTAssertStack, szStack, cchStack + 1);
     144#endif
     145
    128146#ifdef IN_RING0
    129147# ifdef IN_GUEST_R0
     
    153171                           "Location  : %s(%d) %s\n",
    154172                           pszExpr, pszFile, uLine, pszFunction);
     173# ifdef IPRT_WITH_ASSERT_STACK
     174            RTLogRelPrintf("Stack     :\n%s\n", szStack);
     175# endif
    155176# ifndef IN_RC /* flushing is done automatically in RC */
    156177            RTLogFlush(pLog);
     
    169190                            "Location  : %s(%d) %s\n",
    170191                            pszExpr, pszFile, uLine, pszFunction);
     192# ifdef IPRT_WITH_ASSERT_STACK
     193                RTLogPrintf("Stack     :\n%s\n", szStack);
     194# endif
    171195# ifndef IN_RC /* flushing is done automatically in RC */
    172196                RTLogFlush(pLog);
     
    185209                uLine,
    186210                VALID_PTR(pszFunction) ? pszFunction : "");
     211# ifdef IPRT_WITH_ASSERT_STACK
     212        fprintf(stderr, "Stack     :\n%s\n", szStack);
     213# endif
    187214        fflush(stderr);
    188215# endif
Note: See TracChangeset for help on using the changeset viewer.

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