You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by pd...@sodoz.com on 2004/05/05 22:40:08 UTC

Howto use emacs and perldb to debug mod_perl?

Hi,

Has anyone succeeded in using the perldb debugger
within emacs in order to debug apps that use
mod_perl?

The following works:
  /usr/sbin/apache-perl -X -D PERLDB
but then I get the command line debugger.

I know that ptkdb and ddd are other (GUI) options,
but I would like to use emacs.

Thanks in advance
--
Pieter

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Howto use emacs and perldb to debug mod_perl?

Posted by pd...@sodoz.com.
This works for me. Thanks!

I have some suggestions for the pod:

> =head2 Preparing httpd.conf
>
> Now you need to make sure that the SLAVE_EMACS environment variable makes
> it to the perl code that runs inside Apache.  Fortunately this is easy:
>
>      PerlPassEnv SLAVE_EMACS

=head2 Preparing httpd.conf

Now you need to make sure that the SLAVE_EMACS environment variable makes
it to the perl code that runs inside Apache.  Fortunately this is easy,
just add the following to your httpd.conf:

     PerlPassEnv SLAVE_EMACS
     <Perl>
       use Apache::DB ();
       Apache::DB->init;
     </Perl>
     PerlFixupHandler Apache::DB


>      SLAVE_EMACS=1 exec httpd -X -DPERLDB=1
This can also be:
      SLAVE_EMACS=1 exec httpd -X -DPERLDB
