Click here to Skip to main content
Click here to Skip to main content

Catch All Bugs with BugTrap!

By , 31 Jan 2009
Rate this:
Please Sign up or sign in to vote.

What's new in this version?

  • 64 bit support - now BugTrap natively supports Win64
  • Multi-monitor support - BugTrap may capture screenshots from several monitors
  • Other enhancements - Tons of features/options added since last update. See app history for details

Introduction

Some time ago, I was working on a multi-tier application with quite complex logic. The application was handling medical information, and it was important to correctly synchronize data under all circumstances. I put extra code to make the application as stable as possible, and added automatic backups and self-recovery. Do you think it solved all problems?

No, I was still searching for a tool to handle problems, seen by customers, remotely. How could I assist them and debug the problem if I lived on the other side of the globe? Eventually, I found this excellent Jim Crafton article about a tool capable of intercepting unhandled errors. That was a solution!

Unfortunately, the original black-box was not customizable, it didn't support mini-dump files or Unicode strings, and it didn't have any server. In spite of these limitations, it was an excellent starting point because I knew exactly what kind of a tool I wanted. I started working on my own tool in the hope of making it flexible and customizable, and a powerful solution.

Overview

Usually, it's very frustrating to receive a message from your customer saying that your program doesn't work. Most users may not let you know what's incorrect in your application and which piece of code went wrong. Windows has a built-in handler for unhandled errors, however, this default handler might be useless when errors happen on the customer side, because you rarely want to send your error report to Microsoft:

Default Win32/64 error handler

BugTrap solves this problem by overriding the default error handler. BugTrap gathers error details such as address, call stack, and the computer environment. It's also possible to add an arbitrary number of custom log files, with additional information on the default error report, using built-in or external logging functions.

BugTrap may save error reports on the disk, or automatically deliver error reports to the developer's computer by e-mail, over HTTP, or through a fast low-level TCP-based network protocol. The BugTrap server automatically manages the error reports repository, and notifies developers about any new errors.

Network diagram

BugTrap stores error descriptions in log and mini-dump files. Mini-dump files may be opened in Microsoft Visual Studio .NET and in WinDbg. The BugTrap package also includes a CrashExplorer utility that can extract symbolic information from MAP and PDB files. There is a special BugTrap version for .NET applications (currently under development).

Simplified dialog

Dialog with error details

Preview dialog

All details are available in the BugTrap documentation. The documentation is also included as part of the Setup. If you like to know how BugTrap works, you may read these articles:

Adding BugTrap support to Win32/64 applications

BugTrap is redistributed as a dynamic-link library (DLL). Two versions of the BugTrap DLL are available: the ANSI version, and the Unicode version.

DLL name Character encoding
BugTrap.dll ANSI multi-byte character strings
BugTrapU.dll Unicode strings

The code below adds BugTrap support to Win32/64 applications:

#include "BugTrap.h"

#pragma comment(lib, "BugTrap.lib")      // Link to ANSI DLL
// #pragma comment(lib, "BugTrapU.lib")  // Link to Unicode DLL

static void SetupExceptionHandler()
{
    BT_SetAppName(_T("Your application name"));
    BT_SetSupportEMail(_T("your@email.com"));
    BT_SetFlags(BTF_DETAILEDMODE | BTF_EDIETMAIL);
    BT_SetSupportServer(_T("localhost"), 9999);
    BT_SetSupportURL(_T("http://www.your-web-site.com"));
}

The SetupExceptionHandler() function may be called from InitInstance() or main(), depending on the type of your application.

When your application experiences a problem, the user is prompted by BugTrap to submit an error report to the BugTrap server. The error report includes many details of the user environment. The report also includes a complete stack trace for the call that caused a problem.

With BugTrap, you can debug the problem using two different approaches.

1. You can open post-mortem mini-dump files in Visual Studio:

Minidump file in Visual Studio

2. You can use the built-in utility CrashExplorer:

When BugTrap is building stack traces, it searches for the PDB file – a file that holds debugging information. If this file is available, BugTrap is able to show function names and line numbers next to each address. Obviously, the PDB file makes the stack trace much nicer, but most developers prefer not to distribute PDB files to end users because PDB files could simplify program reverse engineering.

