line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FFI::ExtractSymbols::PosixNm; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
25
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
104
|
|
4
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
100
|
|
5
|
4
|
|
|
4
|
|
1630
|
use File::Which qw( which ); |
|
4
|
|
|
|
|
3599
|
|
|
4
|
|
|
|
|
226
|
|
6
|
4
|
|
|
4
|
|
26
|
use File::ShareDir::Dist (); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
45
|
|
7
|
4
|
|
|
4
|
|
16
|
use constant (); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1787
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $config = File::ShareDir::Dist::dist_config('FFI-ExtractSymbols'); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: Posix nm implementation for FFI::ExtractSymbols |
12
|
|
|
|
|
|
|
our $VERSION = '0.07'; # VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
return 1 if FFI::ExtractSymbols->can('extract_symbols'); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $nm = which('nm'); |
18
|
|
|
|
|
|
|
$nm = $config->{'exe'}->{nm} |
19
|
|
|
|
|
|
|
unless defined $nm; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
if(my $prefix = $config->{'function_prefix'}) |
22
|
|
|
|
|
|
|
{ |
23
|
|
|
|
|
|
|
my $re = qr{^$prefix}; |
24
|
|
|
|
|
|
|
*_remove_code_prefix = sub { |
25
|
|
|
|
|
|
|
my $symbol = shift; |
26
|
|
|
|
|
|
|
$symbol =~ s{$re}{}; |
27
|
|
|
|
|
|
|
$symbol; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else |
31
|
12
|
|
|
12
|
|
47
|
{ *_remove_code_prefix = sub { $_[0] } } |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
if(my $prefix = $config->{'data_prefix'}) |
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
my $re = qr{^$prefix}; |
36
|
|
|
|
|
|
|
*_remove_data_prefix = sub { |
37
|
|
|
|
|
|
|
my $symbol = shift; |
38
|
|
|
|
|
|
|
$symbol =~ s{$re}{}; |
39
|
|
|
|
|
|
|
$symbol; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else |
43
|
12
|
|
|
12
|
|
93
|
{ *_remove_data_prefix = sub { $_[0] } } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
*FFI::ExtractSymbols::extract_symbols = sub |
46
|
|
|
|
|
|
|
{ |
47
|
2
|
|
|
2
|
|
17326
|
my($libpath, %callbacks) = @_; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
50
|
0
|
|
18
|
$callbacks{$_} ||= sub {} for qw( export code data ); |
50
|
|
|
|
|
|
|
|
51
|
2
|
|
|
|
|
7
|
my @flags = qw( -g -P ); |
52
|
2
|
50
|
|
|
|
27
|
push @flags, '-D' unless $^O eq 'darwin'; |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
8615
|
foreach my $line (`$nm @flags $libpath`) |
55
|
|
|
|
|
|
|
{ |
56
|
24
|
50
|
|
|
|
4273
|
next if $line =~ /^\s/; |
57
|
24
|
|
|
|
|
155
|
my($symbol, $type) = split /\s+/, $line; |
58
|
24
|
100
|
66
|
|
|
180
|
if($type eq $config->{function_code} || $type eq 'W') |
|
|
100
|
|
|
|
|
|
59
|
|
|
|
|
|
|
{ |
60
|
6
|
|
|
|
|
34
|
$callbacks{export}->(_remove_code_prefix($symbol), $symbol); |
61
|
6
|
|
|
|
|
2525
|
$callbacks{code}-> (_remove_code_prefix($symbol), $symbol); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif($type eq $config->{data_code}) |
64
|
|
|
|
|
|
|
{ |
65
|
6
|
|
|
|
|
45
|
$callbacks{export}->(_remove_data_prefix($symbol), $symbol); |
66
|
6
|
|
|
|
|
4050
|
$callbacks{data}-> (_remove_data_prefix($symbol), $symbol); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
2
|
|
|
|
|
838
|
(); |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |