On Mon, 9 Jul 2001, Doug MacEachern wrote:

> On Sun, 8 Jul 2001, Stas Bekman wrote:
>
> >
> > Doug, how do we want to change the start_gdb with a more generic code and
> > decide which debugger is to be used via the command line option and/or env
> > var?
> >
> > I suggest that we have 'debug:s' option, where:
> >
> >  --debug
> >
> > (no value) uses $ENV{MP_DEBUGGER} || 'gdb'. And:
> >
> >  --debug=db_foo
> >
> > uses 'db_foo' if supported and quits with an error if not.
>
> that would be great.
>
> > Anyway, ddd coupled with gdb should be invoked as:
> > my $command = qq{ddd --gdb --debugger "gdb -command $file" 
>$config->{vars}->{httpd}};
> >
> > I use ddd since it's a fantastic tool when you need to debug/learn
> > complicated data structures. Its 'Data' window is very helpful.
>
> i'll have to try ddd one of these days.
>
> > Probably another useful key would be -debug-jump-init or similar which
> > will take  you right into the modperl_hook_init() via the breakpoint. I'm
> > adding your trick notes to modperl_dev.pod, but I think it'd be nice to
> > have the feature in core. I can also think of having a set of jump points
> > to various frequently used breakpoints selected via the debug options, but
> > this can be added later if found useful.
>
> that would be cool too.

Ok here is the patch. Please see one META in it:

This patch adds the following features:

------

--debugger : choose from one of the configured debuggers

e.g.:

  % ./t/TEST -debug -debugger=ddd

or

  % ./t/TEST -debug -debugger=gdb

if none is specified 'gdb' will be used. (Note that currently 'ddd'
internally uses 'gdb').

------

--debug-hook_init : bring the debugger to the 'modperl_hook_init'
function via the breakpoint (internally it first loads the mod_perl
DSO module via 'apr_dso_load' breakpoint.

e.g.:

  % ./t/TEST -debug -debug-hook_init

------

--breakpoint : set as many breakpoint as needed via repeating the key

e.g:

  % ./t/TEST -debug -breakpoint=modperl_cmd_switches \
     -breakpoint=modperl_cmd_options

will set the 'modperl_cmd_switches' and 'modperl_cmd_options'
breakpoints and run the debugger. But first it'll set the
'apr_dso_load' so one can set breakpoints in mod_perl code (which is
not loaded with the server, if compiled as dso).



Index: Apache-Test/lib/Apache/TestRun.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/Apache-Test/lib/Apache/TestRun.pm,v
retrieving revision 1.10
diff -b -u -r1.10 TestRun.pm
--- Apache-Test/lib/Apache/TestRun.pm   2001/06/27 06:21:24     1.10
+++ Apache-Test/lib/Apache/TestRun.pm   2001/07/10 16:57:47
@@ -14,10 +14,10 @@

 my @std_run      = qw(start-httpd run-tests stop-httpd);
 my @others       = qw(verbose configure clean help ping);
-my @flag_opts    = (@std_run, @others);
-my @string_opts  = qw(order);
+my @flag_opts    = (@std_run, @others, 'debug-hook_init');
+my @string_opts  = qw(order debugger);
 my @num_opts     = qw(times);
-my @list_opts    = qw(preamble postamble);
+my @list_opts    = qw(preamble postamble breakpoint);
 my @hash_opts    = qw(header);
 my @exit_opts    = qw(clean help ping debug);
 my @request_opts = qw(get head post);
@@ -36,6 +36,9 @@
    'postamble'   => 'config to add at the end of httpd.conf',
    'ping'        => 'test if server is running or port in use',
    'debug'       => 'start server under debugger (e.g. gdb)',
+   'debugger=name '  => 'run under one of the supported debuggers',
+   'breakpoint=bp'   => 'set breakpoints (multiply bp can be set)',
+   'debug-hook_init' => 'jump to modperl_hook_init on debug',
    'header'      => "add headers to (".join('|', @request_opts).") request",
    (map { $_, "\U$_\E url" } @request_opts),
 );
