Mailing List Archive

Perl debugger
I have a little problem with the Perl debugger. When I eval some code
and then execute it, the debugger tell me:

main::foo((eval 1):2): DB<1>

So it knows that it's in line 2 of the first eval'ed thing but it does
not show me the contents of the line. Similarly, the 'l' command does
not show anything.

Would it be possible to enhance the debugger so that it keeps in
memory the things that it evals in order to show the lines?

Lionel Cons

+------- CERN - European Laboratory for Particle Physics ------+
| E-mail: Lionel.Cons@cern.ch PGP key ID: D3CFFDA5 |
| Earth-mail: CN/DCI/UWS, CERN, CH-1211 GENEVE 23, Switzerland |
| Phone: + (41 22) 767 49 13 Fax: + (41 22) 767 71 55 |
+--------------------------------------------------------------+

#!/usr/local/bin/perl5
@x=('no bawujts','mx ypihtre','ercqkg lah');
@y=(793633,793634,793633);
$x=join('',grep(eval("\$_*=97,tr/0-9/$x[$x++]/"),@y));
print "\u$x!\n";
Re: Perl debugger [ In reply to ]
Lionel Cons writes:
>
> I have a little problem with the Perl debugger. When I eval some code
> and then execute it, the debugger tell me:
>
> main::foo((eval 1):2): DB<1>
>
> So it knows that it's in line 2 of the first eval'ed thing but it does
> not show me the contents of the line. Similarly, the 'l' command does
> not show anything.
>
> Would it be possible to enhance the debugger so that it keeps in
> memory the things that it evals in order to show the lines?
>
> Lionel Cons
>

It would be great if we could try to reproduce your problems
here. Maybe it is the time to upgrade your perl/perldb? If your perl
is not very ancient, try perldb-kit from CPAN.

Ilya
Re: Perl debugger [ In reply to ]
Ilya Zakharevich writes:
>
> It would be great if we could try to reproduce your problems
> here. Maybe it is the time to upgrade your perl/perldb? If your perl
> is not very ancient, try perldb-kit from CPAN.

I tried with perl5db-kit-0.92 and still see the same thing.

Consider for instance the program:

$c = <<'EOC';
sub foo {
print "hello\n";
$x = 7;
print "\$x = $x\n";
}
EOC

eval($c);
die $@ if $@;

&foo;

When I debug it I get:

# perl -d /tmp/p

Loading DB routines from $RCSfile: perl5db.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:07 $
Emacs support available.

Enter h or `h h' for help.

main::(/tmp/p:1): $c = <<'EOC';
main::(/tmp/p:2): sub foo {
main::(/tmp/p:3): print "hello\n";
main::(/tmp/p:4): $x = 7;
main::(/tmp/p:5): print "\$x = $x\n";
DB<1> n
main::(/tmp/p:9): eval($c);
DB<1> n
main::(/tmp/p:10): die $@ if $@;
DB<1>
main::(/tmp/p:12): &foo;
DB<1> s
main::foo((eval 4):2): DB<1>
hello
main::foo((eval 4):3): DB<1>
main::foo((eval 4):4): DB<1> l
DB<1>

So I don't see the contents of the line being executed. I would
prefer:

main::foo((eval 4):2): print "hello\n";

And I can't list with the command 'l'...

This enhancement would be very useful for the project that I'm working
on... I can even help to fix perl5db.pl...

Lionel Cons

+------- CERN - European Laboratory for Particle Physics ------+
| E-mail: Lionel.Cons@cern.ch PGP key ID: D3CFFDA5 |
| Earth-mail: CN/DCI/UWS, CERN, CH-1211 GENEVE 23, Switzerland |
| Phone: + (41 22) 767 49 13 Fax: + (41 22) 767 71 55 |
+--------------------------------------------------------------+

#!/usr/local/bin/perl
$_=unpack("B*",pack("N*",1432833413,3483503405,3232917200,296530432));
s/(\d)(.)(.)(.)?(.)?/("!","a".."z"," ")[($1<<4)+($2<<3)+($3<<2)+($4<<1)+$5]/eg;
print "\u$_\n";
Re: Perl debugger [ In reply to ]
Lionel Cons writes:
> Consider for instance the program:
>
> $c = <<'EOC';
> sub foo {
> print "hello\n";
> $x = 7;
> print "\$x = $x\n";
> }
> EOC
>
> eval($c);
> die $@ if $@;
>
> &foo;
>
> When I debug it I get:
>
> # perl -d /tmp/p
>
> Loading DB routines from $RCSfile: perl5db.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:07 $
> Emacs support available.
>
> Enter h or `h h' for help.
>
> main::(/tmp/p:1): $c = <<'EOC';
> main::(/tmp/p:2): sub foo {
> main::(/tmp/p:3): print "hello\n";
> main::(/tmp/p:4): $x = 7;
> main::(/tmp/p:5): print "\$x = $x\n";
> DB<1> n
> main::(/tmp/p:9): eval($c);
> DB<1> n
> main::(/tmp/p:10): die $@ if $@;
> DB<1>
> main::(/tmp/p:12): &foo;
> DB<1> s
> main::foo((eval 4):2): DB<1>
> hello
> main::foo((eval 4):3): DB<1>
> main::foo((eval 4):4): DB<1> l
> DB<1>
>
> So I don't see the contents of the line being executed. I would
> prefer:
>
> main::foo((eval 4):2): print "hello\n";
>
> And I can't list with the command 'l'...
>
> This enhancement would be very useful for the project that I'm working
> on... I can even help to fix perl5db.pl...
>

OK, go ahead. It should not be perl5db.pl, it should be perl itself.

Add a new -DS flag, and when this flag is present, store the currently
evaluated SV inside the CV (with increased refcount). Do not forget to
decrease the refcount of SV when CV is freed. You should find an
appropriate place inside the current CV structure (filegv?). I will do
the rest.

To get to the eval text, do

cxix = dopoptoeval(cxstack_ix);
if (cxix >= 0) {
if (cx->blk_eval.old_op_type == OP_ENTEREVAL) {
evaledsv = cx->blk_eval.cur_text;
}
}

It was discussed on p5-p before, but nobody volonteered.

Best,
Ilya