Click here to Skip to main content
15,887,683 members
Articles / Web Development / HTML

Catch All Bugs with BugTrap!

Rate me:
Please Sign up or sign in to vote.
4.34/5 (84 votes)
31 Jan 2009MIT5 min read 1.8M   9.1K   293   485
A tool that can catch unhandled errors and exceptions, and deliver error reports to remote support servers

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:

C++
#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:

C++
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 https://github.com/bchavez/BugTrap 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 ;-)

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Full Automation Pin
Maksim Pyatkovskiy25-Jul-06 5:46
Maksim Pyatkovskiy25-Jul-06 5:46 
GeneralA feature suggestion: an automated registry export Pin
Ray Duku24-Jul-06 3:32
Ray Duku24-Jul-06 3:32 
GeneralRe: A feature suggestion: an automated registry export Pin
Maksim Pyatkovskiy24-Jul-06 4:10
Maksim Pyatkovskiy24-Jul-06 4:10 
GeneralRe: A feature suggestion: an automated registry export Pin
Simon Brown24-Jul-06 21:39
Simon Brown24-Jul-06 21:39 
GeneralRe: A feature suggestion: an automated registry export Pin
Maksim Pyatkovskiy25-Jul-06 5:37
Maksim Pyatkovskiy25-Jul-06 5:37 
GeneralRe: A feature suggestion: an automated registry export Pin
Ray Duku25-Jul-06 22:51
Ray Duku25-Jul-06 22:51 
GeneralMany Thanks Indeed [modified] Pin
Simon Brown23-Jul-06 23:36
Simon Brown23-Jul-06 23:36 
GeneralRe: Many Thanks Indeed Pin
Maksim Pyatkovskiy24-Jul-06 5:34
Maksim Pyatkovskiy24-Jul-06 5:34 
I can't get Mail To... enabled, Submit always works though. Here's my code

This is an expected feature Wink | ;)

Submit button behaves differently. If you have setup a BugTrap server, then Submit button would prefer that way and it would send all reports to the server (over HTTP or TCP).
If you also want to receive reports in e-mail attachments, BugTrap will display an additional link "mail to..." in the simplified dialog. In advanced dialog this would enable "Mail To..." button.

If you only want to receive all reports over e-mail and you have not setup BugTrap server (BT_SetSupportServer() was not called), BugTrap only uses e-mail transport, hides "mail to..." link in the simplified dialog, disables "Mail To..." button in advanced UI and Submit button sends reports in e-mail attachments.

This is done primarily to do not confuse users. User should not be too concerned about details of the selected transport. User should simply hit Submit button and don't think about the rest.

I would pay for a solution like this which includes source for use in my commerical life. I use Codejock a lot and paid for that.

I must think about NDA. I also want to make sure that others might be inetrested in this.
If you only want to see the source code to make sure that there is no adware, trojans, viruses or back doors, I would say that you could waste your money because BugTrap doesn't have any of these abominations. In either case, let's see if anyone else will be interested in this and let's see how large will be BugTrap user base. In this case it could grow to the true platform.

P.S.

1. I do not recommend to send reports over e-mail. Additionally to all problems with ISPs, this method is less reliable than TCP/HTTP because it uses MAPI implementation of e-mail client installed on user computers. You never know what e-mail client is installed and you never know how poor is MAPI implementation in that client. While it perfectly works with Outlook and Outlook Express, I know that the latest version of The Bat! has a bug and it ignores sender address (the previous version of The Bat! worked fine). Additionally to inconsistencies in MAPI implementation, some e-mail clients (for example Outlook and Outlook Express) would warn user about BugTrap attempting to send an e-mail on behalf of the user. If you cannot setup IIS and BugTrap Web Server, why don't you want to open one port in your firewall and setup BugTrap Server? Personally I use exactly this configuration on my computer because BugTrap server runs faster and consumes fewer resources than anything else. Even if you don't have dedicated IP address, you can use such inexpensive services as http://www.no-ip.com, setup a domain name, and specify it instead of the IP address. BugTrap Server is secure - it won't let your users to upload anything they want to your computer if it is correctly configured. I only recommend to use the most recent update of BugTrap Server (http://www.intelle-soft.com/downloads.shtml) because it requires fewer memory than the previous versions. There is no any sense in sending reports over e-mail.

2. I also don't recommend to use BTF_LISTPROCESSES flag unless you really want to dump all running processes. This flag reduces the speed of log generation. Simply try to disable this option and you will notice a big difference in the speed.
GeneralRe: Many Thanks Indeed Pin
Simon Brown24-Jul-06 6:59
Simon Brown24-Jul-06 6:59 
GeneralRe: Many Thanks Indeed Pin
Simon Brown24-Jul-06 21:47
Simon Brown24-Jul-06 21:47 
QuestionThanks for the great work! Pin
Alexey Krasnoperov21-Jul-06 15:42
Alexey Krasnoperov21-Jul-06 15:42 
GeneralProblems: standard system dialog is shown istead of BugTrap Pin
Alex Sosnov19-Jul-06 7:24
Alex Sosnov19-Jul-06 7:24 
GeneralRe: Problems: standard system dialog is shown istead of BugTrap Pin
Maksim Pyatkovskiy19-Jul-06 10:39
Maksim Pyatkovskiy19-Jul-06 10:39 
GeneralRe: Problems: standard system dialog is shown istead of BugTrap [modified] Pin
Alex Sosnov19-Jul-06 12:26
Alex Sosnov19-Jul-06 12:26 
GeneralRe: Problems: standard system dialog is shown istead of BugTrap Pin
Maksim Pyatkovskiy19-Jul-06 12:47
Maksim Pyatkovskiy19-Jul-06 12:47 
GeneralRe: Problems: standard system dialog is shown istead of BugTrap [modified] Pin
Alex Sosnov21-Jul-06 6:51
Alex Sosnov21-Jul-06 6:51 
GeneralRe: Problems: standard system dialog is shown istead of BugTrap Pin
Maksim Pyatkovskiy21-Jul-06 9:25
Maksim Pyatkovskiy21-Jul-06 9:25 
GeneralRe: Problems: standard system dialog is shown istead of BugTrap [modified] Pin
Simon Brown24-Jul-06 6:48
Simon Brown24-Jul-06 6:48 
GeneralRe: Problems: standard system dialog is shown istead of BugTrap Pin
Maksim Pyatkovskiy24-Jul-06 6:57
Maksim Pyatkovskiy24-Jul-06 6:57 
GeneralRe: Problems: standard system dialog is shown istead of BugTrap Pin
Simon Brown24-Jul-06 7:00
Simon Brown24-Jul-06 7:00 
GeneralRe: Problems: standard system dialog is shown istead of BugTrap Pin
Maksim Pyatkovskiy24-Jul-06 12:37
Maksim Pyatkovskiy24-Jul-06 12:37 
GeneralRe: Problems: standard system dialog is shown istead of BugTrap Pin
Simon Brown24-Jul-06 21:36
Simon Brown24-Jul-06 21:36 
QuestionIs it possible to display what the pointers contained ? Pin
Ray Duku17-Jul-06 2:49
Ray Duku17-Jul-06 2:49 
AnswerRe: Is it possible to display what the pointers contained ? Pin
Maksim Pyatkovskiy17-Jul-06 5:57
Maksim Pyatkovskiy17-Jul-06 5:57 
GeneralRe: Is it possible to display what the pointers contained ? Pin
Simon Brown24-Jul-06 1:53
Simon Brown24-Jul-06 1:53 

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

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