develooper Front page | perl.perl5.porters | Postings from October 2010

Re: Perl debugger vs. Sub::Name

Thread Previous | Thread Next
From:
Chip Salzenberg
Date:
October 14, 2010 16:44
Subject:
Re: Perl debugger vs. Sub::Name
Message ID:
AANLkTikfpWrriO5LAC4K=TnJ_f5mAG5q7MiUr75+GaHW@mail.gmail.com
On Thu, Oct 14, 2010 at 3:49 PM, Chip Salzenberg <rev.chip@gmail.com> wrote:
> If you run the debugger on code that uses this module and type "l
> Foo::" and <tab>, this is the choice:
>
>  DB<1> l Foo::
> Foo::BEGIN                 Foo::__ANON__[Foo.pm:3]
>  DB<1> l Foo::

Having gone to the trouble of asking the question, I'm pleased to
provide an answer.  :-)

When the Perl debugger is active (specifically the PERLDBf_SUBLINE
feature), defining a subroutine leads op.c to add an entry to the hash
%DB::sub.  The keys of %DB::sub are subroutine names; the values are
strings encoding filenames and line numbers.  While Sub::Name does
update CvGV(cv), it doesn't modify %DB::sub, so the debugger remains
unaware of the renaming.

The below patch to Sub::Name updates %DB::sub appropriately for the
general case.  The patch doesn't handle the special case of a closure
which gets a different name every time it's cloned, but this is still
a step forward.  (I'm sure going to use it.)  One thing about my patch
puzzles me - I had to add an SvREFCNT_inc() to prevent corruption, but
I didn't think I'd have to.  Perhaps hv_delete() automatically makes
its return value mortal, or something.

Share & Enjoy!

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About