Debugging an NT service using MSDEV and BoundsChecker



How to use BoundsChecker from within MSDEV to debug a service


To debug a service using the Visual C (MSDEV) debugger along with BoundsChecker Integrated debugging, perform the following steps. Note that this example assumes that you are debugging the Scheduler service (you would have to make minor modifications for your service):

1) Go to the Control Panel and invoke the Services applet.

2) Double-click on the service name to bring up the Service dialog.

3) Check the "Allow Service to Interact with Desktop" box.

4) Click OK.

5) Click Close on the Services dialog.

6) Create a MSDOS box and issue the following command:

subst x: "c:\program files\Microsoft Visual Studio\common\msdev98\bin"

Note that you might have to substitute a different drive letter for x: if you have already used X. You may also have to specify a different location for msdev.exe if you didn't install Visual Studio 6.0 into the standard directory.

7) Invoke Regedit and create a new key in the following tree:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options

That contains the name of your service. In this example I will create a key called AtSvc.exe to correspond to the scheduler service by selecting Edit->New->Key from the registry editor menu.

8) After you've created the new key, right click in the right window and select New->String value. Name the new string "Debugger" and make the value of the string "X:\msdev.exe"

If you had to specify a drive letter other than X: in step 6 you must make the necessary changes when creating the registry key.

9) Start the service. In our case we will do it using the following procedure:

a) Go to the Control Panel and invoke the Services applet.

b) Single click on the service name and then click the start button.

10) After about 3-5 seconds MSDEV will be invoked.

11) Make sure that the BoundsChecker integrated debugging is selected. If not, you can enable it by using the BoundsChecker toolbar or by selecting it from the BoundsChecker menu inside Visual Studio.

12) Start your application and it will be debugged by Visual Studio along with BoundsChecker integrated debugging.

Note that you can not delay for more than a few seconds or the Service Control Manager will think that your service did not start properly and report an error. You may also need to modify the "hints" parameter when communicating with the Service Control Manager using the SetServiceStatus API. In general, you should set this to a very large value. Remember that "hints" is specified in milliseconds. Failure to set this value to a high enough value can cause the Service Control Manager to terminate your service while sitting at a breakpoint in the debugger or while BoundsChecker is analyzing your programs memory and resource information. This can be especially true during image rundown after the program exits and BoundsChecker is looking for leaks.

After you have finished debugging your service, remember to perform these steps:

1) Turn off the interact with desktop checkbox in the Services applet.

2) Go into the registry and delete (or rename) the registry key in the "Image File Execution Options" tree that corresponds to your service. Otherwise, MSDEV will be invoked every time you start your service.

Old KB# 11287
Comment List
Related Discussions