Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would Like Auto-Instrumentation of Subroutines #47

Open
dwmarshall opened this issue Jul 1, 2014 · 2 comments
Open

Would Like Auto-Instrumentation of Subroutines #47

dwmarshall opened this issue Jul 1, 2014 · 2 comments

Comments

@dwmarshall
Copy link

Particularly when I am debugging a module that I haven't maintained before, I'd like to automatically instrument all the subroutines. Here's what I'd like to do:

package Foo::Bar;

use Log::Log4perl qw(:easy);

sub A {}

sub B {}

Log::Log4perl::auto_instrument();
1;

This would look through the symbol table for Foo::Bar and replace each subroutine something like this:

*new_A = \&A;
sub A {
   DEBUG "entering A, arguments are : " . join(' ', @_);
  new_A(@_);
  DEBUG "leaving A";
}

Mike, I wanted to get your thoughts before contributing any code changes.

@mschilli
Copy link
Owner

mschilli commented Jul 2, 2014

Sounds like a great idea! Here's a few things you might find useful:

First off, there's a little known feature in the built-in perl debugger that lets you do something similar, so if you have something like

for my $i (1..3) {
    foo($i);
}

sub foo {
    print "$_[0]\n";
}

and run the script via

PERLDB_OPTS="NonStop=1 AutoTrace=1 frame=4" perl -dS scriptname

you'll get

8:      for my $i (1..3) {
9:          foo($i);
in  .=main::foo(1) from ./t:9
 13:        print "$_[0]\n";
1
9:          foo($i);
in  .=main::foo(2) from ./t:9
 13:        print "$_[0]\n";
2
9:          foo($i);
in  .=main::foo(3) from ./t:9
 13:        print "$_[0]\n";
3

but unfortunately, that doesn't provide the convenience Log4perl users take for granted :). As for Log4perl, many, many years ago (11 to be precise), someone on CPAN set out to create a Log4perl extension to accomplish something similar:

http://search.cpan.org/~jcromie/Log-Log4perl-AutoCategorize-0.03/

Unfortunately, this module didn't stand the test of time and looks broken today, but you might be able to extract some ideas.

Keep the pull request coming! :)

@mohawk2
Copy link
Collaborator

mohawk2 commented Sep 6, 2020

Another bit of existing art that leverages the Perl debugger is https://metacpan.org/pod/Devel::TraceRun. You might request a takeover of the AutoCategorize module, and then get it back to working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants