Debugging perl CGI - eclipse

I am using a web form I created as an interface to query a MySQL database. I have written some
perl CGI scripts to process the queries. But I am not getting the desired output, so I need to
debug the scripts. How do I do that? I mostly use Eclipse for debugging perl, but now I have the
web form parameters (checkboxes, listboxes) as input to the script. Is there any way I can pass
in the inputs from the web page and then debug the script in Eclipse? Or is there any other way
of debugging in this case? Hope I have made myself clear. Thanks.

I use this Perl module for CGI debugging. It lets you capture all data sent to a CGI script, when running from a normal browser. It then lets you "replay" the script from anywhere (command line, within a debugger) using the captured data.
CGI::Inspect looks promising, though I haven't tried it yet myself.
Using Devel::DumpTrace during a normal CGI session (with the data being logged to a file, via DUMPTRACE_FH) is a way to do in-depth debugging, without using an actual debugger.

Yes, of course you can use Apaches error log to do debugging; which a very lazy but efficient way to work.
You mention you use Eclipse so I assume you also use the EPIC plug-in for Perl development. Check out this chapter on how to configure Eclipse/EPIC for debugging CGI:
http://www.epic-ide.org/guide/ch06s02.php

I would hope Eclipse has a way to simulate CGI.
I use ActiveState's Komodo IDE, and it can simulate CGI (including input params), so I can recommend that as a good tool for this purpose. The IDE is NOT free, though, but consider this an investment if you're going to be doing this a lot. (I'm NOT affiliated with ActiveState - just a happy customer.)

It's not clear what exactly you want to debug, but a few tips:
When running under Apache, warnings go to the error.log, so you could follow your variables there.
The CGI.pm module allows you to run CGI scripts from the command-line (with parameters).

if you have a hypothetical CGI program written in perl, called webawesome.pl and you want to pass it two parameters: name and age, you can use a shell command like this:
prompt> perl -d webawesome.pl name=sifl age=21
Now you're in the perl debugger and you can step through your program, and the key/value pairs from the command line will be loaded as form parameters by CGI.pm
Setting these command line switches in Eclipse is left as an exercise to the reader, as I am an unabashed vi user, and haven't use eclipse in two or three years. I know there's dialogs to set run/debug options.

You can use Firebug or Fiddler to watch your requests made from the form, to ensure you are sending exactly what you think you are. You can also open a file open(fh,">>debug.txt") and print out the sql calls that you are making to a log file. I would also suggest learning about Data::Dumper which will print out objects prettily so you can see their structure.

Related

How to capture stack trace for Ncurses app?

Typically, when running an application from the command line, I get a nicely printed trace when things go wrong. But, since I happen to be working on an Ncurses application, the trace gets mixed in with the interface that was running, and the output gets all jumbled. Like so:
Specifically, I'm working on this project: todo-curses.
I'm running the app as a Rake task, so I figured the --trace option would help me, but I just can't seem to figure it out. Is there a good way to log the output of the app to a file or something and not include the Ncurses interface with it?
It depends on the application: curses writes to the standard output by default. If you (as the developer of the curses application) use newterm for initializing the library rather than initscr, then you can tell it to write the screen interface to the standard error.
But developers of bindings for curses from other languages typically leave out newterm as an alternative, just to make things simple. For instance, the Ruby curses shown on github has this deficiency. Perhaps a bug report is due.

Changing Code At Runtime While Debugging

I am using Eclipse Kepler Service Release 2 , EPIC 0.5.46 and Strawberry Perl 5 version 18 for perl programming. For debugging I am using Eclipse debugger and PadWalker .
I have an interactive perl program that writes to files based on answers provided by the users to multiple prompts. While debugging , every time i change a single line of code I have to rerun the whole program again and provide inputs to every prompt , which is really time consuming.
Is there a way to make changes to the code in a sub routine , in the middle of debugging session such that the instruction pointer resets itself to the first line of that sub routine. This way i do not have to restart the session to recompile the new code.
Appreciate your inputs and suggestions. Thank You!!!
What you want to do can be done, and I've done it many times in Perl myself. For example, see this.
However although what you describe may work (and is a bit dangerous), the way it is generally done a bit different and safer.
First one has to assume a regular kind of command structure like a command processor, or say a web server.
In a command processor or web server, you read a command (or get a web request), perform an action, then read another command, perform another action and so on. From your description, it sounds like you have such a structure.
In my case, I have each debugger command stored as in Perl file. This is helpful not only for facilitating this task, but also for understanding, testing and changing the code.
Given this kind of program structure, instead of trying to change the program counter, you complete the command and at the level where you are about to read a new command, you make the change and then reload the file which changes the code.
The specific Perl construct to do this is called do. Don't use require or use which will load in a Perl file only if that file or module hasn't been previously loaded. In your situation, you want to reload even if it has been loaded before.
So now how do you get to be able to issue a do command? As you suggest, you could do it through a debugger. Assuming you have this overall program stucture as described above, you put the breakpoint somewhere a common point in the caller which loops over things to process, rather than try to change things in indvidual commands.
And you don't even need a debugger to do this! Many web frameworks like Ruby on Rails, have a "development" mode where they save timestamps on files that implement functionality. If the file has changed they issue the "do" command before running the request.

Tracing (for documentation purposes) through .cmd and .pl files.

I am somewhat new to programming and VERY to command line and perl. I was wondering if anyone knew of a way that I can trace through a .cmd file and see what perl scripts its calling and then open those files and see what files it is calling (or functions etc...) without having to go through each file manually. I use Visual Studio 2010 and Notepad. I am mostly trying to do this to get everything documented and I would like to eventually be able to have a TOC or Tree View of the files and which files/commands/functions they call etc.. I am probably not explaining this well :) So, apologies AND Thanks in advance!! Britt
The perl debugger will let you step through perl applications/scripts and see what is getting used with various levels of detail. See perldoc perldebug or the online documentation for how that works.
Padre is a nice (and free) IDE for perl and you can look at other answers to this question for more ideas on how to use perl with VisualStudio.
Tracing batch file is problematic: Is there any way to trace through the execution of a batch file?
For tracing Perl programs, install Devel::Trace and set PERL5OPT=-d:Trace.

