Perl debugging

A

aizenman

Hi All,

I have two questions about debugging with perl. Your help would be much
appreciated.

First, is there any way to break on builtins like die()? Currently
whenever I die it seems to muck with the calling stack so that I can't
PadWalk my way up it. It would be nice to die at the exact spot where
it was called.

Secondly, is there any way to get the debugger to load certain settings
and breakpoints when it starts *in a given folder* or better yet *for a
given script*? I realize I could muck with my global ~/.perldb but I'd
prefer to have it specific to each project.

Thanks!
-aizenman
 
A

aizenman

Ah, one more question. Is there any way that I can tell the debugger
to break at a certain point in a different file than the one I start
in? I.e.

DB<3> b foo.pm:23
Subroutine main::foo not found.

But actually working :)

Thanks!
-aizenman
 
B

Babacio

Hi All,

I have two questions about debugging with perl. Your help would be much
appreciated.

First, is there any way to break on builtins like die()? Currently
whenever I die it seems to muck with the calling stack so that I can't
PadWalk my way up it. It would be nice to die at the exact spot where
it was called.

I think you should read the doc of Carp.
Starting your program by

use Carp qw(cluck confess);
$SIG{__WARN__} = \&cluck;
$SIG{__DIE__} = \&confess;

may be a good idea.
 
B

Babacio

Babacio.
I think you should read the doc of Carp.
Starting your program by

use Carp qw(cluck confess);
$SIG{__WARN__} = \&cluck;
$SIG{__DIE__} = \&confess;

may be a good idea.

Shouldn't that deserve to be in the FAQ? (Please don't shout if for
some obvious reason, this suggestion is ss}}}|yd¹, I am new to the
perl community). What is the way to submit an item to the FAQ?
(perldoc -q submit says nothing)
 
P

Paul Lalli

Babacio said:
Shouldn't that deserve to be in the FAQ? (Please don't shout if for
some obvious reason, this suggestion is ss}}}|yd¹,

I have no idea what that means.
I am new to the
perl community). What is the way to submit an item to the FAQ?
(perldoc -q submit says nothing)

No, but `perldoc perlfaq` does say:
How to contribute to the perlfaq

You may mail corrections, additions, and suggestions to
(e-mail address removed)

Paul Lalli
 
A

aizenman

Thanks for the advice on breaking on die/confess - does anyone have
suggestions for the other two questions?
-aizenman
 
P

Paul Lalli

Babacio said:
"Paul Lalli".


You should read the footnote.

No, you should stop using "cutesy" spellings and phrases, with
explanations in your signature.

Paul Lalli
 
D

Dave Weaver

Ah, one more question. Is there any way that I can tell the debugger
to break at a certain point in a different file than the one I start
in? I.e.

DB<3> b foo.pm:23
Subroutine main::foo not found.

I'm no debugger expert, but you could always use 'f' to select the
"current file", then 'b' to set the breakpoint.

DB<3> f Foo.pm
DB<4> b 23

Or if you just want to break when a certain sub within Foo is called
(assuming Foo.pm contains package Foo):

DB<5> b Foo::mysub
 
P

Peter Scott

Secondly, is there any way to get the debugger to load certain settings
and breakpoints when it starts *in a given folder* or better yet *for a
given script*? I realize I could muck with my global ~/.perldb but I'd
prefer to have it specific to each project.

perldoc perldebug:

The code is executed in the package "DB". Note that .perldb is pro-
cessed before processing "PERLDB_OPTS". If .perldb defines the subrou-
tine "afterinit", that function is called after debugger initialization
ends. .perldb may be contained in the current directory, or in the
home directory. ^^^^^^^^^^^^^^^^^

To execute debugger commands in .perldb you can use this hack
(undocumented, don't blame me if it stops working one day):

[marvin:/tmp] peter% cat .perldb
sub afterinit { @typeahead = ('x \\%INC', 'b 6') }
[marvin:/tmp] peter% cat foo
print "one\n";
print "two\n";



print "six\n";
print "seven\n";
[marvin:/tmp] peter% perl -d foo

Loading DB routines from perl5db.pl version 1.19
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(foo:1): print "one\n";
auto(-2) DB<1> x \%INC
0 HASH(0x47518)
'./.perldb' => './.perldb'
'AutoLoader.pm' => '/Library/Perl/AutoLoader.pm'
'Carp.pm' => '/Library/Perl/Carp.pm'
[snip]
'warnings.pm' => '/Library/Perl/warnings.pm'
'warnings/register.pm' => '/Library/Perl/warnings/register.pm'
auto(-1) DB<2> b 6
DB<3> l
1==> print "one\n";
2: print "two\n";
3
4
5
6:b print "six\n";
7: print "seven\n";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top