| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Utilities to get and manipulate symbols from a binary.""" | 6 """Utilities to get and manipulate symbols from a binary.""" |
| 7 | 7 |
| 8 import collections | 8 import collections |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| 11 import subprocess | 11 import subprocess |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 sys.path.insert( | 14 sys.path.insert( |
| 15 0, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, | 15 0, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, |
| 16 'third_party', 'android_platform', 'development', | 16 'third_party', 'android_platform', 'development', |
| 17 'scripts')) | 17 'scripts')) |
| 18 import symbol | 18 import symbol |
| 19 | 19 |
| 20 | |
| 21 # TODO(lizeb): Change symbol.ARCH to the proper value when "arm" is no longer | |
| 22 # the only possible value. | |
| 23 _OBJDUMP_BINARY = symbol.ToolPath('objdump') | 20 _OBJDUMP_BINARY = symbol.ToolPath('objdump') |
| 24 | 21 |
| 25 | 22 |
| 26 SymbolInfo = collections.namedtuple('SymbolInfo', ('name', 'offset', 'size', | 23 SymbolInfo = collections.namedtuple('SymbolInfo', ('name', 'offset', 'size', |
| 27 'section')) | 24 'section')) |
| 28 | 25 |
| 26 def SetArchitecture(arch): |
| 27 """Set the architecture for binaries to be symbolized.""" |
| 28 symbol.ARCH = arch |
| 29 global _OBJDUMP_BINARY |
| 30 _OBJDUMP_BINARY = symbol.ToolPath('objdump') |
| 31 |
| 29 | 32 |
| 30 def _FromObjdumpLine(line): | 33 def _FromObjdumpLine(line): |
| 31 """Create a SymbolInfo by parsing a properly formatted objdump output line. | 34 """Create a SymbolInfo by parsing a properly formatted objdump output line. |
| 32 | 35 |
| 33 Args: | 36 Args: |
| 34 line: line from objdump | 37 line: line from objdump |
| 35 | 38 |
| 36 Returns: | 39 Returns: |
| 37 An instance of SymbolInfo if the line represents a symbol, None otherwise. | 40 An instance of SymbolInfo if the line represents a symbol, None otherwise. |
| 38 """ | 41 """ |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 def CreateNameToSymbolInfo(symbol_infos): | 114 def CreateNameToSymbolInfo(symbol_infos): |
| 112 """Create a dict {name: symbol_info, ...}. | 115 """Create a dict {name: symbol_info, ...}. |
| 113 | 116 |
| 114 Args: | 117 Args: |
| 115 symbol_infos: iterable of SymbolInfo instances | 118 symbol_infos: iterable of SymbolInfo instances |
| 116 | 119 |
| 117 Returns: | 120 Returns: |
| 118 a dict {name: symbol_info, ...} | 121 a dict {name: symbol_info, ...} |
| 119 """ | 122 """ |
| 120 return {symbol_info.name: symbol_info for symbol_info in symbol_infos} | 123 return {symbol_info.name: symbol_info for symbol_info in symbol_infos} |
| OLD | NEW |