addr2name.awk 1022 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/awk -f
  2. # Copyright (C) 2000 Free Software Foundation
  3. # This file is part of libgcj.
  4. # This software is copyrighted work licensed under the terms of the
  5. # Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  6. # details.
  7. # This script emulates a little of the functionality of addr2line for
  8. # those systems that don't have it. The only command line argument is
  9. # an executable name. The script reads hexadecimal addresses from
  10. # stdin and prints the corresponding symbol names to stdout. The
  11. # addresses must begin with "0x" and be fully zero filled or this
  12. # won't work.
  13. BEGIN {
  14. object = ARGV[1];
  15. ARGV[1] = "";
  16. while ("nm " object "| sort" | getline) {
  17. if ($2 == "t" || $2 == "T") {
  18. address[i] = "0x" $1; name[i] = $3;
  19. i++;
  20. }
  21. }
  22. syms = i;
  23. }
  24. {
  25. lo = 0;
  26. hi = syms - 1;
  27. while ((hi-1) > lo)
  28. {
  29. try = int ((hi + lo) / 2);
  30. if ($0 < address[try])
  31. hi = try;
  32. else if ($0 >= address[try])
  33. lo = try;
  34. }
  35. print name[lo] "\n"; fflush();
  36. }