objdump-v8 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2016 the V8 project authors. All rights reserved.
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are
  6. # met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above
  11. # copyright notice, this list of conditions and the following
  12. # disclaimer in the documentation and/or other materials provided
  13. # with the distribution.
  14. # * Neither the name of Google Inc. nor the names of its
  15. # contributors may be used to endorse or promote products derived
  16. # from this software without specific prior written permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. import os.path
  30. import re
  31. import subprocess
  32. import sys
  33. def get_address_bounds():
  34. start = -1
  35. end = -1
  36. for arg in sys.argv:
  37. if arg.startswith("--start-address="):
  38. start = int(arg[-12:], 16)
  39. if arg.startswith("--stop-address="):
  40. end = int(arg[-12:], 16)
  41. return start, end
  42. def format_line(line):
  43. pieces = line.split(None, 3)
  44. return " " + pieces[0][2:] + ":\t" + pieces[3]
  45. def is_comment(line):
  46. stripped = line.strip()
  47. return stripped.startswith("--") or stripped.startswith(";;")
  48. def main():
  49. filename = sys.argv[-1]
  50. match = re.match(r"/tmp/perf-(.*)\.map", filename)
  51. if match:
  52. start, end = get_address_bounds()
  53. process_codefile = "code-" + match.group(1) + "-1.asm"
  54. if os.path.exists(process_codefile):
  55. codefile = open(process_codefile, "r")
  56. else:
  57. codefile = open("code.asm", "r")
  58. with codefile:
  59. printing = False
  60. for line in codefile:
  61. if line.startswith("0x"):
  62. addr = int(line.split()[0], 0)
  63. if start <= addr <= end:
  64. printing = True
  65. sys.stdout.write(format_line(line))
  66. elif printing:
  67. break
  68. elif printing:
  69. if not is_comment(line):
  70. break
  71. else:
  72. sys.stdout.write(line)
  73. else:
  74. sys.argv[0] = "objdump"
  75. sys.exit(subprocess.call(sys.argv))
  76. if __name__ == "__main__":
  77. main()