Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Translate debug code to a debugging technique

by hlen (Beadle)
on Oct 02, 2004 at 03:54 UTC ( [id://395819]=perlquestion: print w/replies, xml ) Need Help??

hlen has asked for the wisdom of the Perl Monks concerning the following question:

I found myself using cluck() today. Nothing wrong about that, except I couldn't find a nice way to ditch it for perl -d. I'm trying to see how to schedule/stop for a stack trace in this situation, with the debugger:
sub message_id($) { my $tr = shift; defined $tr or cluck(), return undef; $tr->isa('HTML::Element') or return undef; my $td = ($tr->content_list())[0]; return $td->as_trimmed_text(); }
This function is called hundreds of times, I only want a backtrace when it's about to return in that specific condition.
(and yeah, I know cluck works perfectly there).

Thanks in advance

Replies are listed 'Best First'.
Re: Translate debug code to a debugging technique
by shenme (Priest) on Oct 02, 2004 at 04:03 UTC
    Would "$DB::single = 1;" be enough to return you control while in the debugger? You could then do whatever you needed to track down your problem?
      Seems nice =). I'm trying to test that, but am having some trouble. My code forks, and the debugger is opening some `Daughter' windows, and then I can't get it to respond. It seems to be entering an infinite loop when I close them. I need some practice, maybe there's a way to make it not follow children.

      I still wonder if there's a way to do that without editing the code, out of curiosity.

      Thanks a lot.

Re: Translate debug code to a debugging technique
by Prior Nacre V (Hermit) on Oct 02, 2004 at 05:38 UTC

    You could call cluck() conditionally based on the value of $^D. Something as simple as ( $^D || cluck() ) may suffice.

    See both perlrun and perldebug for a number of gotchas with this method.



Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://395819]
Approved by ikegami
Front-paged by grinder
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-06-20 08:17 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.