6 if (grep ($_ eq '-h' || $_ eq '--help', @ARGV)) {
8 backtrace, for converting raw addresses into symbolic backtraces
9 usage: backtrace [BINARY] ADDRESS...
10 where BINARY is the binary file from which to obtain symbols
11 and ADDRESS is a raw address to convert to a symbol name.
13 If BINARY is unspecified, the default is the first of kernel.o or
14 build/kernel.o that exists.
16 The ADDRESS list should be taken from the "Call stack:" printed by the
17 kernel. Read "Backtraces" in the "Debugging Tools" chapter of the
18 Pintos documentation for more information.
22 die "backtrace: at least one argument required (use --help for help)\n"
25 # Drop leading and trailing garbage inserted by kernel.
26 shift while grep (/^(call|stack:?)$/i, $ARGV[0]);
27 s/\.$// foreach @ARGV;
33 } elsif ($bin !~ /^0/) {
34 die "backtrace: $bin: not found (use --help for help)\n";
35 } elsif (-e 'kernel.o') {
37 } elsif (-e 'build/kernel.o') {
38 $bin = 'build/kernel.o';
40 die "backtrace: can't find binary for backtrace (use --help for help)\n";
44 my ($a2l) = search_path ("i386-elf-addr2line") || search_path ("addr2line");
46 die "backtrace: neither `i386-elf-addr2line' nor `addr2line' in PATH\n";
50 for my $dir (split (':', $ENV{PATH})) {
51 my ($file) = "$dir/$target";
52 return $file if -e $file;
58 open (A2L, "$a2l -fe $bin " . join (' ', @ARGV) . "|");
60 my ($function, $line);
61 chomp ($function = $_);
62 chomp ($line = <A2L>);
63 print shift (@ARGV), ": $function ($line)\n";