You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Pablo Velasquez <pa...@citysearch.com> on 2003/07/18 23:13:23 UTC

DDD and mod_perl handler

Hello,
I've been searching for guidance on using DDD with mod_perl. (DDD is 
fantastic)

I use DDD to debug my perl scripts like so:

ddd --perl myperlscript.pl (quite simple :)

However, I haven't been able to do the same with a mod_perl handler.

Perl 5.005_03
Apache/1.3.24 (Unix) 
mod_perl/1.26
RH 8.0

This is my handler "http://localhost/Reports/Cslink" I'd like to step through 
the code with DDD.

Here's what I have been able to accomplish:
1. Installed Apache::DB
2. If I run this from the command line: ./httpd -X

I do get a message telling me I'm in debug mode:
[notice] Apache::DB initialized in child 2487

3. I go to my browser and call:
http://localhost/Reports/Cslink

4. From the command line I now see this:
Loading DB routines from perl5db.pl version 1.0402
Emacs support available.
Enter h or `h h' for help.
Reports::Generate::Cslink::handler(/usr/local/apache/lib/perl/Reports/Generate/Cslink.pm:11):
11:     $ENV{ORACLE_HOME}='/usr/local/oracle';
DB<1>

5. This is all good, since now the perl debugger is running my program, just 
like when I use DDD to run a regular perl script. However, the question is, 
how can I use DDD to run on top of this?

I've been reading online for the answer and there are some hints:
"Debugging mod_perl C Internals"
http://perl.apache.org/docs/2.0/devel/debug/c.html

In fact, I'm going to try this one, but I was hoping for a more standard 
approach.

Thanks.

-Pablo













Re: DDD and mod_perl handler

Posted by Stas Bekman <st...@stason.org>.
Pablo Velasquez wrote:
> Hello,
> I've been searching for guidance on using DDD with mod_perl. (DDD is 
> fantastic)
[...]
> I've been reading online for the answer and there are some hints:
> "Debugging mod_perl C Internals"
> http://perl.apache.org/docs/2.0/devel/debug/c.html

This document explains how to debug C internals, not perl.

I've done some googling and found a post from Gerald answering a similar 
question for embperl. To debug mod_perl handlers under ddd, you need to 
configure Apache::DB normally, and next instead of starting httpd -x, you need 
to do:

ddd --debugger '/home/httpd/httpd_perl/bin/httpd -f 
/home/httpd/httpd_perl/conf/httpd.conf -X -DPERLDB' --perl

(adjust the paths)

Now when you issue a request ddd will give you an interactive shell, just like 
you get with perl -d. It won't open the source file for you, since it doesn't 
know what that source file is. You have to open it manually via menu item 
'Open Source' and finish the first execution in the interactive shell window. 
Only on the next request you will be able to step through with the source window.

Moreover you won't be able to step through using the source window for 
registry scripts. This is because registry scripts aren't executed as files, 
but evaled as a string.

Here is an example:

httpd.conf:

<IfDefine PERLDB>
   <Perl>
     use Apache::DB ();
     Apache::DB->init;
   </Perl>

   <Location />
     PerlFixupHandler Apache::DB
     #PerlFixupHandler Apache::SmallProf
   </Location>
</IfDefine>

<Location /hello-world>
     SetHandler perl-script
     PerlHandler Apache::HelloWorld
</Location>


#file:Apache/HelloWorld.pm
package Apache::HelloWorld;
use strict;

sub handler {
     my $r = shift;

     $r->send_http_header('text/plain');
     print "Hello ";
     print "world\n"
     return 0;
}

1;

1) start ddd:

ddd --debugger '/home/httpd/httpd_perl/bin/httpd -f 
/home/httpd/httpd_perl/conf/httpd.conf -X -DPERLDB' --perl

2) using the menu 'open source' for Apache/HelloWorld.pm.

3) issue a request:

lynx --dump http://localhost:8000/hello-world

using the DDD commands menu do 'finish' (sometimes twice). At this point all 
the output will go to the interactive shell console and not the client.

4) issue the request second time (this time in browser if wanted):

lynx --dump http://localhost:8000/hello-world

now you can step through the source code with ddd's commands menu, and even 
look at the contents of the variables in the 'Data' window.

The pain is that you have to manually open the source file. If you can find 
how to make it programmatically please share with us.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: DDD and mod_perl handler

Posted by Perrin Harkins <pe...@elem.com>.
On Fri, 2003-07-18 at 17:13, Pablo Velasquez wrote:
> 5. This is all good, since now the perl debugger is running my program, just 
> like when I use DDD to run a regular perl script. However, the question is, 
> how can I use DDD to run on top of this?

You need to change DDD's behavior so that it will debug your script by
running httpd -X.  Check with the DDD folks.  There are some threads in
the archive here about using ptkdb with mod_perl, which might also be
useful to you.

- Perrin