-# Do backtrace.
-open (A2L, "$a2l -fe $bin " . join (' ', @ARGV) . "|");
-while (<A2L>) {
- my ($function, $line);
- chomp ($function = $_);
- chomp ($line = <A2L>);
- print shift (@ARGV), ": $function ($line)\n";
+# Figure out backtrace.
+my (@locs) = map ({ADDR => $_}, @ARGV);
+for my $bin (@binaries) {
+ open (A2L, "$a2l -fe $bin " . join (' ', map ($_->{ADDR}, @locs)) . "|");
+ for (my ($i) = 0; <A2L>; $i++) {
+ my ($function, $line);
+ chomp ($function = $_);
+ chomp ($line = <A2L>);
+ next if defined $locs[$i]{BINARY};
+
+ if ($function ne '??' || $line ne '??:0') {
+ $locs[$i]{FUNCTION} = $function;
+ $locs[$i]{LINE} = $line;
+ $locs[$i]{BINARY} = $bin;
+ }
+ }
+ close (A2L);
+}
+
+# Print backtrace.
+my ($cur_binary);
+for my $loc (@locs) {
+ if (defined ($loc->{BINARY})
+ && @binaries > 1
+ && (!defined ($cur_binary) || $loc->{BINARY} ne $cur_binary)) {
+ $cur_binary = $loc->{BINARY};
+ print "In $cur_binary:\n";
+ }
+
+ my ($addr) = $loc->{ADDR};
+ $addr = sprintf ("0x%08x", hex ($addr)) if $addr =~ /^0x[0-9a-f]+$/i;
+
+ print $addr, ": ";
+ if (defined ($loc->{BINARY})) {
+ my ($function) = $loc->{FUNCTION};
+ my ($line) = $loc->{LINE};
+ $line =~ s/^(\.\.\/)*//;
+ $line = "..." . substr ($line, -25) if length ($line) > 28;
+ print "$function ($line)";
+ } else {
+ print "(unknown)";
+ }
+ print "\n";