Therefore, BugTrap doesn't require PDB files on user computers. Instead, it saves raw function addresses to the log:

Dialog with no source information

So, the end user doesn't have any clue what's behind these hexadecimal numbers.

CrashExplorer reverts back all functions names and line numbers based on the PDB/MAP file and addresses in a log:

CrashExplorer restores function names and lines numbers from MAP or PDB file

Adding BugTrap Support to .NET Applications

.NET version of BugTrap is redistributed as managed library: BugTrapN.dll. This DLL consists of managed and unmanaged code. Such design lets BugTrap support pure managed .NET assemblies as well as mixed C++ assemblies that could throw managed .NET exceptions and native Win32/64 exceptions.

BugTrap for .NET exposes both managed and unmanaged (native) interfaces. Managed interface is accessible from C# or VB.NET code:

ExceptionHandler.AppName = "Your application name";
ExceptionHandler.Flags = FlagsType.DetailedMode | FlagsType.EditMail;
ExceptionHandler.DumpType = MinidumpType.NoDump;
ExceptionHandler.SupportEMail = "your@email.com";
ExceptionHandler.SupportURL = "http://www.your-web-site.com";
ExceptionHandler.SupportHost = "localhost";
ExceptionHandler.SupportPort = 9999;

Unmanaged interface is accessible from native Win32/64 code and was discussed earlier. It is possible to use any interface or even both interfaces in the same application.

Updates

I periodically fix errors and add new features. This frequency of such updates depends on your feedback. You may check http://www.intellesoft.net/downloads.php for the most recent updates. All major updates are submitted to The Code Project.

Building Notes

Most developers may go ahead and download the Setup - it installs all necessary files and components. However, some professionals enjoy building all components from scratch. Those developers may download BugTrap source code from here.

I have been trying to make BugTrap DLL as compact as possible. Therefore BugTrap DLL does not use MFC/ATL/WTL. I have been using pure C and C++. In particular, you will find several classes from my own library: collection classes, IO streams, built-in XML parser, etc. BugTrap DLL depends on zlib. I have included it in the archive to simplify building.

CrashExplorer depends on STL, Boost and WTL. Both libraries must be pre-installed on your computer.

Thank you!

I appreciate support, help, contributions, and even simple feedback that I am getting from many of you. BugTrap could not be in a position to meet the demands of modern software without this.

That's it! Happy bug-trapping Wink | ;-)

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

Maksim Pyatkovskiy

United States United States
No Biography provided

