Skip to content

Commit 017c758

Browse files
Fix regression in stack-trace analyzer in recursion
1 parent 2bbc57a commit 017c758

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

utils/stm32stack.pl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
use Data::Dumper;
5252

5353
# Configuration: set these as appropriate for your architecture/project.
54-
54+
my $debug = 0;
5555
my $objdump = "arm-none-eabi-objdump";
5656
my $call_cost = 4;
5757

@@ -179,11 +179,17 @@
179179
my %call_depth;
180180

181181
sub trace {
182-
my $f = shift;
182+
my ($f, $indent) = (@_);
183+
$indent ||= "";
183184

184185
if ($visited{$f}) {
185-
$visited{$f} = "R" if $visited{$f} eq "?";
186-
return 0;
186+
if ($visited{$f} eq "?") {
187+
$visited{$f} = "R";
188+
$call_depth{$f} = 1;
189+
$total_cost{$f} = $frame_size{$f} || 0;
190+
}
191+
printf("${indent}$f -> %d\n", $total_cost{$f}) if($debug);
192+
return;
187193
}
188194

189195
$visited{$f} = "?";
@@ -197,10 +203,8 @@ sub trace {
197203
my $t = $_;
198204

199205
$has_caller{$t} = 1;
200-
next unless trace($t);
201-
202-
warn "No cost found for $t" if (! defined $total_cost{$t});
203-
my $is = $total_cost{$t} || 0;
206+
trace($t, "$indent ");
207+
my $is = $total_cost{$t};
204208
my $d = $call_depth{$t};
205209

206210
$max_frame = $is if $is > $max_frame;
@@ -211,7 +215,8 @@ sub trace {
211215
$call_depth{$f} = $max_depth + 1;
212216
$total_cost{$f} = $max_frame + ($frame_size{$f} || 0);
213217
$visited{$f} = " " if $visited{$f} eq "?";
214-
return 1;
218+
printf("${indent}$f -> %d\n", $total_cost{$f}) if($debug);
219+
return;
215220
}
216221

217222
sub main_cost {

0 commit comments

Comments
 (0)