Solved

Debugging CGI app written in Perl and run on Apache.

Posted on 2010-09-11
6
682 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
This article was originally published on Monitis Blog, you can check it here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sourc…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 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