VirtualBox

Changeset 47151 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Jul 15, 2013 10:47:42 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
87253
Message:

crOpenGL & wddm: auto dump file generation, fixes and cleanup

Location:
trunk/src/VBox/Additions/common/crOpenGL
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/crOpenGL/load.c

    r46757 r47151  
    397397    crUnlockMutex(mutex);
    398398# if defined(WINDOWS)
    399     if (RTThreadGetState(stub.hSyncThread)!=RTTHREADSTATE_TERMINATED)
     399    if (stub.hSyncThread && RTThreadGetState(stub.hSyncThread)!=RTTHREADSTATE_TERMINATED)
    400400    {
    401401        HANDLE hNative;
     
    820820# ifdef VBOX_WITH_WDDM
    821821    HMODULE hVBoxD3D = NULL;
    822     HRESULT hr;
    823822    GLint spuConnection = 0;
    824823# endif
     
    938937    int i;
    939938    int disable_sync = 0;
     939#if defined(WINDOWS) && defined(VBOX_WITH_WDDM)
     940    HMODULE hVBoxD3D = NULL;
     941#endif
    940942
    941943    stubInitVars();
     
    954956    }
    955957#elif defined(WINDOWS) && defined(VBOX_WITH_WDDM)
    956     if (stub.bNewPresent)
     958    hVBoxD3D = NULL;
     959    if (!GetModuleHandleEx(0, VBOX_MODNAME_DISPD3D, &hVBoxD3D))
     960    {
     961        crDebug("GetModuleHandleEx failed err %d", GetLastError());
     962        hVBoxD3D = NULL;
     963    }
     964
     965    if (hVBoxD3D)
    957966    {
    958967        disable_sync = 1;
    959968        crDebug("running with %s", VBOX_MODNAME_DISPD3D);
     969        stub.trackWindowVisibleRgn = 0;
     970        stub.trackWindowSize = 0;
     971        stub.trackWindowPos = 0;
     972        stub.trackWindowVisibility = 0;
    960973        stub.trackWindowVisibleRgn = 0;
    961974        stub.bRunningUnderWDDM = true;
     
    11161129#include <windows.h>
    11171130
    1118 #ifdef DEBUG_misha
     1131#if 1//def DEBUG_misha
    11191132 /* debugging: this is to be able to catch first-chance notifications
    11201133  * for exceptions other than EXCEPTION_BREAKPOINT in kernel debugger */
     
    11231136
    11241137#ifdef VDBG_VEHANDLER
    1125 static PVOID g_VBoxWDbgVEHandler = NULL;
    1126 static DWORD g_VBoxWDbgVEHExit = 1;
     1138# include <dbghelp.h>
     1139static PVOID g_VBoxVehHandler = NULL;
     1140static DWORD g_VBoxVehEnable = 0;
     1141
     1142/* generate a crash dump on exception */
     1143#define VBOXVEH_F_DUMP 0x00000001
     1144/* generate a debugger breakpoint exception */
     1145#define VBOXVEH_F_BREAK 0x00000002
     1146/* exit on exception */
     1147#define VBOXVEH_F_EXIT  0x00000004
     1148
     1149static DWORD g_VBoxVehFlags = VBOXVEH_F_DUMP
     1150#ifdef DEBUG_misha
     1151                            | VBOXVEH_F_BREAK
     1152#endif
     1153        ;
     1154
     1155typedef BOOL WINAPI FNVBOXDBG_MINIDUMPWRITEDUMP(HANDLE hProcess,
     1156            DWORD ProcessId,
     1157            HANDLE hFile,
     1158            MINIDUMP_TYPE DumpType,
     1159            PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
     1160            PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
     1161            PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
     1162typedef FNVBOXDBG_MINIDUMPWRITEDUMP *PFNVBOXDBG_MINIDUMPWRITEDUMP;
     1163
     1164static HMODULE g_hVBoxMdDbgHelp = NULL;
     1165static PFNVBOXDBG_MINIDUMPWRITEDUMP g_pfnVBoxMdMiniDumpWriteDump = NULL;
     1166static uint32_t g_cVBoxMdFilePrefixLen = 0;
     1167static WCHAR g_aszwVBoxMdFilePrefix[MAX_PATH];
     1168static WCHAR g_aszwVBoxMdDumpCount = 0;
     1169static MINIDUMP_TYPE g_enmVBoxMdDumpType = MiniDumpNormal
     1170        | MiniDumpWithDataSegs
     1171        | MiniDumpWithFullMemory
     1172        | MiniDumpWithHandleData
     1173////        | MiniDumpFilterMemory
     1174////        | MiniDumpScanMemory
     1175//        | MiniDumpWithUnloadedModules
     1176////        | MiniDumpWithIndirectlyReferencedMemory
     1177////        | MiniDumpFilterModulePaths
     1178//        | MiniDumpWithProcessThreadData
     1179//        | MiniDumpWithPrivateReadWriteMemory
     1180////        | MiniDumpWithoutOptionalData
     1181//        | MiniDumpWithFullMemoryInfo
     1182//        | MiniDumpWithThreadInfo
     1183//        | MiniDumpWithCodeSegs
     1184//        | MiniDumpWithFullAuxiliaryState
     1185//        | MiniDumpWithPrivateWriteCopyMemory
     1186//        | MiniDumpIgnoreInaccessibleMemory
     1187//        | MiniDumpWithTokenInformation
     1188////        | MiniDumpWithModuleHeaders
     1189////        | MiniDumpFilterTriage
     1190        ;
     1191
     1192
     1193
     1194#define VBOXMD_DUMP_DIR_PREFIX_DEFAULT L"C:\\dumps\\vboxdmp"
     1195
     1196static HMODULE loadSystemDll(const char *pszName)
     1197{
     1198    char   szPath[MAX_PATH];
     1199    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
     1200    size_t cbName  = strlen(pszName) + 1;
     1201    if (cchPath + 1 + cbName > sizeof(szPath))
     1202    {
     1203        SetLastError(ERROR_FILENAME_EXCED_RANGE);
     1204        return NULL;
     1205    }
     1206    szPath[cchPath] = '\\';
     1207    memcpy(&szPath[cchPath + 1], pszName, cbName);
     1208    return LoadLibraryA(szPath);
     1209}
     1210
     1211static DWORD vboxMdMinidumpCreate(struct _EXCEPTION_POINTERS *pExceptionInfo)
     1212{
     1213    WCHAR aszwMdFileName[MAX_PATH];
     1214    HANDLE hProcess = GetCurrentProcess();
     1215    DWORD ProcessId = GetCurrentProcessId();
     1216    MINIDUMP_EXCEPTION_INFORMATION ExceptionInfo;
     1217    HANDLE hFile;
     1218    DWORD winErr = ERROR_SUCCESS;
     1219
     1220    if (!g_pfnVBoxMdMiniDumpWriteDump)
     1221    {
     1222        if (!g_hVBoxMdDbgHelp)
     1223        {
     1224            g_hVBoxMdDbgHelp = loadSystemDll("DbgHelp.dll");
     1225            if (!g_hVBoxMdDbgHelp)
     1226                return GetLastError();
     1227        }
     1228
     1229        g_pfnVBoxMdMiniDumpWriteDump = (PFNVBOXDBG_MINIDUMPWRITEDUMP)GetProcAddress(g_hVBoxMdDbgHelp, "MiniDumpWriteDump");
     1230        if (!g_pfnVBoxMdMiniDumpWriteDump)
     1231            return GetLastError();
     1232    }
     1233
     1234    /* @todo: this is a tmp stuff until we get that info from the settings properly */
     1235    if (!g_cVBoxMdFilePrefixLen)
     1236    {
     1237        g_cVBoxMdFilePrefixLen = sizeof (VBOXMD_DUMP_DIR_PREFIX_DEFAULT)/sizeof (g_aszwVBoxMdFilePrefix[0]) - 1 /* <- don't include nul terminator */;
     1238        memcpy(g_aszwVBoxMdFilePrefix, VBOXMD_DUMP_DIR_PREFIX_DEFAULT, sizeof (VBOXMD_DUMP_DIR_PREFIX_DEFAULT));
     1239    }
     1240
     1241
     1242    if (RT_ELEMENTS(aszwMdFileName) <= g_cVBoxMdFilePrefixLen)
     1243    {
     1244        return ERROR_INVALID_STATE;
     1245    }
     1246
     1247    ++g_aszwVBoxMdDumpCount;
     1248
     1249    memcpy(aszwMdFileName, g_aszwVBoxMdFilePrefix, g_cVBoxMdFilePrefixLen * sizeof (g_aszwVBoxMdFilePrefix[0]));
     1250    swprintf(aszwMdFileName + g_cVBoxMdFilePrefixLen, RT_ELEMENTS(aszwMdFileName) - g_cVBoxMdFilePrefixLen, L"%d_%d.dmp", ProcessId, g_aszwVBoxMdDumpCount);
     1251
     1252    hFile = CreateFileW(aszwMdFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
     1253    if (hFile == INVALID_HANDLE_VALUE)
     1254        return GetLastError();
     1255
     1256    ExceptionInfo.ThreadId = GetCurrentThreadId();
     1257    ExceptionInfo.ExceptionPointers = pExceptionInfo;
     1258    ExceptionInfo.ClientPointers = FALSE;
     1259
     1260    if (!g_pfnVBoxMdMiniDumpWriteDump(hProcess, ProcessId, hFile, g_enmVBoxMdDumpType, &ExceptionInfo, NULL, NULL))
     1261        winErr = GetLastError();
     1262
     1263    CloseHandle(hFile);
     1264    return winErr;
     1265}
     1266
    11271267LONG WINAPI vboxVDbgVectoredHandler(struct _EXCEPTION_POINTERS *pExceptionInfo)
    11281268{
     
    11391279        case EXCEPTION_INT_DIVIDE_BY_ZERO:
    11401280        case EXCEPTION_ILLEGAL_INSTRUCTION:
    1141             CRASSERT(0);
    1142             if (g_VBoxWDbgVEHExit)
     1281            if (g_VBoxVehFlags & VBOXVEH_F_BREAK)
     1282            {
     1283                BOOL fBreak = TRUE;
     1284                if (pExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
     1285                {
     1286                    HANDLE hProcess = GetCurrentProcess();
     1287                    BOOL fDebuggerPresent = FALSE;
     1288                    /* we do not want to generate breakpoint exceptions recursively, so do it only when running under debugger */
     1289                    if (CheckRemoteDebuggerPresent(hProcess, &fDebuggerPresent))
     1290                        fBreak = !!fDebuggerPresent;
     1291                    else
     1292                        fBreak = FALSE; /* <- the function has failed, don't break for sanity */
     1293                }
     1294
     1295                if (fBreak)
     1296                {
     1297                    RT_BREAKPOINT();
     1298                }
     1299            }
     1300
     1301            if (g_VBoxVehFlags & VBOXVEH_F_DUMP)
     1302                vboxMdMinidumpCreate(pExceptionInfo);
     1303
     1304            if (g_VBoxVehFlags & VBOXVEH_F_EXIT)
    11431305                exit(1);
    11441306            break;
     
    11511313void vboxVDbgVEHandlerRegister()
    11521314{
    1153     CRASSERT(!g_VBoxWDbgVEHandler);
    1154     g_VBoxWDbgVEHandler = AddVectoredExceptionHandler(1,vboxVDbgVectoredHandler);
    1155     CRASSERT(g_VBoxWDbgVEHandler);
     1315    CRASSERT(!g_VBoxVehHandler);
     1316    g_VBoxVehHandler = AddVectoredExceptionHandler(1,vboxVDbgVectoredHandler);
     1317    CRASSERT(g_VBoxVehHandler);
    11561318}
    11571319
     
    11591321{
    11601322    ULONG uResult;
    1161     if (g_VBoxWDbgVEHandler)
    1162     {
    1163         uResult = RemoveVectoredExceptionHandler(g_VBoxWDbgVEHandler);
     1323    if (g_VBoxVehHandler)
     1324    {
     1325        uResult = RemoveVectoredExceptionHandler(g_VBoxVehHandler);
    11641326        CRASSERT(uResult);
    1165         g_VBoxWDbgVEHandler = NULL;
     1327        g_VBoxVehHandler = NULL;
    11661328    }
    11671329}
     
    11861348
    11871349#ifdef VDBG_VEHANDLER
    1188         vboxVDbgVEHandlerRegister();
     1350        g_VBoxVehEnable = !!crGetenv("CR_DBG_VEH_ENABLE");
     1351        if (g_VBoxVehEnable)
     1352            vboxVDbgVEHandlerRegister();
    11891353#endif
    11901354
     
    12011365            crDebug("Failed to connect to host (is guest 3d acceleration enabled?), aborting ICD load.");
    12021366#ifdef VDBG_VEHANDLER
    1203             vboxVDbgVEHandlerUnregister();
     1367            if (g_VBoxVehEnable)
     1368                vboxVDbgVEHandlerUnregister();
    12041369#endif
    12051370            return FALSE;
     
    12071372        else
    12081373        {
    1209             /* @todo: impl proper detection */
    1210 #ifndef DEBUG_misha
    1211             stub.bNewPresent = true;
    1212 #endif
    1213 
    12141374            crNetFreeConnection(ns.conn);
    12151375        }
     
    12361396
    12371397#ifdef VDBG_VEHANDLER
    1238         vboxVDbgVEHandlerUnregister();
     1398        if (g_VBoxVehEnable)
     1399            vboxVDbgVEHandlerUnregister();
    12391400#endif
    12401401        break;
  • trunk/src/VBox/Additions/common/crOpenGL/stub.h

    r46757 r47151  
    261261# ifdef VBOX_WITH_WDDM
    262262    bool            bRunningUnderWDDM;
    263     bool            bNewPresent;
    264263# endif
    265264#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