Subversion Repositories HelenOS-historic

Rev

Rev 293 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 293 Rev 297
Line 6... Line 6...
6
 
6
 
7
MAXSTRING=63
7
MAXSTRING=63
8
symtabfmt = "<Q%ds" % (MAXSTRING+1)
8
symtabfmt = "<Q%ds" % (MAXSTRING+1)
9
 
9
 
10
 
10
 
11
objline = re.compile(r'([0-9a-f]+)\s+[lg]\s+F\s+\.text\s+[0-9a-f]+\s+(.*)$')
11
funcline = re.compile(r'([0-9a-f]+)\s+[lg]\s+F\s+\.text\s+([0-9a-f]+)\s+(.*)$')
-
 
12
bssline = re.compile(r'([0-9a-f]+)\s+[lg]\s+[a-zA-Z]\s+\.bss\s+([0-9a-f]+)\s+(.*)$')
-
 
13
dataline = re.compile(r'([0-9a-f]+)\s+[lg]\s+[a-zA-Z]\s+\.data\s+([0-9a-f]+)\s+(.*)$')
12
fileexp = re.compile(r'([^\s]+):\s+file format')
14
fileexp = re.compile(r'([^\s]+):\s+file format')
13
def read_obdump(inp):
15
def read_obdump(inp):
14
    result = {}
16
    funcs = {}
-
 
17
    data = {}
-
 
18
    bss ={}
15
    fname = ''
19
    fname = ''
16
    for line in inp:
20
    for line in inp:
17
        line = line.strip()
21
        line = line.strip()
18
        res = objline.match(line)
22
        res = funcline.match(line)
19
        if res:
23
        if res:
20
            result.setdefault(fname,[]).append((int(res.group(1),16),
24
            funcs.setdefault(fname,[]).append((int(res.group(1),16),
21
                                                 res.group(2)))
25
                                               res.group(3)))
-
 
26
            continue
-
 
27
        res = bssline.match(line)
-
 
28
        if res:
-
 
29
            start = int(res.group(1),16)
-
 
30
            end = int(res.group(2),16)
-
 
31
            if end:
-
 
32
                bss.setdefault(fname,[]).append((start,res.group(3)))
-
 
33
        res = dataline.match(line)
-
 
34
        if res:
-
 
35
            start = int(res.group(1),16)
-
 
36
            end = int(res.group(2),16)
-
 
37
            if end:
-
 
38
                data.setdefault(fname,[]).append((start,res.group(3)))
22
        res = fileexp.match(line)
39
        res = fileexp.match(line)
23
        if res:
40
        if res:
24
            fname = res.group(1)
41
            fname = res.group(1)
25
            continue
42
            continue
26
   
-
 
27
    return result
-
 
28
 
43
 
-
 
44
    return {
-
 
45
        'text' : funcs,
-
 
46
        'bss' : bss,
-
 
47
        'data' : data
-
 
48
        }
-
 
49
 
29
startfile = re.compile(r'\.text\s+(0x[0-9a-f]+)\s+0x[0-9a-f]+\s+(.*)$')
50
startfile = re.compile(r'\.(text|bss|data)\s+(0x[0-9a-f]+)\s+0x[0-9a-f]+\s+(.*)$')
30
def generate(kmapf, obmapf, out):
51
def generate(kmapf, obmapf, out):
31
    obdump = read_obdump(obmapf)
52
    obdump = read_obdump(obmapf)    
32
 
53
 
33
    def sorter(x,y):
54
    def sorter(x,y):
34
        return cmp(x[0],y[0])
55
        return cmp(x[0],y[0])
35
 
56
 
36
    for line in kmapf:
57
    for line in kmapf:
37
        line = line.strip()
58
        line = line.strip()
38
        res = startfile.match(line)
59
        res = startfile.match(line)
-
 
60
 
39
        if res and obdump.has_key(res.group(2)):
61
        if res and obdump[res.group(1)].has_key(res.group(3)):
40
            offset = int(res.group(1),16)
62
            offset = int(res.group(2),16)
41
            fname = res.group(2)
63
            fname = res.group(3)
42
            symbols = obdump[fname]
64
            symbols = obdump[res.group(1)][fname]
43
            symbols.sort(sorter)
65
            symbols.sort(sorter)
44
            for addr,symbol in symbols:
66
            for addr,symbol in symbols:                
45
                value = fname + ':' + symbol
67
                value = fname + ':' + symbol
46
                data = struct.pack(symtabfmt,addr+offset,value[:MAXSTRING])
68
                data = struct.pack(symtabfmt,addr+offset,value[:MAXSTRING])
47
                out.write(data)
69
                out.write(data)
48
               
70
               
49
    out.write(struct.pack(symtabfmt,0,''))
71
    out.write(struct.pack(symtabfmt,0,''))