Skip to content

Commit

Permalink
Fix pylint error in patch_orderfile and symbolize.
Browse files Browse the repository at this point in the history
BUG=

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

Cr-Commit-Position: refs/heads/master@{#308081}
  • Loading branch information
azarchs authored and Commit bot committed Dec 12, 2014
1 parent 7329c2c commit 6d49e5c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
33 changes: 17 additions & 16 deletions tools/cygprofile/patch_orderfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,27 @@
else:
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:
(nm_addr, size) = uniqueAddrs[start]
if not (addr >= nm_addr and addr < nm_addr + size):
sys.stderr.write ("ERROR: did not find function in binary: addr: " +
hex(addr) + " nm_addr: " + str(nm_addr) + " start: " + str(start) +
" end: " + str(end) + "\n")
raise Error("error")
return (addressMap[nm_addr], size)
(nm_addr, sym_size) = uniqueAddrs[start]
if not (search_addr >= nm_addr and search_addr < nm_addr + sym_size):
error_message = ('ERROR: did not find function in binary: addr: ' +
hex(addr) + ' nm_addr: ' + str(nm_addr) + ' start: ' +
str(start) + ' end: ' + str(end))
sys.stderr.write(error_message + "\n")
raise Exception(error_message)
return (addressMap[nm_addr], sym_size)
else:
halfway = start + ((end - start) / 2)
(nm_addr, size) = uniqueAddrs[halfway]
if (addr >= nm_addr and addr < nm_addr + size):
return (addressMap[nm_addr], size)
nm_addr = uniqueAddrs[halfway][0]
if (addr >= nm_addr and addr < nm_addr + sym_size):
return (addressMap[nm_addr], sym_size)
elif (addr < nm_addr):
return binary_search (addr, start, halfway)
elif (addr >= nm_addr + size):
elif (addr >= nm_addr + sym_size):
return binary_search (addr, halfway, end)
else:
raise "ERROR: did not expect this case"
raise Exception("ERROR: did not expect this case")

f = open (orderfile)
lines = f.readlines()
Expand All @@ -77,13 +78,13 @@ def binary_search (addr, start, end):
for line in nmlines:
try:
functionName = line.split()[3]
except:
except Exception:
functionName = line.split()[2]
functionName = functionName.split('.clone.')[0]
functionAddress = int (line.split()[0].strip(), 16)
try:
functionAddressMap[functionName].append(functionAddress)
except:
except Exception:
functionAddressMap[functionName] = [functionAddress]
functions.append(functionName)

Expand All @@ -94,7 +95,7 @@ def binary_search (addr, start, end):
try:
addrs = functionAddressMap[function]
symbols_found = symbols_found + 1
except:
except Exception:
addrs = []
# sys.stderr.write ("WARNING: could not find symbol " + function + "\n")
for addr in addrs:
Expand Down
7 changes: 3 additions & 4 deletions tools/cygprofile/symbolize.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def ParseLogLines(log_file_lines):
function address called)
"""
call_lines = []
has_started = False
vm_start = 0
line = log_file_lines[0]
assert("r-xp" in line)
Expand Down Expand Up @@ -113,6 +112,7 @@ def ParseLibSymbols(lib_file):

class SymbolNotFoundException(Exception):
def __init__(self,value):
super(SymbolNotFoundException,self).__init__(value)
self.value = value
def __str__(self):
return repr(self.value)
Expand Down Expand Up @@ -201,7 +201,6 @@ def main():
(log_file, lib_file) = args
output_type = options.output_type

lib_name = lib_file.split('/')[-1].strip()
log_file_lines = map(string.rstrip, open(log_file).readlines())
call_info = ParseLogLines(log_file_lines)
(unique_addrs, address_map) = ParseLibSymbols(lib_file)
Expand Down Expand Up @@ -229,7 +228,7 @@ def main():
for symbol in symbols:
print '.text.' + symbol
print ''
except SymbolNotFoundException as e:
except SymbolNotFoundException:
sys.stderr.write('WARNING: Did not find function in binary. addr: '
+ hex(addr) + '\n')
else:
Expand All @@ -243,7 +242,7 @@ def main():
print '\t\t\t\t\t' + symbol
else:
first_symbol = False
except SymbolNotFoundException as e:
except SymbolNotFoundException:
sys.stderr.write('WARNING: Did not find function in binary. addr: '
+ hex(addr) + '\n')

Expand Down

0 comments on commit 6d49e5c

Please sign in to comment.