This tutorial describes how to collect an execution trace from IIS ISAPI DLL. This can be useful for identifying the actions that happened before a crash or memory corruption occurring.
This tutorial covers the following:
Related tutorials:
Execution tracing in a child process.
Execution tracing in a service.
Execution tracing in a service child process.
Execution tracing for a child process from the command line.
This tutorial applies to all native ISAPI DLLs and to mixed-mode ISAPI DLLs that use the native Win32 services API.
Bug Validator ships with an example ISAPI DLL in the examples\isapiExample folder in the Bug Validator installation directory.
The ISAPI DLL has already been modified to use the NT Service API. In this tutorial we’ll describe the modification you would make to the ISAPI DLL to make it work correctly with Bug Validator.
The NT Service API is a simple API that allows you to load the Bug Validator profiling DLL and start the process of collecting an execution trace.
The API also includes some debugging functions to help provide debugging information via log files (the only way to get data out of an ISAPI DLL without a connection to the Bug Validator user interface).
The purpose of attachToBugValidator() is to use the NT Service API to instrument the ISAPI DLL with Bug Validator.
// code to load Bug Validator into the IIS process for this ISAPI
// this assumes the ISAPI is in C:\testISAPIWebsite\
#include "..\..\svlBVStubService\svlBVStubService.h"
#include "..\..\..\svlCommon\svlServiceError.h"
static void attachToBugValidator()
{
svlBVStub_setLogFileName(L"C:\\testISAPIWebsite\\svl_BV_log.txt");
svlBVStub_deleteLogFile();
SVL_SERVICE_ERROR errCode;
#ifdef IS6432
// x86 with x64 GUI
errCode = svlBVStub_LoadBugValidator6432();
#else //#ifdef IS6432
// x86 with x86 GUI
// x64 with x64 GUI
errCode = svlBVStub_LoadBugValidator();
#endif //#ifdef IS6432
if (errCode != SVL_OK)
{
DWORD lastError;
lastError = GetLastError();
svlBVStub_writeToLogFileW(L"Bug Validator load failed. \r\n");
svlBVStub_writeToLogFileLastError(lastError);
svlBVStub_writeToLogFile(errCode);
svlBVStub_dumpPathToLogFile();
}
else
{
svlBVStub_writeToLogFileW(L"Bug Validator load success. \r\n");
errCode = svlBVStub_StartBugValidatorForIIS();
if (errCode != SVL_OK)
{
DWORD lastError;
lastError = GetLastError();
svlBVStub_writeToLogFileW(L"Starting Bug Validator failed. \r\n");
svlBVStub_writeToLogFileLastError(lastError);
svlBVStub_writeToLogFile(errCode);
}
svlBVStub_writeToLogFileW(L"Finished starting Bug Validator\r\n");
}
}
Now that the NT Service API has been implemented in your service, we can start collecting memory allocation data from the service.
If errors are found you will be presented with a dialog box specific to the error so that you can correct the error before starting the web browser.
To finish collecting an execution trace, you need to stop IIS.
If you had selected Stop IIS when web browser is closed on the Monitor IIS and ISAPI dialog then you have nothing to do.
Otherwise, choose Launch > Services > Stop IIS
Bug Validator will collect an execution trace through the IIS shutdown procedure and then present you with the complete execution trace.
There are a few things to check.
svlBVStub_setLogFileName(SZLOGFILENAME);
You have learned how to add the NT Service API to an ISAPI DLL, how to use Bug Validator to collect an execution trace for ISS and ISAPI, and what to look at to diagnose errors if things don’t work first time.