computer motherboard

Analysing a simple crash

This tutorial demonstrates launching the sample application, crashing the application and using C++ Bug Validator to identify the location and cause of the crash. We’re going to demonstrate this with MFC and without MFC.

Simple Crash with MFC

This tutorial analyses a simple NULL pointer dereference crash. The tutorial is performed with MFC code instrumented, so that MFC message processing and pointer validation calls are part of the application trace.

  • Open the settings dialog by clicking the tools icon on the toolbar.
    Bug Validator settings icon
  • The Settings Dialog is displayed. Select the Hook Insertion tab.
    Bug Validator hook insertion
  • Select the check boxes in the section marked DLL Hook Insertion. The image shows that the MFC, CRT, STL and system DLLs have been marked to be ignored (deselected). Click OK to accept the settings.
  • Launch the sample application. Click on the launch icon on the toolbar.
    Bug Validator launch icon
  • The Launch application wizard is displayed.
    Bug Validator launch wizard
  • Select the sample application bvExample.exe using the Browse… button.
  • Click the Next button to move to the 2nd page of the wizard.
    Bug Validator launch wizard
  • Leave the settings as the default settings.
  • Click the Next button to move to the 3rd page of the wizard.
    Bug Validator launch wizard
  • Leave the settings as the default settings.
  • Click the Next button to move to the 4th page of the wizard.
    Bug Validator launch wizard
  • Click the Start Application button to launch the application.
  • The bvExample.exe application is started.
    Bug Validator native example application
  • Wait for the instrumentation of the application to complete.
  • On the File menu, choose Crash 1. This will execute the code shown below, which dereferences a NULL pointer, causing an “Access Violation Exception”
    	// test of dereferencing a NULL pointer
    
    	DWORD	*dwPtr;
    
    	dwPtr = NULL;
    
    	// the next line will crash
    
    	*dwPtr = 0;
    
  • The exception will cause the following dialog box to be displayed by the operating system:
    Windows NT, Windows 2000
    Exception on Windows NT, 2000
    Windows XP
    Exception Windows XP
    Do not click any of the buttons on the dialog.
  • On the C++ Bug Validator Execution History tab, click the Refresh button. The display will refresh. You can now click the buttons on the exception dialog as you desire (to dismiss the application or enter the debugger etc).
  • Scroll to the bottom of the display. The image will look similar to the image shown below.
    Crash with MFC (1)As you can see in the image above, the exception has been caught in the unhandled exception filter, which resulted in the exception dialog being displayed. Scrolling up from the bottom of the list a few items shows the location of the code that caused the problem, as displayed in the the image below.
    Crash with MFC (2)

Simple Crash without MFC

This tutorial analyses a simple NULL pointer dereference crash. The tutorial is performed without MFC code instrumented, so that MFC message processing and pointer validation calls are not part of the application trace. This makes the trace simpler to understand, with the penalty that if the crash is within MFC, you cannot see the trace to the location of the crash.

  • Open the settings dialog by clicking the tools icon on the toolbar.
    Bug Validator settings icon
  • The Settings Dialog is displayed. Select the Hook Insertion tab.
    Bug Validator Hook Insertion
  • Select the check boxes in the section marked DLL Hook Insertion. The image shows that the MFC, CRT, STL and system DLLs have been marked to be ignored (deselected). Click OK to accept the settings.
  • Launch the sample application. Click on the relaunch icon on the toolbar.
    Bug Validator re-launch toolbar
  • The bvExample.exe application is started.
    Bug Validator native example application
  • Wait for the instrumentation of the application to complete.
  • On the File menu, choose Crash 1.
  • The exception dialog is displayed by the operating system. Do not click any of the buttons on the dialog.
  • On the C++ Bug Validator Execution History tab, click the Refresh button. The display will refresh. You can now click the buttons on the exception dialog as you desire (to dismiss the application or enter the debugger etc).
  • Scroll to the bottom of the display. The image will look similar to the image shown below.
    Crash without MFCNotice how the flow of the application is easier to follow without the MFC message loop processing filling up the display.
  • The crash location is the second to last line in the scrolled list. The last line is the call to the unhandled exception filter in crtexe.c. Click on a line to view the source code in the source viewer pane.

Fully functional, free for 30 days