Patch configure so that we dont need a seperate spec file for x86_64. Pass info about...
[AROS.git] / tools / vgpostprocess.py
blob6e8fd4840ab79bc6acafc2c8e37661f91eccc022
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 # Flags entries with no name
37 if (symbolname == ""):
38 symbolname = "<no name>"
40 # Ignore entries with no address
41 if (start != 0 and end != 0):
42 symbol = (symbolname, start, end)
43 module.minaddr = min(start, module.minaddr)
44 module.maxaddr = max(end, module.maxaddr)
45 module.symbols.append(symbol)
47 return modules
49 def addmodulespec(line, module, output):
50 if (line[0] == 'c'):
51 prefix="c"
52 else:
53 prefix=""
55 if (module.id == -1):
56 module.id = addmodulespec.nextmoduleid
57 addmodulespec.nextmoduleid += 1
58 modulename = " " + module.name
59 else:
60 modulename = ""
62 output.write(prefix + "ob=(" + str(module.id) + ")" + modulename + os.linesep)
64 def main():
66 modules = loadsymbolinformation()
68 addmodulespec.nextmoduleid = 1000
70 print "Processing..."
72 reg = r'([c]*fn=\(\d*\) )0x([a-f0-9]*)'
73 output = open(sys.argv[1] + ".processed", "w")
74 with open(sys.argv[1]) as log:
75 for line in log:
76 match = re.match(reg, line)
77 if match:
78 address = int(match.group(2), 16)
79 for module in modules:
80 # Skip modules that can't host this address
81 if (address < module.minaddr):
82 continue
83 if (address > module.maxaddr):
84 continue
86 for symbol in module.symbols:
87 if (symbol[1] <= address and symbol[2] >= address):
88 # Write out additional module spec
89 addmodulespec(line, module, output)
91 # Build out actuall symbol information
92 line = match.group(1) + symbol[0] + os.linesep
93 break
95 output.write(line)
97 output.close()
99 # Usage: vgpostprocess.py callgrind.out.<pid> symbols.out
101 if __name__ == "__main__":
102 main()