Debugging CGI programs can be challenging. A CGI program runs in a very specific environment. There are several environment variables that affect its behavior, and even the standard input stream has a special use (post parameters).
The dbcgi script is a CGI program which captures all the environment variables and standarad input, then creates a shell script which will run the Perl debugger in the same environment. You can use this shell script to deubg your program.
The dbcgi script can also be run at the command prompt. In this setting, the dbcgi program is used to replace another CGI program with a copy of itself. It makes a backup copy of the CGI program so that it can be restored. You restore the backup copy by running the dbcgi program.
./dbcgi mycgiwhere mycgi is the name of your CGI program. dbcgi prints lines describing the commands it is running to backup your file and replace it with a copy of itself.
./dbcgi mycgiThis time dbcgi notices the backup copy of your program and restores it. It also copies the shell script that was made to the current directory. Again, it prints lines describing the commands it is running.
./mycgi.env mycgiwhere mycgi is the name of your CGI progmram. (Note this assumes you currently have your source code open in Emacs. If you did not, you would have to give the full path names of the files.)
You are now debugging your program in a simulation of the web environment.
This script should work for all types of input parameters, including text file uploads. It will break if you upload a binary file because a shell script cannot contain binary characters.