VirtualBox

Changeset 68980 in vbox for trunk/src/VBox/Runtime/r3/win


Ignore:
Timestamp:
Oct 4, 2017 12:35:20 PM (7 years ago)
Author:
vboxsync
Message:

init-win.cpp: Dump the list of loaded modules too, marking the one with the offending PC in it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/init-win.cpp

    r68976 r68980  
    3030*********************************************************************************************************************************/
    3131#define LOG_GROUP RTLOGGROUP_DEFAULT
    32 #include <iprt/win/windows.h>
     32#include <iprt/nt/nt-and-windows.h>
    3333#ifndef LOAD_LIBRARY_SEARCH_APPLICATION_DIR
    3434# define LOAD_LIBRARY_SEARCH_APPLICATION_DIR    0x200
     
    400400    if (pLogger)
    401401    {
    402         RTLogLogger(pLogger, NULL, "\nrtR3WinUnhandledXcptFilter: !Exception!\n");
    403         RTLogLogger(pLogger, NULL,  "Thread ID:   %p\n", RTThreadNativeSelf());
     402        RTLogLogger(pLogger, NULL, "\n!!! rtR3WinUnhandledXcptFilter caught an exception on thread %p!!!\n", RTThreadNativeSelf());
    404403
    405404        /*
    406405         * Dump the exception record.
    407406         */
     407        uintptr_t         uXcptPC  = 0;
    408408        PEXCEPTION_RECORD pXcptRec = RT_VALID_PTR(pPtrs) && RT_VALID_PTR(pPtrs->ExceptionRecord) ? pPtrs->ExceptionRecord : NULL;
    409409        if (pXcptRec)
    410410        {
    411             RTLogLogger(pLogger, NULL, "ExceptionCode=%#010x ExceptionFlags=%#010x ExceptionAddress=%p\n",
     411            RTLogLogger(pLogger, NULL, "\nExceptionCode=%#010x ExceptionFlags=%#010x ExceptionAddress=%p\n",
    412412                        pXcptRec->ExceptionCode, pXcptRec->ExceptionFlags, pXcptRec->ExceptionAddress);
    413413            for (uint32_t i = 0; i < RT_MIN(pXcptRec->NumberParameters, EXCEPTION_MAXIMUM_PARAMETERS); i++)
    414414                RTLogLogger(pLogger, NULL, "ExceptionInformation[%d]=%p\n", i, pXcptRec->ExceptionInformation[i]);
     415            uXcptPC = (uintptr_t)pXcptRec->ExceptionAddress;
    415416
    416417            /* Nested? Display one level only. */
     
    423424                for (uint32_t i = 0; i < RT_MIN(pNestedRec->NumberParameters, EXCEPTION_MAXIMUM_PARAMETERS); i++)
    424425                    RTLogLogger(pLogger, NULL, "Nested: ExceptionInformation[%d]=%p\n", i, pNestedRec->ExceptionInformation[i]);
     426                uXcptPC = (uintptr_t)pNestedRec->ExceptionAddress;
    425427            }
    426428        }
     
    435437        {
    436438#ifdef RT_ARCH_AMD64
    437             RTLogLogger(pLogger, NULL, "cs:rip=%04x:%016RX64\n", pXcptCtx->SegCs, pXcptCtx->Rip);
     439            RTLogLogger(pLogger, NULL, "\ncs:rip=%04x:%016RX64\n", pXcptCtx->SegCs, pXcptCtx->Rip);
    438440            RTLogLogger(pLogger, NULL, "ss:rsp=%04x:%016RX64 rbp=%016RX64\n", pXcptCtx->SegSs, pXcptCtx->Rsp, pXcptCtx->Rbp);
    439441            RTLogLogger(pLogger, NULL, "rax=%016RX64 rcx=%016RX64 rdx=%016RX64 rbx=%016RX64\n",
     
    456458                        pXcptCtx->LastExceptionToRip, pXcptCtx->LastExceptionFromRip);
    457459            uXcptSP = pXcptCtx->Rsp;
     460            uXcptPC = pXcptCtx->Rip;
    458461
    459462#elif defined(RT_ARCH_X86)
    460             RTLogLogger(pLogger, NULL, "cs:eip=%04x:%08RX32\n", pXcptCtx->SegCs, pXcptCtx->Eip);
     463            RTLogLogger(pLogger, NULL, "\ncs:eip=%04x:%08RX32\n", pXcptCtx->SegCs, pXcptCtx->Eip);
    461464            RTLogLogger(pLogger, NULL, "ss:esp=%04x:%08RX32 ebp=%08RX32\n", pXcptCtx->SegSs, pXcptCtx->Esp, pXcptCtx->Ebp);
    462465            RTLogLogger(pLogger, NULL, "eax=%08RX32 ecx=%08RX32 edx=%08RX32 ebx=%08RX32\n",
     
    467470                        pXcptCtx->SegDs, pXcptCtx->SegEs, pXcptCtx->SegFs, pXcptCtx->SegGs, pXcptCtx->EFlags);
    468471            uXcptSP = pXcptCtx->Esp;
     472            uXcptPC = pXcptCtx->Eip;
    469473#endif
    470474        }
     
    473477         * Dump stack.
    474478         */
    475         void  *pvStack  = (void *)&szMarker[0];
    476         size_t cbToDump = PAGE_SIZE - ((uintptr_t)pvStack & PAGE_OFFSET_MASK);
     479        uintptr_t uStack = (uintptr_t)(void *)&szMarker[0];
     480        uStack -= uStack & 15;
     481
     482        size_t cbToDump = PAGE_SIZE - (uStack & PAGE_OFFSET_MASK);
    477483        if (cbToDump < 512)
    478484            cbToDump += PAGE_SIZE;
    479         size_t cbToXcpt = uXcptSP - (uintptr_t)pvStack;
     485        size_t cbToXcpt = uXcptSP - uStack;
    480486        while (cbToXcpt > cbToDump && cbToXcpt <= _16K)
    481487            cbToDump += PAGE_SIZE;
     
    485491        {
    486492            g_pfnGetCurrentThreadStackLimits(&uLow, &uHigh);
    487             size_t cbToTop = RT_MAX(uLow, uHigh) - (uintptr_t)pvStack;
     493            size_t cbToTop = RT_MAX(uLow, uHigh) - uStack;
    488494            if (cbToTop < _1M)
    489495                cbToDump = cbToTop;
    490496        }
    491497
    492         RTLogLogger(pLogger, NULL, "\nStack %p, dumping %#x bytes (low=%p, high=%p)\n", pvStack, cbToDump, uLow, uHigh);
    493         RTLogLogger(pLogger, NULL, "%.*Rhxd\n", cbToDump, pvStack);
     498        RTLogLogger(pLogger, NULL, "\nStack %p, dumping %#x bytes (low=%p, high=%p)\n", uStack, cbToDump, uLow, uHigh);
     499        RTLogLogger(pLogger, NULL, "%.*Rhxd\n", cbToDump, uStack);
    494500
    495501        /*
     
    502508        RTLogLogger(pLogger, NULL,  "Thread name: %s\n", RTThreadSelfName());
    503509        RTLogLogger(pLogger, NULL,  "Thread IPRT: %p\n", RTThreadSelf());
     510
     511        /*
     512         * Try dump the load information.
     513         */
     514        PPEB pPeb = RTNtCurrentPeb();
     515        if (RT_VALID_PTR(pPeb))
     516        {
     517            PPEB_LDR_DATA pLdrData = pPeb->Ldr;
     518            if (RT_VALID_PTR(pLdrData))
     519            {
     520                LIST_ENTRY     *pList      = &pLdrData->InMemoryOrderModuleList;
     521                LIST_ENTRY     *pListEntry = pList->Flink;
     522                uint32_t        cLoops     = 0;
     523                RTLogLogger(pLogger, NULL,
     524                            "\nLoaded Modules:\n"
     525                            "%-*s[*] Timestamp Path\n", sizeof(void *) * 4 + 2 - 1, "Address range"
     526                            );
     527                while (pListEntry != pList && RT_VALID_PTR(pListEntry) && cLoops < 1024)
     528                {
     529                    PLDR_DATA_TABLE_ENTRY pLdrEntry = RT_FROM_MEMBER(pListEntry, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
     530                    uint32_t const        cbLength  = (uint32_t)(uintptr_t)pLdrEntry->Reserved3[1];
     531                    char const            chInd     = uXcptPC - (uintptr_t)pLdrEntry->DllBase < cbLength ? '*' : ' ';
     532
     533                    if (   RT_VALID_PTR(pLdrEntry->FullDllName.Buffer)
     534                        && pLdrEntry->FullDllName.Length > 0
     535                        && pLdrEntry->FullDllName.Length < _8K
     536                        && (pLdrEntry->FullDllName.Length & 1) == 0
     537                        && pLdrEntry->FullDllName.Length <= pLdrEntry->FullDllName.MaximumLength)
     538                        RTLogLogger(pLogger, NULL, "%p..%p%c  %08RX32  %.*ls\n",
     539                                    pLdrEntry->DllBase, (uintptr_t)pLdrEntry->DllBase + cbLength - 1, chInd,
     540                                    pLdrEntry->TimeDateStamp, pLdrEntry->FullDllName.Length / sizeof(RTUTF16),
     541                                    pLdrEntry->FullDllName.Buffer);
     542                    else
     543                        RTLogLogger(pLogger, NULL, "%p..%p%c  %08RX32  <bad or missing: %p LB %#x max %#x\n",
     544                                    pLdrEntry->DllBase, (uintptr_t)pLdrEntry->DllBase + cbLength - 1, chInd,
     545                                    pLdrEntry->TimeDateStamp, pLdrEntry->FullDllName.Buffer, pLdrEntry->FullDllName.Length,
     546                                    pLdrEntry->FullDllName.MaximumLength);
     547
     548                    /* advance */
     549                    pListEntry = pListEntry->Flink;
     550                    cLoops++;
     551                }
     552            }
     553        }
    504554    }
    505555
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