# This is the custom debugger: { package DB; sub DB {} sub sub { print STDERR "== Entering sub $sub\n"; &$sub; # Call the sub print STDERR "=== Leaving sub $sub\n"; } } # Now some example code to test it with: sub hello { print "Hello, "; world(); } sub world { print "World!\n"; } $|++; # Turn off buffering, to make the control flow clearer hello(); #### $ perl d.pl Hello, World! $ perl -d d.pl Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. == Entering sub main::hello Hello, == Entering sub main::world World! === Leaving sub main::world === Leaving sub main::hello #### BEGIN {$^P = 1} #### BEGIN { return if $^P; # If the debugger is running, leave well alone $^P = 1; # Enable subroutine tracing package DB; *sub = sub { print STDERR "== Entering sub $sub\n"; &$sub; print STDERR "=== Leaving sub $sub\n"; }; }