[vlc-devel] [PATCH]Win32: Generate stacktrace on unhandled exception
Geoffroy Couprie
geo.couprie at gmail.com
Thu Jan 29 22:40:15 CET 2009
Hello,
This patch adds the capacity to generate crashdumps on unhandled
exception, to catch errors like segfaults, divide by zero. I may add
some informations like vlc version. If this patch is applied, I'll add
some window to query the user for information on what was played, to
ask an e-mail, and ask if the user wants to send information. I'll
make a script to parse these files, like the one for Mac crashdumps.
Currently, the crashdump looks like that:
[Version]
6.0.6001.2.Service Pack 1
[Exceptions]
c0000005 at 6d7851ad
[CONTEXT]
EDI:00000000
ESI:00000000
EBX:05c2afd8
EDX:05c2afd8n
ECX:05d11e70
EAX:000c1530
EBP:0b29fe38
EIP:6d7851ad
ESP:0b29fc30
[STACKTRACE]
#EIP|base|module
6d784639|6d780000|c:\Users\geo\Documents\dev\vlc\win32\vlc-1.0.0-git\plugins\libdirect3d_plugin.dll
6a5b5ac3|6a540000|c:\Users\geo\Documents\dev\vlc\win32\vlc-1.0.0-git\libvlccore.dll
6a5b5711|6a540000|c:\Users\geo\Documents\dev\vlc\win32\vlc-1.0.0-git\libvlccore.dll
76282cce|76270000|C:\Windows\system32\msvcrt.dll
76282deb|76270000|C:\Windows\system32\msvcrt.dll
76364911|76320000|C:\Windows\system32\kernel32.dll
77a0e4b6|779d0000|C:\Windows\system32\ntdll.dll
77a0e489|779d0000|C:\Windows\system32\ntdll.dll
Comments welcomed :)
Regards,
Geoffroy
-------------- next part --------------
From 0ae416aabfed35ad64f08599a55bd91ac5e5980a Mon Sep 17 00:00:00 2001
From: Geoffroy Couprie <geo.couprie at gmail.com>
Date: Thu, 29 Jan 2009 22:29:54 +0100
Subject: [PATCH] Win32: Generate stacktrace on unhandled exception
---
src/misc/win32_specific.c | 89 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 88 insertions(+), 1 deletions(-)
diff --git a/src/misc/win32_specific.c b/src/misc/win32_specific.c
index a596502..ff0658a 100644
--- a/src/misc/win32_specific.c
+++ b/src/misc/win32_specific.c
@@ -37,7 +37,13 @@
#if !defined( UNDER_CE )
# include <io.h>
# include <fcntl.h>
-# include <mmsystem.h>
+# include <mmsystem.h>
+#if defined ( NDEBUG )
+# define _WIN32_IE 0x500
+# include <shlobj.h>
+# include <tlhelp32.h>
+LONG WINAPI vlc_exception_filter(struct _EXCEPTION_POINTERS *lpExceptionInfo);
+#endif
#endif
#include <winsock.h>
@@ -89,6 +95,10 @@ void system_Init( libvlc_int_t *p_this, int *pi_argc, const char *ppsz_argv[] )
/* Call mdate() once to make sure it is initialized properly */
mdate();
+#if !defined( UNDER_CE ) && defined ( NDEBUG )
+ SetUnhandledExceptionFilter(vlc_exception_filter);
+#endif
+
/* WinSock Library Init. */
if( !WSAStartup( MAKEWORD( 2, 2 ), &Data ) )
{
@@ -396,3 +406,80 @@ void system_End( libvlc_int_t *p_this )
WSACleanup();
}
+
+#if !defined( UNDER_CE ) && defined ( NDEBUG )
+/*****************************************************************************
+ * vlc_exception_filter: handles unhandled exceptions, like segfaults
+ *****************************************************************************/
+LONG WINAPI vlc_exception_filter(struct _EXCEPTION_POINTERS *lpExceptionInfo)
+{
+ wchar_t wdir[MAX_PATH];
+
+ fprintf( stderr, "unhandled vlc exception\n" );
+
+ 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" );
+
+ FILE * fd = _wfopen ( wdir, L"w, ccs=UTF-8" );
+
+ if( !fd )
+ fprintf( stderr, "\nerror while opening file" );
+
+ OSVERSIONINFO osvi;
+ ZeroMemory( &osvi, sizeof(OSVERSIONINFO) );
+ osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
+ GetVersionEx( &osvi );
+
+ fwprintf( fd, L"[Version]\n%d.%d.%d.%d.%s", 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:%08xn\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\n[STACKTRACE]\n#EIP|base|module\n" );
+
+ DWORD pEbp = pContext->Ebp;
+ DWORD caller = *((DWORD*)pEbp + 1) ;
+
+ wchar_t module[ 256 ];
+
+ do
+ {
+ MEMORY_BASIC_INFORMATION mbi ;
+ VirtualQuery( (DWORD *)caller, &mbi, sizeof( mbi ) ) ;
+ HINSTANCE hInstance = mbi.AllocationBase;
+ GetModuleFileName( hInstance, module, 256 ) ;
+ fwprintf( fd, L"%08x|%08x|%s\n", caller, hInstance, module );
+ pEbp = *(DWORD*)pEbp ;
+ caller = *((DWORD*)pEbp + 1) ;
+ /*The last EBP points to NULL!*/
+ }while(caller);
+
+ fclose( fd );
+ fflush( stderr );
+ exit( 1 );
+}
+#endif
--
1.6.0.4
More information about the vlc-devel
mailing list