4.5.5 Starting a Debugging Session for Dynamic-Link Libraries

You can debug one or more DLLs while you are debugging an application. However, no distinction is made between global symbols shared by the applications and any DLLs.

Perform the following steps to debug a DLL at the same time as an application:

1.Start CVW as usual for the application.

2.Type the name of the DLL when CVW displays a dialog box with the following message:

Name any other DLL or executable with debug info.

CVW assumes the .DLL extension if you do not supply an extension with the filename. If your DLL has another extension (such as .DRV), you must specify it explicitly.

3.From the File menu, choose Open Module to display the source code for the different modules. Set breakpoints in either the application or the DLL.

4.Press F5 to continue running the application.

Alternatively, you can use the /l option to specify the DLL on the command line in the Run dialog box, as follows:

cvw /l appdll appname.exe

The /l option and the name of the DLL must precede the name of the first application on the command line. You can repeat the /l option for each DLL to be included in the debugging session. The .DLL extension is the default extension for the /l option.

CVW allows you to debug the LibEntry initialization routine of a DLL. If your application implicitly loads the library, a special technique is required to debug the LibEntry routine. An application implicitly loads a DLL if the library routines are imported in the application's module-definition (.DEF) file or if your application imports library routines through an import library when you link the application. An application explicitly loads a DLL by calling the LoadLibrary function.

If you type in the Command Line dialog box the name of an application that implicitly loads a DLL, CVW automatically loads the DLL and executes the DLL's LibEntry routine when CVW loads the application. In this case, you have no opportunity to debug the LibEntry routine. To avoid this problem, perform the following steps:

1.Instead of typing the name of your application in the Command Line dialog box, type the name of a dummy application that does not implicitly load the library.

2.Type the name of your DLL, being sure to include the extension if it is not .DLL, when the following message is displayed:

Name any other DLL or executable with debug info.

3.From the File menu, choose Open Module to display the source code for the library module containing the LibEntry routine. Set breakpoints in the LibEntry routine.

4.From the File menu, choose Open Module to display the source code for other library or application modules. Set breakpoints.

5.Press F5 to start running the dummy application.

6.Run the application that implicitly loads the DLL by choosing Run from the Program Manager File menu. CVW will resume control when the breakpoint in the LibEntry routine is encountered.

Alternatively, you can use a command line of the following form to specify the dummy application, your application, and the DLL:

cvw /l appdll dummyapp

After this command starts CVW, you need to perform steps 5 and 6 of the preceding procedure.