The problem is that when you ask for the traceback, the program has already died, so the call stack is destroyed.

To solve the problem, you have to arrange to stop the program before it dies.

In this case for example, first put the die in a separate line:

255[am]king ~/a$ cat a print "Hello\n"; a(0); print "Middle\n"; a(1); print "Goodbye\n"; sub a { $parameter = shift; if( $parameter ) { die # <--- line 10 }; }
Then run the code and see it dies at line 10
[am]king ~/a$ perl a Hello Middle Died at a line 10.
Than put a breakpoint to line 10
255[am]king ~/a$ perl -wd a Loading DB routines from perl5db.pl version 1.27 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(a:1): print "Hello\n"; DB<1> b 10 DB<2> c Hello Middle main::a(a:10): die # <--- line 10 DB<2> T . = main::a(1) called from file `a' line 4 DB<2> Died at a line 10. at a line 10 main::a(1) called at a line 4 255[am]king ~/a$
And you'll see that the subroutine was called from line 4.

In reply to Re: Perl debug. How do I find calling line number? by ambrus
in thread Perl debug. How do I find calling line number? by brycen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.