You can debug a CGI applications using the Just-In-Time Debugger with an embedded call to CBL_DEBUGBREAK, or using the
Wait for debuggable attachment or
Launch URL debug options in the project properties. If the Web server is configured to run as a service you need Administrator privileges to allow the debugger to attach to the CGI process.
Tip: If the Debugger fails to find the symbols for your program, you can add the path to the CGI symbols to your symbol path.
Do this from the
Debugging > Symbols page in your Visual Studio Options. For example:
c:\apache2.2\cgi-bin.
You can debug native CGI projects using the Launch URL start option.
Debug using Wait for debuggable attachment
- Start your Web server.
- Ensure the CGI binaries are in a folder on the Web server and execution of CGIs in that folder is enabled.
- Start the IDE.
Note:
- If the CGI is running as a service, you must start Visual Studio with administrator's privileges.
- You can use the httpd executable to run the Apache Web Server from the command line. Since this executable uses your own User ID, it is not necessary to start the IDE with administrator's privileges.
- In the IDE, click
Project >
myproject properties and select the
Debug tab.
- Choose either one of the following debug options:
- Click
Start browser with URL and specify the application URL - for example,
http://localhost:80/cgiform1.htm.
To ensure that this option will wait for the correct CGI, either the project output folder or the path specified by the
Working directory setting on
Debug tab must match the CGI folder of the Web server.
Or,
- Click
Wait for debuggable attachment and specify
Wait for directory.
- Specify the path to the CGI folder in the
Working directory field.
Also:
- Check
Return to waiting state when debugging, if you want to debug the CGI application multiple times.
- Click
Debug > Start debugging.
The debugger waits for your CGI application to run, and then attaches to it.
Debug using CBL_DEBUGBREAK and the Just-In-Time debugger
You can also embed a call to CBL_DEBUGBREAK in your code and use it to debug CGIs. When the CGI runs and the call is encountered, you receive a Just-in-time debug notification which prompts you to allow the CGI to be debugged with administrator's privileges.
Alternatively, you can start the IDE as described above and configure it so it automatically starts debugging the CGI, when the call is encountered. You need to specify the following option on the
Debug tab in the project's properties - choose
Wait for debuggable attachment and specify
Wait for any program.
Note: You must use any of the
Wait for debuggable attachment options when you debug CGIs that run under IIS 7.5. By default, this application uses "ApplicationPoolIdentity" to run CGIs which blocks the Just-in-time debug prompt.