6 my %sym_tab = (new Math::BigInt(0) => "ERRRRRRROR");
7 my $sections = "BdDdTtVvWwuU";
16 my $h = substr $i->as_hex(), 2;
17 $h = ('0' x (16-length($h))) . $h;
24 print " input is read from stdin\n";
29 $nm = "$ENV{'SYSTEM_TARGET'}$nm" if defined $ENV{"SYSTEM_TARGET"};
30 $nm = 'arm-softfloat-elf-nm' if !(system("file -L $img | grep -qw ARM") >> 8);
32 foreach my $l (split('\n', qx{$nm $img | c++filt}))
34 if ($l =~ /^([0-9a-fA-F]*)\s+([$sections])\s+(.*)$/)
36 my ($addr, $sec, $sym) = (new Math::BigInt("0x$1"), $2, $3);
37 if (defined $addr && ref $addr && !$addr->is_nan())
39 $sym_tab{as_hex($addr)} = $sym;
40 $sec_tab{as_hex($addr)} = $sec;
44 my @sorted_sym_tab_keys = sort keys %sym_tab;
45 my $min_addr = $sorted_sym_tab_keys[0];
46 my $max_addr = $sorted_sym_tab_keys[@sorted_sym_tab_keys - 1];
48 print "Scanning image done, proceed.\n";
52 my $addr = as_hex(shift);
55 return new Math::BigInt(0)
56 if $addr lt $min_addr or $addr gt $max_addr;
58 foreach my $s (@sorted_sym_tab_keys)
62 return new Math::BigInt("0x$hit");
68 return new Math::BigInt(0);
73 my $addr = new Math::BigInt("0x".shift);
74 my $hit = find_sym($addr);
75 my $offset = $addr-$hit;
76 my $o = $hit->as_hex();
80 printf " %s %30s(%s) + %6s = %s\n",
81 $addr->as_hex(), $sym_tab{as_hex($hit)}, $sec_tab{as_hex($hit)},
82 $offset->as_hex(), $hit->as_hex();
89 if (/^\s+#(\d+)\s+([0-9a-f]+)\s+([0-9a-f]+)/i) # fiasco bt without debuginfo
92 my $stack = new Math::BigInt("0x$2");
94 my $fsize = $stack - $last_f;
97 printf "%2d %s ", $fn, $stack->as_hex();
98 if ($fsize >= 0 && $fsize <= 2000)
100 printf "%4d", $fsize;
106 elsif (/^(?:.*?\|)?\s*(0x)?([0-9a-f]+)\s*$/i) # simple figure
110 elsif (/^[\da-f]+:([\d\sa-f]+)$/i) # fiasco memory dump (mostly user stack)
113 for my $addr (split(/\s+/, $l))
118 elsif (/^\s*[\da-f]+\s+([\d\sa-f]+)\s*$/i) # fiasco tcb view stack
121 for my $val (split(/\s+/, $l))
123 next if $val eq '35353535'; # stack poison
124 if ($val =~ /^f.......(?:........)?$/i) {
127 print " 0x$val ... value ...\n";