s3:smb2_server: make sure we grant credits on async read/write operations (bug #8357)
[Samba.git] / script / findstatic.pl
blob43a4916435d5910fada7d3934fdc0abcce0cbb82
1 #!/usr/bin/perl -w
2 # find a list of fns and variables in the code that could be static
3 # usually called with something like this:
4 # findstatic.pl `find . -name "*.o"`
5 # Andrew Tridgell <tridge@samba.org>
7 use strict;
9 # use nm to find the symbols
10 my($saved_delim) = $/;
11 undef $/;
12 my($syms) = `nm -o @ARGV`;
13 $/ = $saved_delim;
15 my(@lines) = split(/\n/s, $syms);
17 my(%def);
18 my(%undef);
19 my(%stype);
21 my(%typemap) = (
22 "T" => "function",
23 "C" => "uninitialised variable",
24 "D" => "initialised variable"
28 # parse the symbols into defined and undefined
29 for (my($i)=0; $i <= $#{@lines}; $i++) {
30 my($line) = $lines[$i];
31 if ($line =~ /(.*):[a-f0-9]* ([TCD]) (.*)/) {
32 my($fname) = $1;
33 my($symbol) = $3;
34 push(@{$def{$fname}}, $symbol);
35 $stype{$symbol} = $2;
37 if ($line =~ /(.*):\s* U (.*)/) {
38 my($fname) = $1;
39 my($symbol) = $2;
40 push(@{$undef{$fname}}, $symbol);
44 # look for defined symbols that are never referenced outside the place they
45 # are defined
46 foreach my $f (keys %def) {
47 print "Checking $f\n";
48 my($found_one) = 0;
49 foreach my $s (@{$def{$f}}) {
50 my($found) = 0;
51 foreach my $f2 (keys %undef) {
52 if ($f2 ne $f) {
53 foreach my $s2 (@{$undef{$f2}}) {
54 if ($s2 eq $s) {
55 $found = 1;
56 $found_one = 1;
61 if ($found == 0) {
62 my($t) = $typemap{$stype{$s}};
63 print " '$s' is unique to $f ($t)\n";
66 if ($found_one == 0) {
67 print " all symbols in '$f' are unused (main program?)\n";