MUIM_List_TestPos now treats the last column as extending to the
[AROS.git] / tools / vgpostprocess.py
blob69ccbc45bca78e5d39facd737cbf144e11ad982f
1 import re, os, sys
3 class Module:
4 def __init__(self):
5 self.name = ""
6 self.id = -1
7 self.symbols = []
8 self.minaddr = 0xFFFFFFFF
9 self.maxaddr = 0
11 def loadsymbolinformation():
12 reg = r'S\|(.*)\|(.*)\|(.*)\|(.*)'
13 modules = []
14 symbols = []
15 lastmodname = ""
16 module = None
18 with open(sys.argv[2]) as f:
19 for line in f:
20 match = re.match(reg, line)
21 if match:
22 modname = match.group(1)
23 symbolname = match.group(2)
24 start = int(match.group(3), 16)
25 end = int(match.group(4), 16)
27 # New module is needed
28 if (modname != lastmodname):
29 if (module):
30 print "%s %x %x" % (module.name, module.minaddr, module.maxaddr)
31 module = Module()
32 module.name = modname
33 modules.append(module)
34 lastmodname = modname
36 # Correction of end
37 if (symbolname != "" and start > 0x1000 and end == 0):
38 end = start
40 # Flags entries with no name
41 if (symbolname == ""):
42 symbolname = "<no name>"
44 # Ignore entries with no address
45 if (start != 0 and end != 0):
46 symbol = (symbolname, start, end)
47 module.minaddr = min(start, module.minaddr)
48 module.maxaddr = max(end, module.maxaddr)
49 module.symbols.append(symbol)
51 return modules
53 def addmodulespec(line, module, output):
54 if (line[0] == 'c'):
55 prefix="c"
56 else:
57 prefix=""
59 if (module.id == -1):
60 module.id = addmodulespec.nextmoduleid
61 addmodulespec.nextmoduleid += 1
62 modulename = " " + module.name
63 else:
64 modulename = ""
66 output.write(prefix + "ob=(" + str(module.id) + ")" + modulename + os.linesep)
68 def main():
70 modules = loadsymbolinformation()
72 addmodulespec.nextmoduleid = 1000
74 print "Processing..."
76 reg = r'([c]*fn=\(\d*\) )0x([a-f0-9]*)'
77 output = open(sys.argv[1] + ".processed", "w")
78 with open(sys.argv[1]) as log:
79 for line in log:
80 match = re.match(reg, line)
81 if match:
82 address = int(match.group(2), 16)
83 for module in modules:
84 # Skip modules that can't host this address
85 if (address < module.minaddr):
86 continue
87 if (address > module.maxaddr):
88 continue
90 for symbol in module.symbols:
91 if (symbol[1] <= address and symbol[2] >= address):
92 # Write out additional module spec
93 addmodulespec(line, module, output)
95 # Build out actuall symbol information
96 line = match.group(1) + symbol[0] + os.linesep
97 break
99 output.write(line)
101 output.close()
103 # Usage: vgpostprocess.py callgrind.out.<pid> symbols.out
105 if __name__ == "__main__":
106 main()