![]() |
Development Lifecycle »
Debug Tips »
General
Intermediate
License: The Code Project Open License (CPOL)
XCrashReport : Exception Handling and Crash Reporting - Part 4By Hans DietrichAdd basic exception handling and crash reporting to your application |
VC6Win2K, WinXP, Win2003, MFC, Dev, QA
|
|
Advanced Search |
|
|
|
||||||||||||||||
with one that prompts you to email the crash files to the software vendor. The really brilliant thing about Carruth's approach is that it allows the customer to review in detail what is being sent, and to choose what files are sent.
Problem #1: It uses WTL. Not a big deal, but it is one more thing to configure and deal with, and I am very reluctant to tweak some of the older MFC apps I maintain.
Problem #2: The replacement crash dialog runs in the same process as the crashed app. This is a big concern, because you really want to do as little as possible in the exception handler, and GUI dialogs cross the line.
Problem #3: It uses zlib.dll to zip the crash files. This is one more file to add to the installation, and I get twitchy when I think about dealing with that.
Problem #4: There is extra stuff in the implementation that was not essential for me. For example, output of the crash info to XML using Microsoft's MSXML. While I think this is a very interesting use of XML, I wanted to keep the exception handler (and the code it pulls in) to a very small footprint.
Running as a separate app was no problem. Since the exception handler was doing all the work of creating the crash files, all the new crash dialog app had to do was to find them, zip them, and email the zip. To make the crash dialog app (I am calling it XCrashReport from now on) as independent as possible, the last thing the exception handler does is to invoke XCrashReport with the name of the crashed app on the command line. By default, I decided that the crashed app, the crash files, and XCrashReport must all reside in the same directory. This design decision could easily be changed, but so far it seems to work well for my needs.
Next came the MFC stuff. I knew there would be two dialogs - the main window, and then a dialog that showed the details of the files being sent, and allowed the user to select which ones to send. For the last, I saw that my XListCtrl would be perfect, using checkboxes to allow selection. I could also use my new XHyperLink and XColorStatic controls. And I could use my XZip code to zip up the crash files.
I would like to thank Grant McDorman for his enhancements to Mike Carruth's code, which you can find here. In particular, McDorman added the ability to dump a section of the registry to a text file, which can then be added to the error report.
The user can then click on the click here link to review the contents of the error report before it is sent. This shows the ERRORLOG.TXT file being displayed:
This shows the CRASH.DMP file being displayed:
This shows the REGISTRY.TXT file being displayed:
RecordExceptionInfo() function in ExceptionHandler.cpp, there is code that will detect whether the app is running under a debugger, and dismiss the exception accordingly:
EXCEPTION_CONTINUE_SEARCH. This tells Win32 that this handler didn't actually handle the exception, so that things will proceed as per normal, and the debugger will catch the exception. EXCEPTION_EXECUTE_HANDLER, which suppresses the standard crash dialog. If not successful, the handler returns EXCEPTION_CONTINUE_SEARCH, which again lets things proceed as per normal (the standard crash dialog will pop up). #define XCRASHREPORT_MINI_DUMP_FILE _T("CRASH.DMP") #define XCRASHREPORT_ERROR_LOG_FILE _T("ERRORLOG.TXT") #define XCRASHREPORT_REGISTRY_DUMP_FILE _T("REGISTRY.TXT") #define XCRASHREPORT_CRASH_REPORT_APP _T("XCrashReport.exe")
#define XCRASHREPORT_SEND_TO_NAME _T("Software Support") #define XCRASHREPORT_SEND_TO_ADDRESS _T("support@softwarevendor.com")
#define INI_FILE_NAME _T("XCrashReport.ini") #define INI_FILE_SECTION _T("FilesToAdd") #define INI_FILE_TEMPLATE _T("File%03d") #define INI_REG_SECTION _T("RegistryToAdd") #define INI_REG_TEMPLATE _T("Registry%03d") #define MAX_INI_ITEMS 999
#define XCRASHREPORT_DUMP_REGISTRY #define XCRASHREPORT_REGISTRY_KEY \ _T("HKCU\\Software\\CodeProject\\XCrashReportTest")
[RegistryToAdd]
;Registry001=HKCU\Software\CodeProject\XCrashReportTest,Main reg key
;Registry002=HKCU\Software\CodeProject\XCrashReportTest\Program,new reg key
[FilesToAdd]
;File001=CRASH.DMP,Crash Dump,DMP File
;File002=ERRORLOG.TXT,Crash log,Text Document
The download also includes the latest dbghelp.lib and dbghelp.h.
XCRASHREPORT_REGISTRY_KEY) is not included - you must add it to the XCrashReport.ini file if you want to include it. On the target system, the XCrashReport.ini file must be placed in the exe directory.
Here is an example XCrashReport.ini file:
;
; sample XCrashReport.ini file
;
[FilesToAdd]
File001=CRASH.DMP,Crash Dump,DMP File
File002=ERRORLOG.TXT,Crash log,Text Document
File003=BozoSoft.db,Database File,DB File
[RegistryToAdd]
Registry001=HKCU\Software\BozoSoft\BozoApp1,Main reg key
Registry002=HKCU\Software\BozoSoft\BozoApp2\Program,another reg key
There is no limit on the size of the file that may be added, although internally only the first 64 KB of the file will be displayed on the Error Report Contents dialog. ExceptionHandler.cpp(823) : fatal error C1010: unexpected end of file while looking for precompiled header directive. How can I fix this?
#define XCRASHREPORT_DUMP_REGISTRY
This file is included in the XCrashReport.exe project. #define XCRASHREPORT_WRITE_MINIDUMP
This file is one of the files that you include in your app's project. // CrashFileNames.h Version 1.0 // // Author: Hans Dietrich // hdietrich2@hotmail.com // // This software is released into the public domain. // You are free to use it in any way you like, except // that you may not sell this source code. // // This software is provided "as is" with no expressed // or implied warranty. I accept no liability for any // damage or loss of business that this software may cause. // ///////////////////////////////////////////////////////////////////// #ifndef CRASHFILENAMES_H #define CRASHFILENAMES_H #define XCRASHREPORT_MINI_DUMP_FILE _T("CRASH.DMP") #define XCRASHREPORT_ERROR_LOG_FILE _T("ERRORLOG.TXT") #define XCRASHREPORT_REGISTRY_DUMP_FILE _T("REGISTRY.TXT") #define XCRASHREPORT_CRASH_REPORT_APP _T("XCrashReport.exe") #endif //CRASHFILENAMES_HThis file is one of the files that you include in your app's project, and it is also used in XCrashReport.exe. Both will need to be recompiled.
// RegistryDefines.h Version 1.0 // // Author: Hans Dietrich // hdietrich2@hotmail.com // // This software is released into the public domain. // You are free to use it in any way you like, except // that you may not sell this source code. // // This software is provided "as is" with no expressed // or implied warranty. I accept no liability for any // damage or loss of business that this software may cause. // ////////////////////////////////////////////////////////////////////// #ifndef REGISTRYDEFINES_H #define REGISTRYDEFINES_H #define XCRASHREPORT_DUMP_REGISTRY #define XCRASHREPORT_REGISTRY_KEY \ _T("HKCU\\Software\\CodeProject\\XCrashReportTest") #endif //REGISTRYDEFINES_HThis file is used in XCrashReport.exe.
This software is released into the public domain. You are free to use it in any way you like, except that you may not sell this source code. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 19 Oct 2003 Editor: Sean Ewington |
Copyright 2003 by Hans Dietrich Everything else Copyright © CodeProject, 1999-2009 Web10 | Advertise on the Code Project |