|
34 | 34 | # $& (whole re) matches the complete objdump line with the stack growth |
35 | 35 | # $1 (first bracket) matches the dynamic amount of the stack growth |
36 | 36 | # |
| 37 | +# $sub: subroutine for special handling to check stack usage. |
| 38 | +# |
37 | 39 | # use anything else and feel the pain ;) |
38 | | -my (@stack, $re, $dre, $x, $xs, $funcre, $min_stack); |
| 40 | +my (@stack, $re, $dre, $sub, $x, $xs, $funcre, $min_stack); |
39 | 41 | { |
40 | 42 | my $arch = shift; |
41 | 43 | if ($arch eq "") { |
|
59 | 61 | } elsif ($arch eq 'arm') { |
60 | 62 | #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64 |
61 | 63 | $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o; |
| 64 | + $sub = \&arm_push_handling; |
62 | 65 | } elsif ($arch =~ /^x86(_64)?$/ || $arch =~ /^i[3456]86$/) { |
63 | 66 | #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp |
64 | 67 | # or |
|
111 | 114 | } |
112 | 115 | } |
113 | 116 |
|
| 117 | +# |
| 118 | +# To count stack usage of push {*, fp, ip, lr, pc} instruction in ARM, |
| 119 | +# if FRAME POINTER is enabled. |
| 120 | +# e.g. c01f0d48: e92ddff0 push {r4, r5, r6, r7, r8, r9, sl, fp, ip, lr, pc} |
| 121 | +# |
| 122 | +sub arm_push_handling { |
| 123 | + my $regex = qr/.*push.*fp, ip, lr, pc}/o; |
| 124 | + my $size = 0; |
| 125 | + my $line_arg = shift; |
| 126 | + |
| 127 | + if ($line_arg =~ m/$regex/) { |
| 128 | + $size = $line_arg =~ tr/,//; |
| 129 | + $size = ($size + 1) * 4; |
| 130 | + } |
| 131 | + |
| 132 | + return $size; |
| 133 | +} |
| 134 | + |
114 | 135 | # |
115 | 136 | # main() |
116 | 137 | # |
|
166 | 187 | $size = hex($size) if ($size =~ /^0x/); |
167 | 188 | $total_size += $size; |
168 | 189 | } |
| 190 | + elsif (defined $sub) { |
| 191 | + my $size = &$sub($line); |
| 192 | + |
| 193 | + $total_size += $size; |
| 194 | + } |
169 | 195 | } |
170 | 196 | if ($total_size > $min_stack) { |
171 | 197 | push @stack, "$intro$total_size\n"; |
|
0 commit comments