Comments and Discussions

 
AnswerRe: Link for source code still broken? PinmemberMike Diack5-Jun-12 22:28 
GeneralRe: Link for source code still broken? PinmemberMember 89721436-Jun-12 17:21 
QuestionWhere can I get the Sourcecode? PinmemberDomiOh27-Apr-12 14:25 
AnswerRe: Where can I get the Sourcecode? PinmemberMike Diack16-May-12 5:05 
GeneralRe: Where can I get the Sourcecode? PinmemberDomiOh31-May-12 7:57 
GeneralRe: Where can I get the Sourcecode? PinmemberMike Diack31-May-12 8:42 
QuestionSupport for dynamic loading of BugTrap Pinmemberemwtur20-Mar-12 10:52 
QuestionVS2010 Support? PinmemberJonTampa7-Nov-11 12:18 
It seems much has changed on the inside of .vsproj between VS2008 and VS2010. Has anyone converted or found a BugTrap VS2010 .sln?
QuestionThe application stop working after showing the error message. Pinmembergaferrero29-Sep-11 3:38 
QuestionTrapping runtime errors and RT security checks with BugTrap Pinmembervolker bijewitz27-Sep-11 20:12 
QuestionBugTrap for .NET 4.0? Pinmembersub-star19-Sep-11 1:48 
AnswerRe: BugTrap for .NET 4.0? Pinmembersub-star21-Sep-11 4:46 
QuestionAnyone tried to use this lately? Pinmembercharlieg14-Aug-11 15:47 
AnswerRe: Anyone tried to use this lately? PinmemberMike Diack30-Aug-11 22:33 
Question.net Pinmemberalhambra-eidos26-Jul-11 10:40 
AnswerRe: .net PinmemberMike Diack30-Aug-11 22:34 
Bugemail error: can't send error report to the server -- fix [modified] PinmemberOleg Shirokii25-Jul-11 1:05 
GeneralErrorlog stacktrace Pinmembernguyenwu730-Mar-11 23:29 
GeneralRe: Errorlog stacktrace PinmemberMike Diack30-Aug-11 22:35 
GeneralThank you Pinmembernthnhung9-Feb-11 10:33 
GeneralWhere can I get the source code for BugTrapN - BadImageFormatException from test application using prebuilt dll. Pinmemberbencbr2-Dec-10 5:20 
GeneralRe: Where can I get the source code for BugTrapN - BadImageFormatException from test application using prebuilt dll. PinmemberMike Diack5-Jan-11 23:01 
GeneralUse in mixed (managed/native apps) and callstacks Pinmemberbencbr2-Dec-10 5:18 
QuestionAny CPU support? PinmemberClutchplate5-Oct-10 7:17 
AnswerRe: Any CPU support? PinmemberMike Diack2-Nov-10 3:23 
AnswerRe: Any CPU support? Pinmemberemwtur20-Mar-12 10:49 
GeneralDon't close application on ExceptionHandler.HandleException(e); PinmemberkawfeeEsim23-Jul-10 5:54 
GeneralRe: Don't close application on ExceptionHandler.HandleException(e); PinmemberMike Diack17-Aug-10 0:24 
GeneralHELP: Windows 7's error reporting (WER) getting in the way. PinmemberMike Diack5-Jul-10 23:59 
GeneralRe: HELP: Windows 7's error reporting (WER) getting in the way. PinmemberMike Diack8-Dec-11 0:49 
QuestionSource code Pinmemberkris24037610-Jun-10 7:04 
AnswerRe: Source code PinmemberMaksim Pyatkovskiy10-Jun-10 8:02 
GeneralCrash Explorer Crash PinmemberMember 134478827-May-10 0:01 
GeneralRe: Crash Explorer Crash PinmemberMike Diack1-Jun-10 2:38 
GeneralRe: Crash Explorer Crash PinmemberMember 13447881-Jul-10 23:26 
GeneralBugTrap .NET on Windows Server 2003 Pinmemberarif.setiawan9-Apr-10 2:07 
QuestionHas anybody been able to build from the sources? PinmemberMember 13447883-Mar-10 1:13 
AnswerRe: Has anybody been able to build from the sources? PinmemberMaksim Pyatkovskiy7-Mar-10 19:12 
QuestionIdeas for future changes/improvements? PinmemberMike Diack1-Mar-10 0:21 
AnswerRe: Ideas for future changes/improvements? PinmemberTBFowler41-Mar-10 7:16 
GeneralRe: Ideas for future changes/improvements? PinmemberMaksim Pyatkovskiy1-Mar-10 8:45 
GeneralRe: Ideas for future changes/improvements? PinmemberMike Diack12-Mar-10 0:02 
AnswerRe: Ideas for future changes/improvements? PinmemberSpaun21-Apr-10 21:31 
GeneralRe: Ideas for future changes/improvements? PinmemberMike Diack22-Apr-10 21:45 
GeneralRe: Ideas for future changes/improvements? PinmemberSpaun4-May-10 22:08 
GeneralA message from the author PinmemberMaksim Pyatkovskiy30-Jan-10 19:04 
NewsRe: A message from the author PinmemberTBFowler425-Feb-10 6:35 
GeneralRe: A message from the author PinmemberDave Brotherstone25-Feb-10 7:10 
GeneralRe: A message from the author PinmemberMaksim Pyatkovskiy27-Feb-10 19:56 
GeneralRe: A message from the author Pinmemberjoleg7427-Feb-10 17:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 31 Jan 2009
Article Copyright 2006 by Maksim Pyatkovskiy
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid