Perl debugging

Discussion in 'Perl Misc' started by aizenman@gmail.com, Sep 29, 2005.

  1. Guest

    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
    , Sep 29, 2005
    #1
    1. Advertising

  2. Guest

    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
    , Sep 29, 2005
    #2
    1. Advertising

  3. Babacio Guest

    writes:

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

    --
    Thank you for learning me a new verb: 'to muck'
    Babacio, Sep 29, 2005
    #3
  4. Babacio Guest

    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)

    --
    ¹stupid | silly.
    Babacio, Sep 29, 2005
    #4
  5. Paul Lalli Guest

    Babacio wrote:
    >
    > 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


    Paul Lalli
    Paul Lalli, Sep 29, 2005
    #5
  6. Babacio Guest

    "Paul Lalli".

    > Babacio wrote:
    >>
    >> 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.


    You should read the footnote.

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


    Oups, thanks.

    --
    Bé erre hue ixe eu elle, Bruxelles.
    Babacio, Sep 29, 2005
    #6
  7. Guest

    Thanks for the advice on breaking on die/confess - does anyone have
    suggestions for the other two questions?
    -aizenman
    , Sep 29, 2005
    #7
  8. Paul Lalli Guest

    Babacio wrote:
    > "Paul Lalli".
    >
    > > Babacio wrote:
    > >>
    > >> 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.

    >
    > You should read the footnote.


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

    Paul Lalli
    Paul Lalli, Sep 29, 2005
    #8
  9. Babacio Guest

    "Paul Lalli"

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

    >>
    >> You should read the footnote.

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


    Sir! Yes, sir!

    --
    Bé erre hue ixe eu elle, Bruxelles.
    Babacio, Sep 29, 2005
    #9
  10. Dave Weaver Guest

    On 29 Sep 2005 09:26:17 -0700, <> wrote:
    > 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
    Dave Weaver, Sep 30, 2005
    #10
  11. Peter Scott Guest

    On Thu, 29 Sep 2005 09:20:09 -0700, aizenman wrote:
    > 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";


    --
    Peter Scott
    http://www.perlmedic.com/
    http://www.perldebugged.com/
    Peter Scott, Sep 30, 2005
    #11
  12. Guest

    Hot. Thank you very much.
    , Sep 30, 2005
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,765
  2. Johann Blake
    Replies:
    1
    Views:
    1,183
    Hermit Dave
    Jan 5, 2004
  3. jacob navia

    Debugging C vs debugging C++

    jacob navia, Oct 26, 2006, in forum: C Programming
    Replies:
    11
    Views:
    570
    Ian Collins
    Oct 27, 2006
  4. AAaron123
    Replies:
    3
    Views:
    643
    AAaron123
    Jul 28, 2009
  5. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Jan 23, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    284
    PerlFAQ Server
    Jan 23, 2011
Loading...

Share This Page