Starting a Debugging Session

Like most Windows applications, CVW can be started in several ways. You can double-click the CVW icon and respond to CVW's prompts for arguments, or you can run CVW by using the Run command from the Program Manager File menu.

To specify CVW options, choose the Run command from the Program Manager File menu. Windows displays a dialog box where you can enter the appropriate options for your debugging session. For specific information on CodeView command-line syntax and options, see “The CodeView Command Line”.

You can run CVW to perform the following tasks:

Debug a single application

Debug multiple instances of an application

Debug multiple applications

Debug dynamic-link libraries (DLLs)

This section describes the methods you use to perform these tasks and summarizes the syntax of the CVW command line for each task.

Starting CVW for a Single Application

After you start CVW from Windows, CodeView displays the Load dialog box.

·To start debugging a single application:

1.Type the name of the application in the File to Debug text box.

CVW assumes the .EXE filename extension if you do not include an extension for the application name. You can also pick the program that you want to debug by choosing it from the Files List box.

2.If you want to specify command-line arguments, move the cursor to the Arguments text box and type the program's command line.

3.Choose OK.

CVW loads the application and displays the source code for the application's WinMain routine.

4.Set breakpoints in the code if you desire.

5.Use the Go (G) command (F5) to begin executing the application.

·To avoid the startup dialog boxes:

1.Choose the Run command from the Windows File menu.

2.Type the application name and arguments on the CVW command line. Use the following syntax to start debugging a single application:

CVW [[options]] appname[[.EXE]] [[arguments]]

3.Choose OK.

Starting CVW for Multiple Instances of an Application

Windows can run multiple instances of an application, which can cause problems. For example, each instance of an application might corrupt the other's data. To help you solve such problems, CVW allows you to debug multiple instances of an application. The breakpoints you set in your application apply to all of the instances. To determine which instance of the application has the focus in CVW, examine the DS register.

·To debug multiple instances of an application:

1.Start CVW as usual for one instance of your application.

2.Run additional instances of your application by choosing the Run command from the Windows File menu.

You cannot specify the application name more than once on the CVW com-mand line. Any additional application names are passed as arguments to the first application.

Starting CVW for Multiple Applications

You can debug two or more applications at the same time, such as a dynamic data exchange (DDE) client and server.

·To debug several applications at the same time:

1.Start CVW as usual for a single application.

2.Choose Load from the Run menu and choose other applications that you also want to debug.

3.Set breakpoints in either or both applications. You can use the Open Module command from the CVW File menu to display the source code for the different modules. If you know the module and the location or function name, you can use the context operator ({ }) to directly set breakpoints in the other applications.

4.Use the Go (G) command (F5) to start running the first application.

5.Choose the Run command from the Windows File menu to start running the second application.

You can also use the /L option on the CVW command line to load the symbols for additional applications, as shown in this example:

CVW /Lsecond.exe /Lthird.exe first

The /L option and name of each additional application must precede the name of the first application on the command line. You must specify the .EXE filename extension for the additional applications. Repeat the /L option for each application to be included in the debugging session.

Once CVW starts, choose the Run command from the Windows File menu to start executing the additional applications.

Note:

Global symbols with the same name in several applications (such as WinMain) may not be distinguished. You can use the context operator to specify the exact instance of a symbol.

Starting CVW for DLLs

You can debug one or more DLLs while debugging an application.

·To debug a DLL at the same time as an application:

1.Start CVW as usual for the application.

2.Choose Load from the Run menu and type the name of the DLL.

3.Set breakpoints in the application or DLL. You can use the Open Module command from the CVW File menu to display the source code for the different modules.

4.Use the Go (G) command (F5) to continue executing the application.

You can also use the /L option on the CVW command line to specify the DLLs, as shown in this example:

CVW /Lappdll appname

The /L option must precede the name of the application. Repeat the /L option for each DLL you want to debug.

Debugging the LibEntry DLL Initialization Routine

CVW allows you to debug the LibEntry initialization routine of a DLL. If your application implicitly loads the library, however, 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 routine.

If your application implicitly loads the DLL and you specify the application in the Command Line dialog box, Windows automatically loads the DLL and executes the LibEntry routine when it loads the application. This gives you no opportunity to debug the LibEntry routine since it is executed when the application is loaded and before CVW gains control.

To gain control before the LibEntry routine is executed, you must set a breakpoint in the LibEntry routine before the DLL is loaded.

·To set this breakpoint:

1.In the CVW Load dialog box, provide the name of a “dummy” application that does not load the library instead of the name of your application. The WINSTUB.EXE program is provided for this purpose.

2.Load the DLL by using the Load command from the Run menu.

3.Choose the Open Module command from the CVW File menu and select the module containing the LibEntry routine.

4.Set at least one breakpoint in the LibEntry routine.

5.Use the Go (G) command (F5) to start the dummy application.

6.Run your application using the Run command from the Windows File menu. CVW resumes control when the breakpoint in the LibEntry routine is taken.

You can also specify the dummy application and the DLL on the CVW command line.

·To begin a DLL debugging session from the command line:

1.Type the command line:

CVW /Lmydll winstub

2.After CVW starts, follow steps 3 through 6 above to begin debugging.