Solved

Debugging CGI app written in Perl and run on Apache.

Posted on 2010-09-11
6
672 Views
Last Modified: 2013-12-25
Hi, what is the best way of debugging CGI application written in perl and run with Apache Web Server?

For now I'm using print STDERR "debug text" and watching error logs, but that's quite inefficient.
0
Comment
Question by:DalHorinek
6 Comments
 
LVL 10

Expert Comment

by:jeromee
ID: 33654324
DalHorinek,
here's the best way to go about it... It's a bit difficult to set up at first but once you are set up there's no better way.
I assume that you use your cgi app to handle HTML"form".
make sure that you use the GET (vs POST) way of submitting forms which look like this once your form has been subnitted: http://my.website.com/cgi-bin/my_app.pl?arg1=val1&arg2=val2 where 2 arguments are being passed arg1 arg2 with the respective values val1 and val2.

Now to debug the application, locate the cgi application on the disk...say /home/apache/cgi-bin/my_app.pl
   * go to /home/apache/cgi-bin
   * perl -d cgi-bin/my_app.pl  "arg1=val1&arg2=val2"
(note that arg1=val1&arg2=val2 is exactly the same as the ones listed in the URL above)

From that point on, you are under the Perl debugger (more info here: http://perldoc.perl.org/perldebug.html) which is the best way to debug an Perl app.

Note that most of the time your application will be running as the user nobody with a limited shell environment. So, to fully replicate the way your app is run by Apache, you may need to log in as nobody.

Good luck!

0
 
LVL 48

Expert Comment

by:Tintin
ID: 33654597
Are you trying to debug errors or logic?
0
 
LVL 6

Author Comment

by:DalHorinek
ID: 33654695
Both, I'd love something like breakpoints and inspector, at least the inspector to watch what is where ..

I know about embedded debugger, anyway I use CGI module for handling and some around functions and so on, is CGI module able to handle params passed as arguments when run from command line?

Also there is question about sessions ...
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 33654802
I almost always use the Template Toolkit for generating web pages.
http://search.cpan.org/~abw/Template-Toolkit-2.22/lib/Template.pm

Using this, I'll put something like this in my file:
[% IF Debug; Debug; END %]

Then in my code, whenever I want to see what is going on, I'll use this:
$template->{Debug} .= "Some message\n";

The $template is the "\%vars" parameter in the template documentation.

Not as easy as using breakpoints and single-stepping, but you don't have to change your process at all to use it.  Also, once you have it working, all you need to do is remove (or comment out) the debug line in the template, and all your debugging display goes away - you don't need to change the perl code behind it at all (slight speed penalty to leave the debugging code in perl, but this is minor - in most cases anyway).  If you need to add it back in, just uncomment the debug line in the template.  Over using STDERR, it keeps the debug output and the real output together.
0
 
LVL 6

Author Comment

by:DalHorinek
ID: 33654827
Thanks Adam, I use Template Toolkit too, but this approach didn't cross my mind, it seems as good idea, thank you.  
0
 
LVL 6

Author Closing Comment

by:DalHorinek
ID: 33654833
Nice approach presented.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question