Commit 6d49e5ca authored by azarchs's avatar azarchs Committed by Commit bot

Fix pylint error in patch_orderfile and symbolize.

BUG=

Review URL: https://codereview.chromium.org/799893003

Cr-Commit-Position: refs/heads/master@{#308081}
parent 7329c2c1
...@@ -38,26 +38,27 @@ while nm_index < len(nmlines): ...@@ -38,26 +38,27 @@ while nm_index < len(nmlines):
else: else:
nm_index = nm_index + 1 nm_index = nm_index + 1
def binary_search (addr, start, end): def binary_search (search_addr, start, end):
if start >= end or start == end - 1: if start >= end or start == end - 1:
(nm_addr, size) = uniqueAddrs[start] (nm_addr, sym_size) = uniqueAddrs[start]
if not (addr >= nm_addr and addr < nm_addr + size): if not (search_addr >= nm_addr and search_addr < nm_addr + sym_size):
sys.stderr.write ("ERROR: did not find function in binary: addr: " + error_message = ('ERROR: did not find function in binary: addr: ' +
hex(addr) + " nm_addr: " + str(nm_addr) + " start: " + str(start) + hex(addr) + ' nm_addr: ' + str(nm_addr) + ' start: ' +
" end: " + str(end) + "\n") str(start) + ' end: ' + str(end))
raise Error("error") sys.stderr.write(error_message + "\n")
return (addressMap[nm_addr], size) raise Exception(error_message)
return (addressMap[nm_addr], sym_size)
else: else:
halfway = start + ((end - start) / 2) halfway = start + ((end - start) / 2)
(nm_addr, size) = uniqueAddrs[halfway] nm_addr = uniqueAddrs[halfway][0]
if (addr >= nm_addr and addr < nm_addr + size): if (addr >= nm_addr and addr < nm_addr + sym_size):
return (addressMap[nm_addr], size) return (addressMap[nm_addr], sym_size)
elif (addr < nm_addr): elif (addr < nm_addr):
return binary_search (addr, start, halfway) return binary_search (addr, start, halfway)
elif (addr >= nm_addr + size): elif (addr >= nm_addr + sym_size):
return binary_search (addr, halfway, end) return binary_search (addr, halfway, end)
else: else:
raise "ERROR: did not expect this case" raise Exception("ERROR: did not expect this case")
f = open (orderfile) f = open (orderfile)
lines = f.readlines() lines = f.readlines()
...@@ -77,13 +78,13 @@ functionAddressMap = {} ...@@ -77,13 +78,13 @@ functionAddressMap = {}
for line in nmlines: for line in nmlines:
try: try:
functionName = line.split()[3] functionName = line.split()[3]
except: except Exception:
functionName = line.split()[2] functionName = line.split()[2]
functionName = functionName.split('.clone.')[0] functionName = functionName.split('.clone.')[0]
functionAddress = int (line.split()[0].strip(), 16) functionAddress = int (line.split()[0].strip(), 16)
try: try:
functionAddressMap[functionName].append(functionAddress) functionAddressMap[functionName].append(functionAddress)
except: except Exception:
functionAddressMap[functionName] = [functionAddress] functionAddressMap[functionName] = [functionAddress]
functions.append(functionName) functions.append(functionName)
...@@ -94,7 +95,7 @@ for function in profiled_list: ...@@ -94,7 +95,7 @@ for function in profiled_list:
try: try:
addrs = functionAddressMap[function] addrs = functionAddressMap[function]
symbols_found = symbols_found + 1 symbols_found = symbols_found + 1
except: except Exception:
addrs = [] addrs = []
# sys.stderr.write ("WARNING: could not find symbol " + function + "\n") # sys.stderr.write ("WARNING: could not find symbol " + function + "\n")
for addr in addrs: for addr in addrs:
......
...@@ -39,7 +39,6 @@ def ParseLogLines(log_file_lines): ...@@ -39,7 +39,6 @@ def ParseLogLines(log_file_lines):
function address called) function address called)
""" """
call_lines = [] call_lines = []
has_started = False
vm_start = 0 vm_start = 0
line = log_file_lines[0] line = log_file_lines[0]
assert("r-xp" in line) assert("r-xp" in line)
...@@ -113,6 +112,7 @@ def ParseLibSymbols(lib_file): ...@@ -113,6 +112,7 @@ def ParseLibSymbols(lib_file):
class SymbolNotFoundException(Exception): class SymbolNotFoundException(Exception):
def __init__(self,value): def __init__(self,value):
super(SymbolNotFoundException,self).__init__(value)
self.value = value self.value = value
def __str__(self): def __str__(self):
return repr(self.value) return repr(self.value)
...@@ -201,7 +201,6 @@ def main(): ...@@ -201,7 +201,6 @@ def main():
(log_file, lib_file) = args (log_file, lib_file) = args
output_type = options.output_type output_type = options.output_type
lib_name = lib_file.split('/')[-1].strip()
log_file_lines = map(string.rstrip, open(log_file).readlines()) log_file_lines = map(string.rstrip, open(log_file).readlines())
call_info = ParseLogLines(log_file_lines) call_info = ParseLogLines(log_file_lines)
(unique_addrs, address_map) = ParseLibSymbols(lib_file) (unique_addrs, address_map) = ParseLibSymbols(lib_file)
...@@ -229,7 +228,7 @@ def main(): ...@@ -229,7 +228,7 @@ def main():
for symbol in symbols: for symbol in symbols:
print '.text.' + symbol print '.text.' + symbol
print '' print ''
except SymbolNotFoundException as e: except SymbolNotFoundException:
sys.stderr.write('WARNING: Did not find function in binary. addr: ' sys.stderr.write('WARNING: Did not find function in binary. addr: '
+ hex(addr) + '\n') + hex(addr) + '\n')
else: else:
...@@ -243,7 +242,7 @@ def main(): ...@@ -243,7 +242,7 @@ def main():
print '\t\t\t\t\t' + symbol print '\t\t\t\t\t' + symbol
else: else:
first_symbol = False first_symbol = False
except SymbolNotFoundException as e: except SymbolNotFoundException:
sys.stderr.write('WARNING: Did not find function in binary. addr: ' sys.stderr.write('WARNING: Did not find function in binary. addr: '
+ hex(addr) + '\n') + hex(addr) + '\n')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment