]> git.sesse.net Git - vlc/blobdiff - bin/winvlc.c
Merge branch 'master' of git@git.videolan.org:vlc
[vlc] / bin / winvlc.c
index f8268df656fd51a92781ff75da3d1e15b1fe4762..b4824293108df311d22ac9859cca66352e334db9 100644 (file)
 #include <stdlib.h>
 #include <windows.h>
 
+#if !defined(UNDER_CE) && defined ( NDEBUG )
+#   define  _WIN32_IE 0x500
+#   include <shlobj.h>
+#   include <tlhelp32.h>
+#   include <wininet.h>
+static void check_crashdump();
+LONG WINAPI vlc_exception_filter(struct _EXCEPTION_POINTERS *lpExceptionInfo);
+#endif
+
 #ifndef UNDER_CE
 static char *FromWide (const wchar_t *wide)
 {
@@ -128,6 +137,11 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
     libvlc_exception_init (&ex);
     libvlc_exception_init (&dummy);
 
+#if !defined( UNDER_CE ) && defined ( NDEBUG )
+    check_crashdump();
+    SetUnhandledExceptionFilter(vlc_exception_filter);
+#endif
+
     /* Initialize libvlc */
     libvlc_instance_t *vlc;
     vlc = libvlc_new (argc - 1, (const char **)argv + 1, &ex);
@@ -149,3 +163,134 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
     (void)hInstance; (void)hPrevInstance; (void)lpCmdLine; (void)nCmdShow;
     return ret;
 }
+
+#if !defined( UNDER_CE ) && defined ( NDEBUG )
+
+static void get_crashdump_path(wchar_t * wdir)
+{
+    if( S_OK != SHGetFolderPathW( NULL,
+                        CSIDL_APPDATA | CSIDL_FLAG_CREATE,
+                        NULL, SHGFP_TYPE_CURRENT, wdir ) )
+        fprintf( stderr, "Can't open the vlc conf PATH\n" );
+
+    swprintf( wdir+wcslen( wdir ), L"%s", L"\\vlc\\crashdump" );
+}
+
+static void check_crashdump()
+{
+    wchar_t * wdir = (wchar_t *)malloc(sizeof(wchar_t)*MAX_PATH);
+    get_crashdump_path(wdir);
+
+    FILE * fd = _wfopen ( wdir, L"r, ccs=UTF-8" );
+    if( fd )
+    {
+        fclose( fd );
+        int answer = MessageBox( NULL, L"VLC media player just crashed." \
+        " Do you want to send a bug report to the developers team?",
+        L"VLC crash reporting", MB_YESNO);
+
+        if(answer == IDYES)
+        {
+            HINTERNET Hint = InternetOpen(L"VLC Crash Reporter", INTERNET_OPEN_TYPE_PRECONFIG, NULL,NULL,0);
+            if(Hint)
+            {
+                HINTERNET ftp = InternetConnect(Hint, L"crash.videolan.org", INTERNET_DEFAULT_FTP_PORT,
+                                                NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
+                if(ftp)
+                {
+                    SYSTEMTIME now;
+                    GetSystemTime(&now);
+                    wchar_t remote_file[MAX_PATH];
+                    swprintf( remote_file, L"/crashs/%04d%02d%02d%02d%02d%02d",now.wYear,
+                            now.wMonth, now.wDay, now.wHour, now.wMinute, now.wSecond  );
+
+                    FtpPutFile( ftp, wdir, remote_file, FTP_TRANSFER_TYPE_BINARY, 0);
+                    InternetCloseHandle(ftp);
+                }
+                else
+                    fprintf(stderr,"Can't connect to FTP server%d\n",GetLastError());
+                InternetCloseHandle(Hint);
+            }
+        }
+
+        _wremove(wdir);
+    }
+    free((void *)wdir);
+}
+
+/*****************************************************************************
+ * vlc_exception_filter: handles unhandled exceptions, like segfaults
+ *****************************************************************************/
+LONG WINAPI vlc_exception_filter(struct _EXCEPTION_POINTERS *lpExceptionInfo)
+{
+    fprintf( stderr, "unhandled vlc exception\n" );
+
+    wchar_t * wdir = (wchar_t *)malloc(sizeof(wchar_t)*MAX_PATH);
+    get_crashdump_path(wdir);
+    FILE * fd = _wfopen ( wdir, L"w, ccs=UTF-8" );
+    free((void *)wdir);
+
+    if( !fd )
+    {
+        fprintf( stderr, "\nerror while opening file" );
+        exit( 1 );
+    }
+
+    OSVERSIONINFO osvi;
+    ZeroMemory( &osvi, sizeof(OSVERSIONINFO) );
+    osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
+    GetVersionEx( &osvi );
+
+    fwprintf( fd, L"[version]\nOS=%d.%d.%d.%d.%s\nVLC=" VERSION_MESSAGE, osvi.dwMajorVersion,
+                                                           osvi.dwMinorVersion,
+                                                           osvi.dwBuildNumber,
+                                                           osvi.dwPlatformId,
+                                                           osvi.szCSDVersion);
+
+    const CONTEXT *const pContext = (const CONTEXT *)lpExceptionInfo->ContextRecord;
+    const EXCEPTION_RECORD *const pException = (const EXCEPTION_RECORD *)lpExceptionInfo->ExceptionRecord;
+    /*No nested exceptions for now*/
+    fwprintf( fd, L"\n\n[exceptions]\n%08x at %08x",pException->ExceptionCode,
+                                            pException->ExceptionAddress );
+    if( pException->NumberParameters > 0 )
+    {
+        unsigned int i;
+        for( i = 0; i < pException->NumberParameters; i++ )
+            fprintf( fd, " | %08x", pException->ExceptionInformation[i] );
+    }
+
+    fwprintf( fd, L"\n\n[context]\nEDI:%08x\nESI:%08x\n" \
+                "EBX:%08x\nEDX:%08x\nECX:%08x\nEAX:%08x\n" \
+                "EBP:%08x\nEIP:%08x\nESP:%08x\n",
+                    pContext->Edi,pContext->Esi,pContext->Ebx,
+                    pContext->Edx,pContext->Ecx,pContext->Eax,
+                    pContext->Ebp,pContext->Eip,pContext->Esp );
+
+    fwprintf( fd, L"\n[stacktrace]\n#EIP|base|module\n" );
+
+    wchar_t module[ 256 ];
+       MEMORY_BASIC_INFORMATION mbi ;
+       VirtualQuery( (DWORD *)pContext->Eip, &mbi, sizeof( mbi ) ) ;
+       HINSTANCE hInstance = mbi.AllocationBase;
+       GetModuleFileName( hInstance, module, 256 ) ;
+       fwprintf( fd, L"%08x|%s\n", pContext->Eip, module );
+
+       DWORD pEbp = pContext->Ebp;
+    DWORD caller = *((DWORD*)pEbp + 1);
+
+    do
+    {
+        VirtualQuery( (DWORD *)caller, &mbi, sizeof( mbi ) ) ;
+        HINSTANCE hInstance = mbi.AllocationBase;
+        GetModuleFileName( hInstance, module, 256 ) ;
+        fwprintf( fd, L"%08x|%s\n", caller, module );
+        pEbp = *(DWORD*)pEbp ;
+        caller = *((DWORD*)pEbp + 1) ;
+        /*The last EBP points to NULL!*/
+    }while(caller);
+
+    fclose( fd );
+    fflush( stderr );
+    exit( 1 );
+}
+#endif