Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Enabling GUI Debugging under Mod_Perl

by mkirank (Chaplain)
on Dec 03, 2004 at 13:44 UTC ( [id://412121]=perltutorial: print w/replies, xml ) Need Help??

Greetings
I Did the following to Enable GUI Debugging of Mod_Perl (Apache::Registry) scripts (I got this Information from different places ) ,
I have documented the steps followed and want to put it under the appropriate section (Suggest appropriate section) in perlmonks ,
This is my first attempt to writing a Setup Guide so am seeking the wise monks Inputs on the same.
Please let me know your Feedback/Opinions and any suggestions

Steps Followed


Installed the following packages from CPAN
1.Tk Graphical User Interface ToolKit from CPAN (Tk-804.027.tar)
2. Installed the Apache-DB-0.09
3. Installed the Devel-ptkdb-1.1091.tar.gz

Open the Apache::DB.pm file and change
#require 'Apache/perl5db.pl'; Comment this line
require 'Devel/ptkdb.pm';

Save the below code as file Db.patch


################################################################# --- DB.pm 2003/07/23 16:59:07 1.1 +++ DB.pm 2003/07/23 17:03:29 @@ -39,6 +39,34 @@ return 0; } + +sub ptkdb ($$) { + my ($class,$r) = @_; + + init(); + + # need to have a list of authorized remote hosts + $ENV{DISPLAY} = $r->get_remote_host.':0.0'; + $DB::connection_refused = 0; # try try again + require 'Devel/ptkdb.pm'; + $DB::single = 1; +# bug workaround? Pressing "Return" button at toplevel makes ptkdb h +ang. + $DB::subroutine_depth = 0 ; + $DB::step_over_depth = -1 ; + + if (ref $r) { + $SIG{INT} = \&DB::dbint_handler; + $r->register_cleanup(sub { + $SIG{INT} = \&DB::ApacheSIGINT(); + $DB::single = 0; # do not debug during withdraw + $DB::window->close_ptkdb_window; + }); + } + + return 0; +} + + 1; __END__ #################################################################

Save the below code as file Ptkdb.patch


################################################################# --- ptkdb.pm 2003/07/23 17:05:20 1.1 +++ ptkdb.pm 2003/07/23 17:51:09 @@ -1105,8 +1105,21 @@ # Main Window - +eval { $self->{main_window} = MainWindow->new() ; +}; +if ($@) { + my $err = $@; + my $r = eval { Apache->request }; # check if running under mod_per +l + undef $@; + if ($r && $err =~ m/Xlib: connection .*? refused|Xlib: Client is no +t authorized|couldn't connect to display/) { + $DB::connection_refused = 1; + $self->{main_window} = undef; + warn($err); # log the problem + return; + } + die $err; +} $self->{main_window}->geometry($ENV{'PTKDB_GEOMETRY'} || "800x600") + ; $self->setup_options() ; # must be done after MainWindow and before + other frames are setup @@ -1237,8 +1250,9 @@ $DB::window->{'event'} = 'run' ; $self->{current_file} = "" ; # force a file reset - $self->{'main_window'}->destroy ; + $self->{'main_window'}->destroy if $self->{'main_window'}; $self->{'main_window'} = undef ; + $DB::connection_refused = undef; # allow another try } sub setup_menu_bar { @@ -4048,7 +4062,12 @@ $^W = $saveW ; unless( $DB::ptkdb::isInitialized ) { - return if( $filename ne $0 ) ; # not in our target file + if ( $filename ne $0 ) { # not in our target file + # check if running under mod_perl + my $r = eval { Apache->request }; + undef $@; + return unless $r; + } &DB::Initialize($filename) ; } @@ -4063,6 +4082,11 @@ return ; } + if ( $DB::connection_refused ) { # X to remote host failed + $@ = $DB::save_err ; + return ; + } + $DB::window->setup_main_window() unless $DB::window->{'main_window'} + ; $DB::window->EnterActions() ; #################################################################

Install the DB.pm Patch


Note Find the path of DB.pm and ptkdb.pm (on Linux You can use Locate command)
patch <PATH ON SYSTEM>/Apache/DB.pm < Db.patch
Install the ptkdb patch
patch <PATH ON SYSTEM>/Devel/ptkdb.pm < Ptkdb.patch


Add the Following Lines in Httpd.conf
<IfDefine PERLDB> <Perl> use Apache::DB (); Apache::DB->init; </Perl> <Location /> PerlFixupHandler Apache::DB->ptkdb </Location> </IfDefine>

Start the Httpd with the Following Command (this starts apache in a Single mode)
/usr/local/apache/bin/httpd -X -D PERLDB

Enable the X-Windows (there are some security considerations ..man xhost for more details.) xhost +
When a request is sent the GUI pops up and we can go through the script (for the scripts that we run under Apache::Registry )
We need to step in on the below Line below
eval & {$cv}($r, @_) } if $r->seqno;

If your server is Linux and u are working on Windows you can do the same by using xterm

Install cygwin

Open cygwin
export DISPLAY=localhost:0.0
X -multiwindow &
xhost +
xterm -display localhost:0 &
ssh -X -l root <LINUX SERVER>
export DISPLAY=localhost:0.0
xhost +

2004-12-03 Janitored by Arunbear - added readmore tags, as per Monastery guidelines

Updated Steve_p - moved to Tutorials per consideration

Replies are listed 'Best First'.
Re: Enabling GUI Debugging under Mod_Perl
by chb (Deacon) on Dec 06, 2004 at 09:16 UTC
    Maybe a sentence about the security implications of 'xhost +' would be appropriate (at least read 'man xhost'). You'll definitively want to turn it off after your development session, as everyone will be able to open windows on your screen...
Re: Enabling GUI Debugging under Mod_Perl
by zentara (Archbishop) on Dec 03, 2004 at 14:07 UTC
    Maybe Tutorials ?

    I'm not really a human, but I play one on earth. flash japh
      A tutorial full of patches? That doesn't look nice. WHats wrong with a tarball?
Why not use ddd?
by mjg (Scribe) on Oct 14, 2005 at 01:28 UTC
    Why not just use GNU DDD rather than all this Tk and patching junk?
      ptkdb allows you to debug CGI scripts running on the server, by adding something to the shebang line. DDD does not. DDD requires you to essentially debug Apache, which results in debugging ALL scripts on the machine.

      I've been using ptkdb to debug CGI scripts for about six months. When I saw your reference to DDD, I took a look. It's a pretty slick program. Unfortunately, if you're needing to debug something running on a web server, forget it.

      That would be why.

      Alternately, if you know how to get DDD to pop up a debugging window to debug a particular script running on a server (not necessarily ALL scripts on the server), please enlighten us.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perltutorial [id://412121]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-28 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found