The findCloseAddress() function receives an input parameter ram.map file "ramMapFile", and search inside it for the function with the closest address to the input parameter "reqAddress".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | def findCloseAddress (ramMapFile, reqAddress):
"""
Find similar address in file
"""
from sys import maxint as MAXINT
fd = open (ramMapFile, 'r')
foundLine = ""
smallestDiff = MAXINT
for line in fd:
if "SYMBOL TABLE:" in line :
break
for line in fd:
linePart = line.split()
if len(linePart) > 0:
currAddress = int(linePart[0], 16)
diff = reqAddress - currAddress
if diff < smallestDiff and diff >= 0:
smallestDiff = diff
foundLine = ''.join(line)
print "\nRequired Address : 0x%x" % reqAddress
print "\nClosest Line :\n%s" % foundLine
print "\nDifference : 0x%x (%d instructions)" % (smallestDiff, smallestDiff / 4)
if __name__ == "__main__":
mapFile = r"C:\default\ram.map"
reqAddress = 0xffffffff803130cc
findCloseAddress (mapFile, reqAddress)
|
I have run into system crash during my work on Vxworks 5.5 systems, in which the system doesn't say in which function it crashed, but rather an address of the instruction that caused the failure. Searching this address in the ram.map took a lot of time. This function findCloseAddress() in the script goes through the ram.map file, and finds the function with the closest address to the value supplied to it.