You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2001/07/07 18:20:36 UTC

TestServer::start_gdb

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.

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.

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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: TestServer::start_gdb

Posted by Stas Bekman <st...@stason.org>.
On Thu, 19 Jul 2001, Doug MacEachern wrote:

> looks great stas, feel free to commit.
> there's just one style nit
> if () {
> } else {
> }
> which should be:
> if () {
> else {
> }

doh! habits, habits

I'd install per-commit filter to croak on the '} else {' pattern :)

thanks for reminder

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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: TestServer::start_gdb

Posted by Doug MacEachern <do...@covalent.net>.
looks great stas, feel free to commit.
there's just one style nit
if () {
} else {
}
which should be:
if () {
else {
}



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: TestServer::start_gdb

Posted by Stas Bekman <st...@stason.org>.
the previous patch had a flow :( (always started gdb)
here is a correct one:

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 -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/19 16:28:56
@@ -16,27 +16,30 @@
 my @others       = qw(verbose configure clean help ping);
 my @flag_opts    = (@std_run, @others);
 my @string_opts  = qw(order);
+my @debug_opts   = qw(debug);
 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 @help_opts    = qw(clean help ping);
+my @exit_opts    = (@help_opts,@debug_opts);
 my @request_opts = qw(get head post);

 my %usage = (
-   'start-httpd' => 'start the test server',
-   'run-tests'   => 'run the tests',
-   'times=N'     => 'repeat the tests N times',
-   'order=mode'  => 'run the tests in one of the modes: (repeat|rotate|random)',
-   'stop-httpd'  => 'stop the test server',
-   'verbose'     => 'verbose output',
-   'configure'   => 'force regeneration of httpd.conf',
-   'clean'       => 'remove all generated test files',
-   'help'        => 'display this message',
-   'preamble'    => 'config to add at the beginning of httpd.conf',
-   '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)',
-   'header'      => "add headers to (".join('|', @request_opts).") request",
+   'start-httpd'     => 'start the test server',
+   'run-tests'       => 'run the tests',
+   'times=N'         => 'repeat the tests N times',
+   'order=mode'      => 'run the tests in one of the modes: (repeat|rotate|random)',
+   'stop-httpd'      => 'stop the test server',
+   'verbose'         => 'verbose output',
+   'configure'       => 'force regeneration of httpd.conf',
+   'clean'           => 'remove all generated test files',
+   'help'            => 'display this message',
+   'preamble'        => 'config to add at the beginning of httpd.conf',
+   'postamble'       => 'config to add at the end of httpd.conf',
+   'ping'            => 'test if server is running or port in use',
+   'debug[=name]'    => 'start server under debugger name (e.g. gdb, ddd, ...)',
+   'breakpoint=bp'   => 'set breakpoints (multiply bp can be set)',
+   'header'          => "add headers to (".join('|', @request_opts).") request",
    (map { $_, "\U$_\E url" } @request_opts),
 );

@@ -119,8 +122,9 @@
     local *ARGV = $self->{args};
     my(%opts, %vopts, %conf_opts);

-    GetOptions(\%opts, @flag_opts, @exit_opts,
-               (map "$_=s", @request_opts,@string_opts),
+    GetOptions(\%opts, @flag_opts, @help_opts,
+               (map "$_:s", @debug_opts),
+               (map "$_=s", @request_opts, @string_opts),
                (map "$_=i", @num_opts),
                (map { ("$_=s", $vopts{$_} ||= []) } @list_opts),
                (map { ("$_=s", $vopts{$_} ||= {}) } @hash_opts));
@@ -136,6 +140,16 @@
        $conf_opts{lc $key} = $val;
     }

+    if (exists $opts{debug}) {
+        $opts{debugger} = $opts{debug};
+        $opts{debug} = 1;
+    }
+
+    # breakpoint automatically turns the debug mode on
+    if (@{ $opts{breakpoint} }) {
+        $opts{debug} ||= 1;
+    }
+
     if ($opts{configure}) {
         $conf_opts{save} = 1;
     }
@@ -374,8 +388,14 @@
 sub opt_debug {
     my $self = shift;
     my $server = $self->{server};
+
+    my $debug_opts = {};
+    for (qw(debugger breakpoint)) {
+        $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.11
diff -u -r1.11 TestServer.pm
--- Apache-Test/lib/Apache/TestServer.pm	2001/07/17 15:30:38	1.11
+++ Apache-Test/lib/Apache/TestServer.pm	2001/07/19 16:28:57
@@ -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,23 +82,59 @@

 sub start_gdb {
     my $self = shift;
+    my $opts = shift;

-    my $config = $self->{config};
-    my $args = $self->args;
+    my $debugger    = $opts->{debugger};
+    my @breakpoints = @{ $opts->{breakpoint} || [] };
+    my $config      = $self->{config};
+    my $args        = $self->args;
     my $one_process = $self->version_of(\%one_process);

     my $file = catfile $config->{vars}->{serverroot}, '.gdb-test-start';
-    my $fh = $config->genfile($file, 1);
-    print $fh "run $one_process $args";
+    my $fh   = $config->genfile($file, 1);
+
+    if (@breakpoints) {
+        print $fh "b ap_run_pre_config\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';
+
+    unless ($debuggers{ $opts->{debugger} }) {
+        error "$opts->{debugger} is not a supported debugger",
+              "These are the supported debuggers: ".
+              join ", ", sort keys %debuggers;
+        die("\n");
+    }
+
+    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:stas@stason.org   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: TestServer::start_gdb

Posted by Stas Bekman <st...@stason.org>.
On Wed, 18 Jul 2001, Doug MacEachern wrote:

> On Thu, 19 Jul 2001, Stas Bekman wrote:
>
> > now -debug will always set the apr_dso_load and modperl_hook_init bp and
> > run after these.
>
> i think you misunderstood my comment before.  no breakpoints should
> be set by default, only when -breakpoint is specified.  and rather than
> using apr_dso_load to wait until modperl is loaded, you should use
> ap_run_pre_config since there might be more dso's besides modperl being
> loaded.  after applying your patch, i get:
> Global symbol "$debugger" requires explicit package name at
> Apache-Test/lib/Apache/TestServer.pm line 133.
>
> needs to be $opts->{debugger} instead.  otherwise works great, this is a
> really cool feature!

:)

Here is another try:

This patch adds the following features:

--- 1 ---

one of the supported debuggers can be invoked via the -debug switch:

e.g.: run with the defaults: gdb

  % ./t/TEST -debug

or use ddd:

  % ./t/TEST -debug=ddd

Note that currently we tell 'ddd' to internally use 'gdb'.

--- 2 ---

--breakpoint : set as many breakpoint as needed by 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
'ap_run_pre_config' breakpoint and run till there, since without it we
cannot set breakpoints in mod_perl code if it's loaded via DSO.

If you want to tell the debugger to jump to the start of the mod_perl
code you may run:

  % ./t/TEST -debug -breakpoint=modperl_hook_init

In fact --breakpoint automatically turns on the debug mode, so you can
run:

  % ./t/TEST -breakpoint=modperl_hook_init

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 -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/19 15:51:52
@@ -16,27 +16,30 @@
 my @others       = qw(verbose configure clean help ping);
 my @flag_opts    = (@std_run, @others);
 my @string_opts  = qw(order);
+my @debug_opts   = qw(debug);
 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 @help_opts    = qw(clean help ping);
+my @exit_opts    = (@help_opts,@debug_opts);
 my @request_opts = qw(get head post);

 my %usage = (
-   'start-httpd' => 'start the test server',
-   'run-tests'   => 'run the tests',
-   'times=N'     => 'repeat the tests N times',
-   'order=mode'  => 'run the tests in one of the modes: (repeat|rotate|random)',
-   'stop-httpd'  => 'stop the test server',
-   'verbose'     => 'verbose output',
-   'configure'   => 'force regeneration of httpd.conf',
-   'clean'       => 'remove all generated test files',
-   'help'        => 'display this message',
-   'preamble'    => 'config to add at the beginning of httpd.conf',
-   '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)',
-   'header'      => "add headers to (".join('|', @request_opts).") request",
+   'start-httpd'     => 'start the test server',
+   'run-tests'       => 'run the tests',
+   'times=N'         => 'repeat the tests N times',
+   'order=mode'      => 'run the tests in one of the modes: (repeat|rotate|random)',
+   'stop-httpd'      => 'stop the test server',
+   'verbose'         => 'verbose output',
+   'configure'       => 'force regeneration of httpd.conf',
+   'clean'           => 'remove all generated test files',
+   'help'            => 'display this message',
+   'preamble'        => 'config to add at the beginning of httpd.conf',
+   'postamble'       => 'config to add at the end of httpd.conf',
+   'ping'            => 'test if server is running or port in use',
+   'debug[=name]'    => 'start server under debugger name (e.g. gdb, ddd, ...)',
+   'breakpoint=bp'   => 'set breakpoints (multiply bp can be set)',
+   'header'          => "add headers to (".join('|', @request_opts).") request",
    (map { $_, "\U$_\E url" } @request_opts),
 );

@@ -119,8 +122,9 @@
     local *ARGV = $self->{args};
     my(%opts, %vopts, %conf_opts);

-    GetOptions(\%opts, @flag_opts, @exit_opts,
-               (map "$_=s", @request_opts,@string_opts),
+    GetOptions(\%opts, @flag_opts, @help_opts,
+               (map "$_:s", @debug_opts),
+               (map "$_=s", @request_opts, @string_opts),
                (map "$_=i", @num_opts),
                (map { ("$_=s", $vopts{$_} ||= []) } @list_opts),
                (map { ("$_=s", $vopts{$_} ||= {}) } @hash_opts));
@@ -136,6 +140,16 @@
        $conf_opts{lc $key} = $val;
     }

+    if (exists $opts{debug}) {
+        $opts{debugger} = $opts{debug};
+        $opts{debug} = 1;
+    }
+
+    # breakpoint automatically turns the debug mode on
+    if (exists $opts{breakpoint}) {
+        $opts{debug} ||= 1;
+    }
+
     if ($opts{configure}) {
         $conf_opts{save} = 1;
     }
@@ -374,8 +388,14 @@
 sub opt_debug {
     my $self = shift;
     my $server = $self->{server};
+
+    my $debug_opts = {};
+    for (qw(debugger breakpoint)) {
+        $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.11
diff -u -r1.11 TestServer.pm
--- Apache-Test/lib/Apache/TestServer.pm	2001/07/17 15:30:38	1.11
+++ Apache-Test/lib/Apache/TestServer.pm	2001/07/19 15:51:53
@@ -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,23 +82,59 @@

 sub start_gdb {
     my $self = shift;
+    my $opts = shift;

-    my $config = $self->{config};
-    my $args = $self->args;
+    my $debugger    = $opts->{debugger};
+    my @breakpoints = @{ $opts->{breakpoint} || [] };
+    my $config      = $self->{config};
+    my $args        = $self->args;
     my $one_process = $self->version_of(\%one_process);

     my $file = catfile $config->{vars}->{serverroot}, '.gdb-test-start';
-    my $fh = $config->genfile($file, 1);
-    print $fh "run $one_process $args";
+    my $fh   = $config->genfile($file, 1);
+
+    if (@breakpoints) {
+        print $fh "b ap_run_pre_config\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';
+
+    unless ($debuggers{ $opts->{debugger} }) {
+        error "$opts->{debugger} is not a supported debugger",
+              "These are the supported debuggers: ".
+              join ", ", sort keys %debuggers;
+        die("\n");
+    }
+
+    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:stas@stason.org   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: TestServer::start_gdb

Posted by Doug MacEachern <do...@covalent.net>.
On Thu, 19 Jul 2001, Stas Bekman wrote:

> now -debug will always set the apr_dso_load and modperl_hook_init bp and
> run after these.

i think you misunderstood my comment before.  no breakpoints should
be set by default, only when -breakpoint is specified.  and rather than
using apr_dso_load to wait until modperl is loaded, you should use
ap_run_pre_config since there might be more dso's besides modperl being
loaded.  after applying your patch, i get:
Global symbol "$debugger" requires explicit package name at
Apache-Test/lib/Apache/TestServer.pm line 133.

needs to be $opts->{debugger} instead.  otherwise works great, this is a
really cool feature!



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: TestServer::start_gdb

Posted by Stas Bekman <st...@stason.org>.
This patch adds the following features:

------

now -debug will always set the apr_dso_load and modperl_hook_init bp and
run after these.

------

run with the defaults: gdb

  % ./t/TEST -debug

or use ddd (and later on some other debuggers):

  % ./t/TEST -debug[=]ddd

Note that currently I tell 'ddd' to internally use 'gdb'.

------

--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 -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/18 15:57:51
@@ -16,27 +16,30 @@
 my @others       = qw(verbose configure clean help ping);
 my @flag_opts    = (@std_run, @others);
 my @string_opts  = qw(order);
+my @debug_opts   = qw(debug);
 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 @help_opts    = qw(clean help ping);
+my @exit_opts    = (@help_opts,@debug_opts);
 my @request_opts = qw(get head post);

 my %usage = (
-   'start-httpd' => 'start the test server',
-   'run-tests'   => 'run the tests',
-   'times=N'     => 'repeat the tests N times',
-   'order=mode'  => 'run the tests in one of the modes: (repeat|rotate|random)',
-   'stop-httpd'  => 'stop the test server',
-   'verbose'     => 'verbose output',
-   'configure'   => 'force regeneration of httpd.conf',
-   'clean'       => 'remove all generated test files',
-   'help'        => 'display this message',
-   'preamble'    => 'config to add at the beginning of httpd.conf',
-   '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)',
-   'header'      => "add headers to (".join('|', @request_opts).") request",
+   'start-httpd'     => 'start the test server',
+   'run-tests'       => 'run the tests',
+   'times=N'         => 'repeat the tests N times',
+   'order=mode'      => 'run the tests in one of the modes: (repeat|rotate|random)',
+   'stop-httpd'      => 'stop the test server',
+   'verbose'         => 'verbose output',
+   'configure'       => 'force regeneration of httpd.conf',
+   'clean'           => 'remove all generated test files',
+   'help'            => 'display this message',
+   'preamble'        => 'config to add at the beginning of httpd.conf',
+   'postamble'       => 'config to add at the end of httpd.conf',
+   'ping'            => 'test if server is running or port in use',
+   'debug[=name]'    => 'start server under debugger name (e.g. gdb, ddd, ...)',
+   'breakpoint=bp'   => 'set breakpoints (multiply bp can be set)',
+   'header'          => "add headers to (".join('|', @request_opts).") request",
    (map { $_, "\U$_\E url" } @request_opts),
 );

@@ -119,8 +122,9 @@
     local *ARGV = $self->{args};
     my(%opts, %vopts, %conf_opts);

-    GetOptions(\%opts, @flag_opts, @exit_opts,
-               (map "$_=s", @request_opts,@string_opts),
+    GetOptions(\%opts, @flag_opts, @help_opts,
+               (map "$_:s", @debug_opts),
+               (map "$_=s", @request_opts, @string_opts),
                (map "$_=i", @num_opts),
                (map { ("$_=s", $vopts{$_} ||= []) } @list_opts),
                (map { ("$_=s", $vopts{$_} ||= {}) } @hash_opts));
@@ -136,6 +140,11 @@
        $conf_opts{lc $key} = $val;
     }

+    if (exists $opts{debug}) {
+        $opts{debugger} = $opts{debug};
+        $opts{debug} = 1;
+    }
+
     if ($opts{configure}) {
         $conf_opts{save} = 1;
     }
@@ -143,6 +152,9 @@
         $conf_opts{thaw} = 1;
     }

+    # META: should the 'breakpoint' opt trigger 'debug' mode on? if so
+    # should be done here
+
     #propagate some values
     for (qw(verbose)) {
         $conf_opts{$_} = $opts{$_};
@@ -374,8 +386,14 @@
 sub opt_debug {
     my $self = shift;
     my $server = $self->{server};
+
+    my $debug_opts = {};
+    for (qw(debugger breakpoint)) {
+        $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.11
diff -u -r1.11 TestServer.pm
--- Apache-Test/lib/Apache/TestServer.pm	2001/07/17 15:30:38	1.11
+++ Apache-Test/lib/Apache/TestServer.pm	2001/07/18 15:57:52
@@ -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,23 +82,62 @@

 sub start_gdb {
     my $self = shift;
+    my $opts = shift;
+
+    my $debugger = $opts->{debugger};

+    my @breakpoints = @{ $opts->{breakpoint} || [] };
+    unshift @breakpoints, 'modperl_hook_init';
+
     my $config = $self->{config};
     my $args = $self->args;
     my $one_process = $self->version_of(\%one_process);

     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';
+
+    unless ($debuggers{ $opts->{debugger} }) {
+        error "$debugger is not a supported debugger",
+              "These are the supported debuggers: ".
+              join ", ", sort keys %debuggers;
+        die("\n");
+    }
+
+    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:stas@stason.org   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: TestServer::start_gdb

Posted by Stas Bekman <st...@stason.org>.
On Sun, 15 Jul 2001, Doug MacEachern wrote:

> On Sat, 14 Jul 2001, Stas Bekman wrote:
>
> > doable. I know you don't want to lose -d shortcut :)
>
> yeah :)
>
> > I'm not sure what's the definition of 'always'. There are cases where you
> > run -d to debug the segfault and you want the debugger to 'run' till the
> > segfault without any breakpoints. Whereas in other cases you want to debug
> > during the development and that's when the use of apr_dso_load becomes
> > useful.
>
> by 'always' i meant whenever there is a -breakpoint, it should get set at
> ap_init_modules.  rather than have a special case -debug-hook_init, you
> would just say -breakpoint modperl_hook_init

ok

> > What I'm trying to tell is that by default the -d behavior should probably
> > just run the server, and some other flag to turn on the development mode.
>
> remind me what is development mode again, just turning up the trace level
> or more stuff?

I'm thinking about these 2 modes:

user mode:

  Running mod_perl under debugger to get the segfault trace
  and send it to the list.
  => the invocation should be as simple as possible (read: -d)

devel mode:

  Running mod_perl under debugger during the process of adding new
  features and debugging existing ones.
  => the invocation can be more complex (read: more command line options)

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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: TestServer::start_gdb

Posted by Doug MacEachern <do...@covalent.net>.
On Sat, 14 Jul 2001, Stas Bekman wrote:
 
> doable. I know you don't want to lose -d shortcut :)

yeah :)
 
> I'm not sure what's the definition of 'always'. There are cases where you
> run -d to debug the segfault and you want the debugger to 'run' till the
> segfault without any breakpoints. Whereas in other cases you want to debug
> during the development and that's when the use of apr_dso_load becomes
> useful.

by 'always' i meant whenever there is a -breakpoint, it should get set at
ap_init_modules.  rather than have a special case -debug-hook_init, you
would just say -breakpoint modperl_hook_init

> What I'm trying to tell is that by default the -d behavior should probably
> just run the server, and some other flag to turn on the development mode.

remind me what is development mode again, just turning up the trace level
or more stuff?





---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: TestServer::start_gdb

Posted by Stas Bekman <st...@stason.org>.
On Fri, 13 Jul 2001, Doug MacEachern wrote:

> On Wed, 11 Jul 2001, Stas Bekman wrote:
>
> >   % ./t/TEST -debug -debugger=ddd
>
> how about reusing the current -debug: t/TEST -d ddd ?

doable. I know you don't want to lose -d shortcut :)

> > --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
>
> i'd rather not have a special case for this, but instead always set
> breakpoints after apr_dso_load, or better yet at ap_init_modules which
> will work for both dso and static (i think)

I'm not sure what's the definition of 'always'. There are cases where you
run -d to debug the segfault and you want the debugger to 'run' till the
segfault without any breakpoints. Whereas in other cases you want to debug
during the development and that's when the use of apr_dso_load becomes
useful.

What I'm trying to tell is that by default the -d behavior should probably
just run the server, and some other flag to turn on the development mode.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: TestServer::start_gdb

Posted by Doug MacEachern <do...@covalent.net>.
On Wed, 11 Jul 2001, Stas Bekman wrote:
 
>   % ./t/TEST -debug -debugger=ddd

how about reusing the current -debug: t/TEST -d ddd ?

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

i'd rather not have a special case for this, but instead always set
breakpoints after apr_dso_load, or better yet at ap_init_modules which
will work for both dso and static (i think)

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

nice!


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: TestServer::start_gdb

Posted by Stas Bekman <st...@stason.org>.
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:stas@stason.org   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: TestServer::start_gdb

Posted by Doug MacEachern <do...@covalent.net>.
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.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org