@@ -120,7 +123,7 @@
     my(%opts, %vopts, %conf_opts);

     GetOptions(\%opts, @flag_opts, @exit_opts,
-               (map "$_=s", @request_opts,@string_opts),
+               (map "$_=s", @request_opts, @string_opts),
                (map "$_=i", @num_opts),
                (map { ("$_=s", $vopts{$_} ||= []) } @list_opts),
                (map { ("$_=s", $vopts{$_} ||= {}) } @hash_opts));
@@ -143,6 +146,9 @@
         $conf_opts{thaw} = 1;
     }

+    # META: should any of 'debugger','breakpoint and 'debug-hook_init'
+    # opts trigger 'debug' mode on? if so should be done here
+
     #propagate some values
     for (qw(verbose)) {
         $conf_opts{$_} = $opts{$_};
@@ -374,8 +380,14 @@
 sub opt_debug {
     my $self = shift;
     my $server = $self->{server};
+
+    my $debug_opts = {};
+    for (qw(debugger breakpoint debug-hook_init)) {
+        $debug_opts->{$_} = $self->{opts}->{$_};
+    }
+
     $server->stop;
-    $server->start_debugger;
+    $server->start_debugger($debug_opts);
 }

 sub opt_help {
Index: Apache-Test/lib/Apache/TestServer.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/Apache-Test/lib/Apache/TestServer.pm,v
retrieving revision 1.10
diff -b -u -r1.10 TestServer.pm
--- Apache-Test/lib/Apache/TestServer.pm        2001/06/24 14:47:44
1.10
+++ Apache-Test/lib/Apache/TestServer.pm        2001/07/10 16:57:47
@@ -9,6 +9,14 @@
 use Apache::TestTrace;
 use Apache::TestConfig ();

+# some debuggers use the same syntax as others, so we reuse the same
+# code by using the following mapping
+my %debuggers =
+    (
+     gdb => 'gdb',
+     ddd => 'gdb',
+    );
+
 sub trace {
     shift->{config}->trace(@_);
 }
@@ -74,6 +82,14 @@

 sub start_gdb {
     my $self = shift;
+    my $opts = shift;
+
+    my $debugger = $opts->{debugger};
+
+    my @breakpoints = @{ $opts->{breakpoint} || [] };
+    if ($opts->{'debug-hook_init'}){
+        unshift @breakpoints, 'modperl_hook_init';
+    }

     my $config = $self->{config};
     my $args = $self->args;
@@ -81,16 +97,48 @@

     my $file = catfile $config->{vars}->{serverroot}, '.gdb-test-start';
     my $fh = $config->genfile($file, 1);
-    print $fh "run $one_process $args";
+
+    if (@breakpoints) {
+        print $fh "b apr_dso_load\n";
+        print $fh "run $one_process $args\n";
+        print $fh "finish\n";
+        for (@breakpoints) {
+            print $fh "b $_\n"
+        }
+        print $fh "continue\n";
+    }
+    else {
+        print $fh "run $one_process $args\n";
+    }
     close $fh;

-    system "gdb $config->{vars}->{httpd} -command $file";
+    my $command;
+    if ($debugger eq 'ddd') {
+        $command = qq{ddd --gdb --debugger "gdb -command $file"  
+$config->{vars}->{httpd}};
+    } else {
+        $command = "gdb $config->{vars}->{httpd} -command $file";
+    }
+
+    debug  $command;
+    system $command;

     unlink $file;
 }

 sub start_debugger {
-    shift->start_gdb; #XXX support dbx and others
+    my $self = shift;
+    my $opts = shift;
+
+    $opts->{debugger} ||= $ENV{MP_DEBUGGER} || 'gdb';
+    my $debugger = $opts->{debugger} || $ENV{MP_DEBUGGER} || 'gdb';
+
+    unless ($debuggers{$debugger}) {
+        error "$debugger is not supported";
+        die();
+    }
+
+    my $method = "start_".$debuggers{$opts->{debugger}};
+    $self->$method($opts);
 }

 sub pid {



_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to