SQLPLUS session to remember history

I have just started using sqlplus for oracle and it is horrible, I was trying to look for ideas if anyone has any scripts written around sqlplus which stores history and and it works more like an editor.
You might want to consider using YASQL, http://sourceforge.net/projects/yasql/, which is an alternative client written in Perl.
It is pretty neat and covers most of what one would expect from a DB CLI client. It does not support everything sqlplus does, though.
What you want is the extremely handy rlwrap command. It will wrap almost any command and add readline-style command history and editing. It supports, colors, custom completions, and all that jazz. I'm not sure if the link I provided to rlwrap is the "official" source, and compiling it can sometimes be a pain, but your favorite Unix package source should have some version of it available.

How can Perl fill out fields on a GUI made in Visual Basic?

I have a script that runs several little programs I don't have the source code to, one of which requires filling out some fields in a GUI. I've been doing this by hand, but I'd like to have the Perl script focus the GUI window, then enter some hardcoded text into each field and close the window.
In the past I've used the Win32::GuiTest module for tasks like this. Have a look at the example scripts and documentation.
Unless there's a specific reason you're using Perl, Autoit is a Basic-like scripting language pretty much specifically designed for automating GUI tasks. It's very easy to pick up.
You can have it wait for a window to become active, send any sequence of keystrokes or tell it to specifically focus on a GUI element with a given handle, and much more. You can also package the scripts as standalone executables, which can be a nice benefit when you need it.
You might want to look into Win32::OLE. There's also a book on this topic.