Skip to content

Commit 6c48a19

Browse files
Improve stack analyzer to handle PAGE entry code. From howard0su. Closes #614
1 parent 2ae3687 commit 6c48a19

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

utils/stm32stack.pl

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
# Configuration: set these as appropriate for your architecture/project.
5454
my $debug = 0;
5555
my $objdump = "arm-none-eabi-objdump";
56-
my $call_cost = 4;
56+
my $call_cost = 0;
5757

5858
# First, we need to read all object and corresponding .su files. We're
5959
# gathering a mapping of functions to callees and functions to frame
@@ -164,6 +164,7 @@
164164
$call_graph{$from} = \%resolved;
165165
}
166166

167+
map_page_entry(\%call_graph);
167168
# Create fake edges and nodes to account for dynamic behaviour.
168169
$call_graph{"INTERRUPT"} = {};
169170

@@ -244,9 +245,10 @@ sub main_cost {
244245
foreach (keys %call_graph) { trace $_; }
245246

246247
# Now, print results in a nice table.
247-
printf " %-30s %8s %8s %8s\n",
248+
printf " %-50s %8s %8s %8s\n",
248249
"Func", "Cost", "Frame", "Height";
249250
print "------------------------------------";
251+
print "------------------------------------";
250252
print "------------------------------------\n";
251253

252254
my $max_iv = 0;
@@ -273,7 +275,7 @@ sub main_cost {
273275

274276
if ($ambiguous{$name}) { $name = $_; }
275277

276-
printf "%s %-30s %8d %8d %8d\n", $tag, $name, $cost,
278+
printf "%s %-50s %8d %8d %8d\n", $tag, $name, $cost,
277279
$frame_size{$_} || 0, $call_depth{$_};
278280
}
279281

@@ -289,3 +291,28 @@ sub main_cost {
289291

290292
print "The following functions were not resolved:\n";
291293
foreach (keys %unresolved) { print " $_\n"; }
294+
295+
sub map_page_entry {
296+
my($call_graph) = @_;
297+
#
298+
# All Page entry functions are called from well-known functions
299+
#
300+
my %funcmap = (init => {}, exit => {}, event => {});
301+
for (keys %$call_graph) {
302+
if(/^PAGE_.+(Init|Exit|Event)\@/) {
303+
$funcmap{lc($1)}{$_} = 1;
304+
}
305+
}
306+
for my $from (keys %$call_graph) {
307+
if ($from =~ /^PAGE_ChangeByID@/) {
308+
$call_graph->{$from} = {%{ $call_graph->{$from} }, %{ $funcmap{init} }, %{ $funcmap{exit} } };
309+
}
310+
if ($from =~ /^PAGE_Exit@/) {
311+
$call_graph->{$from} = {%{ $call_graph->{$from} }, %{ $funcmap{exit} } };
312+
}
313+
if ($from =~ /^PAGE_Event@/) {
314+
$call_graph->{$from} = {%{ $call_graph->{$from} }, %{ $funcmap{event} } };
315+
}
316+
}
317+
}
318+

0 commit comments

Comments
 (0)