Skip to content

Commit a82d741

Browse files
maninder42masahir0y
authored andcommitted
scripts/checkstack.pl: add arm push handling for stack usage
To count stack usage of push {*, fp, ip, lr, pc} instruction in ARM, if FRAME POINTER is enabled. e.g. c01f0d48: e92ddff0 push {r4, r5, r6, r7, r8, r9, sl, fp, ip, lr, pc} c01f0d50 <Y>: c01f0d44: e1a0c00d mov ip, sp c01f0d48: e92ddff0 push {r4, r5, r6, r7, r8, r9, sl, fp, ip, lr, pc} c01f0d4c: e24cb004 sub fp, ip, #4 c01f0d50: e24dd094 sub sp, sp, torvalds#448 ; 0x1C0 $ cat dump | scripts/checkstack.pl arm 0xc01f0d50 Y []: 448 added subroutine frame work for this. After change: 0xc01f0d500 Y []: 492 Co-developed-by: Vaneet Narang <[email protected]> Signed-off-by: Vaneet Narang <[email protected]> Signed-off-by: Maninder Singh <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 4cdcb74 commit a82d741

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

scripts/checkstack.pl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
# $& (whole re) matches the complete objdump line with the stack growth
3535
# $1 (first bracket) matches the dynamic amount of the stack growth
3636
#
37+
# $sub: subroutine for special handling to check stack usage.
38+
#
3739
# 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);
3941
{
4042
my $arch = shift;
4143
if ($arch eq "") {
@@ -59,6 +61,7 @@
5961
} elsif ($arch eq 'arm') {
6062
#c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64
6163
$re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o;
64+
$sub = \&arm_push_handling;
6265
} elsif ($arch =~ /^x86(_64)?$/ || $arch =~ /^i[3456]86$/) {
6366
#c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp
6467
# or
@@ -111,6 +114,24 @@
111114
}
112115
}
113116

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+
114135
#
115136
# main()
116137
#
@@ -166,6 +187,11 @@
166187
$size = hex($size) if ($size =~ /^0x/);
167188
$total_size += $size;
168189
}
190+
elsif (defined $sub) {
191+
my $size = &$sub($line);
192+
193+
$total_size += $size;
194+
}
169195
}
170196
if ($total_size > $min_stack) {
171197
push @stack, "$intro$total_size\n";

0 commit comments

Comments
 (0)