| 1 | package Devel::DebugHooks::TraceCall; | ||
| 2 | |||
| 3 | our @ISA; | ||
| 4 | |||
| 5 | BEGIN { | ||
| 6 | @DB::options{ qw/ w s / } = ( 1, 1 ); | ||
| 7 | push @ISA, 'Devel::DebugHooks'; | ||
| 8 | } | ||
| 9 | |||
| 10 | |||
| 11 | |||
| 12 | sub import { | ||
| 13 | my $class = shift; | ||
| 14 | |||
| 15 | $class->SUPER::import( @_ ); | ||
| 16 | } | ||
| 17 | |||
| 18 | |||
| 19 | my $flow_fh; | ||
| 20 | sub log_call { | ||
| 21 | $flow_fh or open $flow_fh, '>dbg_flow.txt'; | ||
| 22 | |||
| 23 | my( $from, $to ) = @{ DB::state( 'stack' ) }[ -2, -1 ]; | ||
| 24 | |||
| 25 | my $extra = ''; | ||
| 26 | $extra = "$to->{ file }:$to->{ line }:" if $to->{ sub } =~ /^CODE/; | ||
| 27 | |||
| 28 | $from = $from &&( $from->{ sub } // $from->{ package }.'::' ) // ''; | ||
| 29 | $to = $to && $to->{ sub } // ''; | ||
| 30 | print $flow_fh "$from -> $extra$to\n"; | ||
| 31 | |||
| 32 | |||
| 33 | 1; | ||
| 34 | } | ||
| 35 | |||
| 36 | |||
| 37 | |||
| 38 | use Devel::DebugHooks(); | ||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | my $handler = DB::reg( 'call', 'TraceCall' ); | ||
| 43 | $$handler->{ context } = $DB::dbg; | ||
| 44 | $$handler->{ code } = \&log_call; | ||
| 45 | |||
| 46 | |||
| 47 | 1; |