(it's a matter of taste)


> =item 3.
> 
> It will prompt you by saying C<Run perldb (like this):>, with a
> default response after the colon.  Instead of the default, type in
> C</home/myacct/httpd-debug dummy>, i.e. the script you prepared above.
> The C<dummy> is a dummy argument to keep emacs happy.

=item 3.

It will prompt you by saying C<Run perldb (like this):>, with a
default response after the colon.  Instead of the default, type in
C</home/myacct/httpd-debug dummy>, i.e. the script you prepared above.
C<dummy> is required by emacs, as part of the name of the debug
window.
ie. For or C<dummy>, the debug window will be called C<*gud-dummy*>.

cu
--
Pieter

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Howto use emacs and perldb to debug mod_perl?

Posted by pd...@sodoz.com.
This works for me. Thanks!

I have some suggestions for the pod:

> =head2 Preparing httpd.conf
>
> Now you need to make sure that the SLAVE_EMACS environment variable makes
> it to the perl code that runs inside Apache.  Fortunately this is easy:
>
>      PerlPassEnv SLAVE_EMACS

=head2 Preparing httpd.conf

Now you need to make sure that the SLAVE_EMACS environment variable makes
it to the perl code that runs inside Apache.  Fortunately this is easy,
just add the following to your httpd.conf:

     PerlPassEnv SLAVE_EMACS
     <Perl>
       use Apache::DB ();
       Apache::DB->init;
     </Perl>
     PerlFixupHandler Apache::DB


>      SLAVE_EMACS=1 exec httpd -X -DPERLDB=1
This can also be:
      SLAVE_EMACS=1 exec httpd -X -DPERLDB
(it's a matter of taste)


> =item 3.
> 
> It will prompt you by saying C<Run perldb (like this):>, with a
> default response after the colon.  Instead of the default, type in
> C</home/myacct/httpd-debug dummy>, i.e. the script you prepared above.
> The C<dummy> is a dummy argument to keep emacs happy.

=item 3.

It will prompt you by saying C<Run perldb (like this):>, with a
default response after the colon.  Instead of the default, type in
C</home/myacct/httpd-debug dummy>, i.e. the script you prepared above.
C<dummy> is required by emacs, as part of the name of the debug
window.
ie. For or C<dummy>, the debug window will be called C<*gud-dummy*>.

cu
--
Pieter

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Howto use emacs and perldb to debug mod_perl?

Posted by pd...@sodoz.com.
This works for me. Thanks!

I have some suggestions for the pod:

> =head2 Preparing httpd.conf
>
> Now you need to make sure that the SLAVE_EMACS environment variable makes
> it to the perl code that runs inside Apache.  Fortunately this is easy:
>
>      PerlPassEnv SLAVE_EMACS

=head2 Preparing httpd.conf

Now you need to make sure that the SLAVE_EMACS environment variable makes
it to the perl code that runs inside Apache.  Fortunately this is easy,
just add the following to your httpd.conf:

     PerlPassEnv SLAVE_EMACS
     <Perl>
       use Apache::DB ();
       Apache::DB->init;
     </Perl>
     PerlFixupHandler Apache::DB


>      SLAVE_EMACS=1 exec httpd -X -DPERLDB=1
This can also be:
      SLAVE_EMACS=1 exec httpd -X -DPERLDB
(it's a matter of taste)


> =item 3.
> 
> It will prompt you by saying C<Run perldb (like this):>, with a
> default response after the colon.  Instead of the default, type in
> C</home/myacct/httpd-debug dummy>, i.e. the script you prepared above.
> The C<dummy> is a dummy argument to keep emacs happy.

=item 3.

It will prompt you by saying C<Run perldb (like this):>, with a
default response after the colon.  Instead of the default, type in
C</home/myacct/httpd-debug dummy>, i.e. the script you prepared above.
C<dummy> is required by emacs, as part of the name of the debug
window.
ie. For or C<dummy>, the debug window will be called C<*gud-dummy*>.

cu
--
Pieter

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Howto use emacs and perldb to debug mod_perl?

Posted by "Paul G. Weiss" <pa...@weiss.name>.
On Thu, 06 May 2004 12:22:49 -0700, Stas Bekman <st...@stason.org> wrote:

> If someone can write a section explaining how to do that properly, I  
> think it'll be a great addition to our docs. Just post the pod here and  
> I'll add it. Thanks.
>
>

OK, I'm not exactly a hand at writing pod but I had a go.  Here it is:

=head1 NAME

perldbemacs - How do debug mod_perl using perldb in Emacs

=head1 DESCRIPTION

The perldb function in Emacs allows you to run the Perl debugger while
viewing the source code in another window.  It is a much nicer environment
for debugging Perl than the plain standalone Perl debugger.  This
is how to use perldb to debug mod_perl code.

=head2 Modifying perl5db.pl

Unfortunately, this requires a modification to perl5db.pl.  First you need
to locate your copy of perl5db.pl.  You can use perldoc to do it:

      perl /usr/bin/perldoc -l Apache::perl5db.pl

or if you're using a specially built perl:

      /my/perl `which perldoc`  -l Apache::perl5db.pl

it will print out something like this:

      /usr/lib/perl5/site_perl/5.8.1/i386-linux-thread-multi/Apache/perl5db.pl

That's the file you need to edit.  Locate the line:

      $rl = 0, shift (@main::ARGV) if $slave_editor;

and right before it insert the line

      $slave_editor ||= $ENV{SLAVE_EMACS};


=head2 Preparing httpd.conf

Now you need to make sure that the SLAVE_EMACS environment variable makes
it to the perl code that runs inside Apache.  Fortunately this is easy:

      PerlPassEnv SLAVE_EMACS

=head2 Your debugging script

Prepare a script for debugging.  Call it, say, C</home/myacct/httpd-debug>.
It should go something like this:

      #!/bin/sh
      SLAVE_EMACS=1 exec httpd -X -DPERLDB=1

That is, of course, assuming that your mod_perl httpd is on the C<PATH>

=head2 Starting the debugger

=over 4

=item 1.

Launch emacs.

=item 2.

Run the perldb function (Alt-X perldb)

=item 3.

It will prompt you by saying C<Run perldb (like this):>, with a
default response after the colon.  Instead of the default, type in
C</home/myacct/httpd-debug dummy>, i.e. the script you prepared above.
The C<dummy> is a dummy argument to keep emacs happy.

=item 4.

You should now be running the debugger.

=back

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Howto use emacs and perldb to debug mod_perl?

Posted by Stas Bekman <st...@stason.org>.
Paul G. Weiss wrote:
> On Thu, 6 May 2004 16:12:16 +0000, <pd...@sodoz.com> wrote:
> 
>> James Moore claimed to have gotten it right:
>> http://groups.google.ch/groups?q=emacs+mod_perl&hl=en&lr=lang_en|lang_de&ie=UTF-8&oe=UTF-8&selm=1051404465.5094 
>>
>> +85%40yasure&rnum=1
>>
>> It partially works for me. The last part doesn't:
>>
>>> James Moore wrote:
>>> Not elegant, but it does get you full functionality (or at least the  
>>> only
>>> bit I cared about, the => pointer into your code buffer for the 
>>> current  line
>>> of execution).
>>
>>
> 
> His method ruins it if you want to run the debugger w/o emacs.
> Here's a modification that gets around that problem:
> 
> in the Apache/perl5db.pl file add the line:
> 
>     $slave_editor ||= $ENV{SLAVE_EMACS};
> 
> right after the assignment to $slave_editor.
> 
> Then in your httpd.conf add the line:
> PerlPassEnv SLAVE_EMACS
> 
> And in the script you pass to emacs when it says Run perldb (like this):
> 
> SLAVE_EMACS=1 exec httpd -X -DPERLDB

If someone can write a section explaining how to do that properly, I think 
it'll be a great addition to our docs. Just post the pod here and I'll add it. 
Thanks.


-- 
__________________________________________________________________
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

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Howto use emacs and perldb to debug mod_perl?

Posted by "Paul G. Weiss" <pa...@weiss.name>.
On Thu, 6 May 2004 16:12:16 +0000, <pd...@sodoz.com> wrote:

> James Moore claimed to have gotten it right:
> http://groups.google.ch/groups?q=emacs+mod_perl&hl=en&lr=lang_en|lang_de&ie=UTF-8&oe=UTF-8&selm=1051404465.5094
> +85%40yasure&rnum=1
>
> It partially works for me. The last part doesn't:
>> James Moore wrote:
>> Not elegant, but it does get you full functionality (or at least the  
>> only
>> bit I cared about, the => pointer into your code buffer for the current  
>> line
>> of execution).
>

His method ruins it if you want to run the debugger w/o emacs.
Here's a modification that gets around that problem:

in the Apache/perl5db.pl file add the line:

     $slave_editor ||= $ENV{SLAVE_EMACS};

right after the assignment to $slave_editor.

Then in your httpd.conf add the line:
PerlPassEnv SLAVE_EMACS

And in the script you pass to emacs when it says Run perldb (like this):

SLAVE_EMACS=1 exec httpd -X -DPERLDB


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Howto use emacs and perldb to debug mod_perl?

Posted by pd...@sodoz.com.
James Moore claimed to have gotten it right:
http://groups.google.ch/groups?q=emacs+mod_perl&hl=en&lr=lang_en|lang_de&ie=UTF-8&oe=UTF-8&selm=1051404465.5094
+85%40yasure&rnum=1

It partially works for me. The last part doesn't:
> James Moore wrote:
> Not elegant, but it does get you full functionality (or at least the only
> bit I cared about, the => pointer into your code buffer for the current line
> of execution).

Now for some answers:

> Doesn't Emacs just use the running perl debugger and redisplay it's output?
Yes, with a normal perl script this works, but I have to run
a binary (apache), and this spawns the perl5db.pl script.

> Does it do it by pid?
No, it parses the output of Apache::DB.

> Do you get some kind of error message from Emacs?
Emacs has a command M-x perldb, which only accepts
a perl script as argument. I can't pass a perl script,
because it's a binary. So I could not even ask emacs
to do anything, hence no error message.

In the mean time I used a fifo (with mkfifo)
and got the apache output into emacs, using |fifo.
Somehow gud refused to deal with this (I guess as
the pipe is only one-directional).

Another idea is to copy some of Devel::ptkdb and
make a Devel::emacs (name?) and use emacsclient.

cu
--
Pieter

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Howto use emacs and perldb to debug mod_perl?

Posted by Frank Wiles <fr...@wiles.org>.
On Wed, 5 May 2004 20:40:08 +0000
pdupreez@sodoz.com wrote:

> Hi,
> 
> Has anyone succeeded in using the perldb debugger
> within emacs in order to debug apps that use
> mod_perl?
> 
> The following works:
>   /usr/sbin/apache-perl -X -D PERLDB
> but then I get the command line debugger.
> 
> I know that ptkdb and ddd are other (GUI) options,
> but I would like to use emacs.
> 
> Thanks in advance

  Not being an Emacs user, no I haven't tried that.  Doesn't Emacs
  just use the running perl debugger and redisplay it's output? 
  Does it do it by pid?  Do you get some kind of error message from 
  Emacs? 

  I've always just used it in the shell I launched the Apache process
  from. If you get me some more info about the problem you're seeing
  I'll play around with Emacs and see if I can get it to work for you. 

 ---------------------------------
   Frank Wiles <fr...@wiles.org>
   http://frank.wiles.org
 ---------------------------------


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html