[vlc-devel] [RFC PATCH 6/7] win32: Use breakpad for error reporting

Hugo Beauzée-Luyssen hugo at beauzee.fr
Wed Dec 20 11:34:40 CET 2017


---
 bin/Makefile.am |  4 +++
 bin/winvlc.cpp  | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/bin/Makefile.am b/bin/Makefile.am
index 26cfea507e..a8c519ba6b 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -33,6 +33,10 @@ vlc_SOURCES = winvlc.cpp
 vlc_DEPENDENCIES = vlc_win32_rc.$(OBJEXT)
 vlc_LDFLAGS = -mwindows
 vlc_LDADD += vlc_win32_rc.$(OBJEXT)
+if HAVE_BREAKPAD
+vlc_LDADD += $(BREAKPAD_LIBS) -lwininet
+vlc_CPPFLAGS = $(BREAKPAD_CFLAGS) -DHAVE_BREAKPAD -DBREAKPAD_URL=\"@BREAKPAD_URL@\"
+endif
 endif
 
 vlc_osx_SOURCES = darwinvlc.m
diff --git a/bin/winvlc.cpp b/bin/winvlc.cpp
index f35c854cb2..b4228ea25b 100644
--- a/bin/winvlc.cpp
+++ b/bin/winvlc.cpp
@@ -35,6 +35,13 @@
 #include <vlc/vlc.h>
 #include <windows.h>
 #include <shellapi.h>
+#ifdef HAVE_BREAKPAD
+# include "client/windows/handler/exception_handler.h"
+# include "common/windows/http_upload.h"
+# include <memory>
+# include <map>
+# include <string>
+#endif
 
 #ifndef _WIN32_IE
 #  define  _WIN32_IE 0x501
@@ -43,7 +50,6 @@
 #include <io.h>
 #include <shlobj.h>
 #define HeapEnableTerminationOnCorruption (HEAP_INFORMATION_CLASS)1
-static const wchar_t *crashdump_path;
 
 static char *FromWide (const wchar_t *wide)
 {
@@ -109,6 +115,59 @@ static void PrioritizeSystem32(void)
                                 &m, sizeof( m ) );
 }
 
+#ifdef HAVE_BREAKPAD
+static bool FilterCallback(void*, EXCEPTION_POINTERS*, MDRawAssertionInfo*)
+{
+    // Don't spam breakpad if we're debugging
+    return !IsDebuggerPresent();
+}
+
+static void check_crashdump( const wchar_t* path )
+{
+    wchar_t pattern[MAX_PATH];
+    WIN32_FIND_DATA data;
+    _snwprintf( pattern, MAX_PATH, L"%s/*.dmp", path );
+    HANDLE h = FindFirstFile( pattern, &data );
+    if (h == INVALID_HANDLE_VALUE)
+        return;
+    int answer = MessageBox( NULL, L"Ooops: VLC media player just crashed.\n" \
+        "Would you like to send a bug report to the developers team?",
+        L"VLC crash reporting", MB_YESNO);
+    std::map<std::wstring, std::wstring> params;
+//    wchar_t ptimeStr[32];
+//    FILETIME creationTime, exitTime, kernelTime, userTime;
+//    uint64_t nbMs = 0;
+//    if ( GetProcessTimes( GetCurrentProcess(), &creationTime, &exitTime, &kernelTime,
+//                     &userTime ) )
+//    {
+//        ULARGE_INTEGER u;
+//        u.LowPart = creationTime.dwLowDateTime;
+//        u.HighPart = creationTime.dwHighDateTime;
+//        nbMs = u.QuadPart / 10000000;
+//    }
+//    _snwprintf( ptimeStr, sizeof(ptimeStr), L"%" PRId64, nbMs );
+    params[L"prod"] = L"VLC";
+    params[L"ver"] = TEXT(PACKAGE_VERSION);
+//    params[L"ptime"] = ptimeStr;
+    do
+    {
+        wchar_t fullPath[MAX_PATH];
+        _snwprintf( fullPath, MAX_PATH, L"%s/%s", path, data.cFileName );
+        if( answer == IDYES )
+        {
+            std::map<std::wstring, std::wstring> files;
+            files[L"upload_file_minidump"] = fullPath;
+            google_breakpad::HTTPUpload::SendRequest(
+                            TEXT( BREAKPAD_URL "/reports" ), params, files,
+                            NULL, NULL, NULL );
+        }
+        DeleteFile( fullPath );
+    } while ( FindNextFile( h, &data ) );
+    FindClose(h);
+}
+
+#endif
+
 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                     LPSTR lpCmdLine,
                     int nCmdShow )
@@ -195,6 +254,10 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
     argv[argc] = NULL;
     LocalFree (wargv);
 
+#ifdef HAVE_BREAKPAD
+    using google_breakpad::ExceptionHandler;
+    std::unique_ptr<ExceptionHandler> exceptionHandler;
+
     if(crash_handling)
     {
         static wchar_t path[MAX_PATH];
@@ -202,8 +265,16 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                     NULL, SHGFP_TYPE_CURRENT, path ) )
             fprintf( stderr, "Can't open the vlc conf PATH\n" );
         _snwprintf( path+wcslen( path ), MAX_PATH,  L"%s", L"\\vlc\\crashdump" );
-        crashdump_path = &path[0];
+        const wchar_t* crashdump_path = &path[0];
+
+        check_crashdump( crashdump_path );
+        // Breakpad needs the folder to exist to generate the crashdump
+        CreateDirectory( crashdump_path, NULL );
+        exceptionHandler.reset( new ExceptionHandler( crashdump_path,
+                                FilterCallback, NULL, NULL,
+                                ExceptionHandler::HANDLER_ALL) );
     }
+#endif
 
     _setmode( _fileno( stdin ), _O_BINARY ); /* Needed for pipes */
 
-- 
2.11.0



More information about the vlc-devel mailing list