fficient software debugging is definitely an acquired talent. Most programmers have some ideas on how to do it when they first get started but typically can't handle a large complex program that doesn't work. Add multithreading to a complex program and you're sure to lose most junior software developers.
In the "old days" the only way to debug a program was to put in a bunch of print statements, or the language appropriate equivalent, interspersed with the rest of the code to dump out variables and let you know where the program got to before it crashed. This method still works well for any language without a suitable debugger.
from Gurock Software uses a mixture of old-fashioned techniques with tight Visual Studio integration to help ease the pain of debugging multithreaded applications. Today's version of the old print statements writes messages into a log file. The advantage of a log file is that you can typically put enough information there to help you find out what's going onand you can make logging a feature that can be turned on or off via configuration in a production deployment of your application.
Installation and Setup
Installing SmartInspect takes only a few minutes and adds a single icon to your desktop to access the console program. To use the product with your projects, you'll need to perform this three-step process.
|Figure 1. The Project Property Pages: This is where you add the Gurock.SmartInspect namespace as an import for your project.|
- You must add a reference to the SmartInspect.dll. To do that, right click the References item in the Solution Explorer, browse to the folder where you installed the program, and select the SmartInspect.dll file.
- Add SmartInspect to the import list by right-clicking on your root project item in Solution Explorer and selecting Properties. From the Properties page, select "Imports," and then enter "Gurock.SmartInspect" in the namespace edit box (see Figure 1).
- Enabling SmartInspect in your project requires a single line of code in the form load method. In VB.NET, this line should look like:
SiAuto.Si.Enabled = True
After enabling SmartInspect, you have two choices for debugging codeyou can debug through the SmartInspect console or exclusively through log files. The console is great for initial development and testing but it isn't something you'd want to leave in a production program. During development however, using the console for debugging sessions is much easier than wading through log files.
You can use either the TCP/IP protocol for real-time logging (the default) or specify a log file, for example:
SiAuto.Si.Connections = @"file(filename=c:\log.sil)";
The console can load a specified log file or receive the logging information via TCP/IP. For production use it's better to use log files, especially for a commercial app where support is likely to be offsite.
The best way to enable debugging for a production application is to use the LoadConnections
method of the SmartInspect class. With this method, support staff can send a preconfigured connections file to the customer to enable logging. Here's an example of using the LoadConnections
In the example above, if you had deployed an application with a customer that was having problems, you could have the customer place a preconfigured connections file called connections.sic
in the c:\
folder, thus enabling logging and directing the log output to a destination specified in the connections file. You can then use the log contents to debug the deployed application. Logging will remain disabled if SmartInspect can't find the specified connections file, or if the file doesn't contain a valid connection string.
The code that logs a message works with both the console and log file output. SmartInspect provides two additional methods, EnterMethod
, that let you know when a program enters or leaves a method. The console also provides a button so you can display the call stack to trace program execution paths easily. Here's a code snippet from the downloadable TimeServer sample program
showing several different log methods:
int minutes = DateTime.Now.Minute;
int seconds = DateTime.Now.Second;
int index = minutes / seconds;
SiAuto.Main.LogMessage("Sending date to client.");
for( int j = 0; j<1024; j++)
buffer[j] = (byte) (j * 431);