This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / scripts / checkstack.pl
1 #!/usr/bin/perl
2
3 #       Check the stack usage of functions
4 #
5 #       Copyright Joern Engel <joern@wh.fh-wedel.de>
6 #       Inspired by Linus Torvalds
7 #       Original idea maybe from Keith Owens
8 #       s390 port and big speedup by Arnd Bergmann <arnd@bergmann-dalldorf.de>
9 #       Mips port by Juan Quintela <quintela@mandrakesoft.com>
10 #       IA64 port via Andreas Dilger
11 #       Arm port by Holger Schurig
12 #       Random bits by Matt Mackall <mpm@selenic.com>
13 #
14 #       Usage:
15 #       objdump -d vmlinux | stackcheck_ppc.pl [arch]
16 #
17 #       TODO :  Port to all architectures (one regex per arch)
18
19 # check for arch
20 #
21 # $re is used for two matches:
22 # $& (whole re) matches the complete objdump line with the stack growth
23 # $1 (first bracket) matches the size of the stack growth
24 #
25 # use anything else and feel the pain ;)
26 my (@stack, $re, $x, $xs);
27 {
28         my $arch = shift;
29         if ($arch eq "") {
30                 $arch = `uname -m`;
31         }
32
33         $x      = "[0-9a-f]";   # hex character
34         $xs     = "[0-9a-f ]";  # hex character or space
35         if ($arch eq 'arm') {
36                 #c0008ffc:      e24dd064        sub     sp, sp, #100    ; 0x64
37                 $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o;
38         } elsif ($arch =~ /^i[3456]86$/) {
39                 #c0105234:       81 ec ac 05 00 00       sub    $0x5ac,%esp
40                 $re = qr/^.*[as][du][db]    \$(0x$x{1,8}),\%esp$/o;
41         } elsif ($arch eq 'ia64') {
42                 #e0000000044011fc:       01 0f fc 8c     adds r12=-384,r12
43                 $re = qr/.*adds.*r12=-(([0-9]{2}|[3-9])[0-9]{2}),r12/o;
44         } elsif ($arch eq 'mips64') {
45                 #8800402c:       67bdfff0        daddiu  sp,sp,-16
46                 $re = qr/.*daddiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
47         } elsif ($arch eq 'mips') {
48                 #88003254:       27bdffe0        addiu   sp,sp,-32
49                 $re = qr/.*addiu.*sp,sp,-(([0-9]{2}|[3-9])[0-9]{2})/o;
50         } elsif ($arch eq 'ppc') {
51                 #c00029f4:       94 21 ff 30     stwu    r1,-208(r1)
52                 $re = qr/.*stwu.*r1,-($x{1,8})\(r1\)/o;
53         } elsif ($arch eq 'ppc64') {
54                 #XXX
55                 $re = qr/.*stdu.*r1,-($x{1,8})\(r1\)/o;
56         } elsif ($arch =~ /^s390x?$/) {
57                 #   11160:       a7 fb ff 60             aghi   %r15,-160
58                 $re = qr/.*ag?hi.*\%r15,-(([0-9]{2}|[3-9])[0-9]{2})/o;
59         } else {
60                 print("wrong or unknown architecture\n");
61                 exit
62         }
63 }
64
65 sub bysize($) {
66         my ($asize, $bsize);
67         ($asize = $a) =~ s/.*   +(.*)$/$1/;
68         ($bsize = $b) =~ s/.*   +(.*)$/$1/;
69         $bsize <=> $asize
70 }
71
72 #
73 # main()
74 #
75 my $funcre = qr/^$x* <(.*)>:$/;
76 my $func;
77 while (my $line = <STDIN>) {
78         if ($line =~ m/$funcre/) {
79                 $func = $1;
80         }
81         if ($line =~ m/$re/) {
82                 my $size = $1;
83                 $size = hex($size) if ($size =~ /^0x/);
84
85                 if ($size > 0x80000000) {
86                         $size = - $size;
87                         $size += 0x80000000;
88                         $size += 0x80000000;
89                 }
90
91                 next if $line !~ m/^($xs*)/;
92                 my $addr = $1;
93                 $addr =~ s/ /0/g;
94                 $addr = "0x$addr";
95
96                 my $intro = "$addr $func:";
97                 my $padlen = 56 - length($intro);
98                 while ($padlen > 0) {
99                         $intro .= '     ';
100                         $padlen -= 8;
101                 }
102                 next if ($size < 100);
103                 push @stack, "$intro$size\n";
104         }
105 }
106
107 print sort bysize @stack;