Skip to content

Instantly share code, notes, and snippets.

@belden
Last active August 29, 2015 14:14
Show Gist options
  • Save belden/af7ea7857243743125ed to your computer and use it in GitHub Desktop.
Save belden/af7ea7857243743125ed to your computer and use it in GitHub Desktop.
debugging tools
#!/usr/bin/env perl
# use this in the debugger to find a package that implements some name
# to use this:
# 1. download to a local file
# curl https://gist.githubusercontent.com/belden/af7ea7857243743125ed/raw/76b350faaa6ec586f15d426e78d5a5f374783d5a/findsub.pl > /tmp/findsub.pl
# 2. load it up in the debugger
# DB<28> do '/tmp/findsub.pl'
# 3. use it
# DB<29> main::findsub 'prepare_body'
use strict;
use warnings;
sub main::findsub {
my $target = shift;
foreach my $candidate (keys %INC) {
(my $module = $candidate) =~ s{\.pm$}{};
$module =~ s{/}{::}g;
my %table = do {
no strict 'refs';
%{$module . '::'};
};
while (my ($entry, $glob) = each %table) {
if ($entry =~ /$target/) {
print "$module has $target\n";
}
}
}
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment