source: mainline/src/debug/genmap.py@ dd80fc6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since dd80fc6 was b6d20a7, checked in by Ondrej Palkovsky <ondrap@…>, 20 years ago

Symbols now include filename

  • Property mode set to 100755
File size: 1.6 KB
RevLine 
[ab08b42]1#!/usr/bin/env python
2
3import sys
4import struct
5import re
6
7symline = re.compile(r'(0x[a-f0-9]+)\s+([^\s]+)$')
[b6d20a7]8fileline = re.compile(r'[^\s]+\s+0x[a-f0-9]+\s+0x[a-f0-9]+\s+([^\s]+\.o)$')
9
10MAXSTRING=63
11symtabfmt = "<Q%ds" % (MAXSTRING+1)
[ab08b42]12
13def read_symbols(inp):
14 while 1:
15 line = inp.readline()
16 if not line:
17 return
18 if 'memory map' in line:
19 break
20
21 symtable = {}
[b6d20a7]22 filename = ''
[ab08b42]23 while 1:
24 line = inp.readline()
25 if not line.strip():
26 continue
27 if line[0] not in (' ','.'):
28 break
29 line = line.strip()
[b6d20a7]30 # Search for file name
31 res = fileline.match(line)
32 if res:
33 filename = res.group(1)
34 # Search for symbols
[ab08b42]35 res = symline.match(line)
36 if res:
[b6d20a7]37 symtable[int(res.group(1),16)] = filename + ':' + res.group(2)
[ab08b42]38 return symtable
39
40def generate(inp, out):
41 symtab = read_symbols(inp)
42 if not symtab:
43 print "Bad kernel.map format, empty."
44 sys.exit(1)
45 addrs = symtab.keys()
46 addrs.sort()
47 for addr in addrs:
48 # Do not write address 0, it indicates end of data
49 if addr == 0:
50 continue
51 data = struct.pack(symtabfmt,addr,symtab[addr][:MAXSTRING])
52 out.write(data)
53 out.write(struct.pack(symtabfmt,0,''))
54
55def main():
56 if len(sys.argv) != 3:
57 print "Usage: %s <kernel.map> <output.bin>" % sys.argv[0]
58 sys.exit(1)
59
60 inp = open(sys.argv[1],'r')
61 out = open(sys.argv[2],'w')
62 generate(inp,out)
63 inp.close()
64 out.close()
65
66if __name__ == '__main__':
67 main()
Note: See TracBrowser for help on using the repository browser.