-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfresolve
executable file
·52 lines (48 loc) · 1.4 KB
/
fresolve
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
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
# resolve ftracer hex addresses
# fresolve elf-binary
# only works for a single binary, no shared libraries
import bisect
import subprocess
import sys
import re
# must match printf field size used in ftracer.c
FIELDSIZE = 25
FUNC_START = 20
FUNC_END = 21+FIELDSIZE
if len(sys.argv) < 2:
print "usage: fresolve elf-executable < ftracer_log"
sys.exit(1)
pipe = subprocess.Popen("nm " + sys.argv[1], shell=True,
stdout=subprocess.PIPE).stdout
symtab = []
adresses = []
max = 0
for l in pipe:
m = re.match(r"^([0-9a-f]+) \S (\w+)", l)
if m:
val = int(m.group(1), 16)
if val > max:
max = val
pos = bisect.bisect_left(adresses, val)
adresses.insert(pos, val)
symtab.insert(pos, m.group(2))
for l in sys.stdin:
f = l[FUNC_START:FUNC_END]
m = re.match(r"( *)(0x[0-9a-f]+)", f)
if not m:
print l,
else:
adr = int(m.group(2), 16)
if adr > max + 1000:
print l,
continue
n = bisect.bisect_left(adresses, adr) - 1
if n >= len(adresses):
print l,
continue
sym = symtab[n]
print (l[:FUNC_START] +
m.group(1) +
"%.*s" % (FIELDSIZE - len(m.group(1)), symtab[n]) +
l[FUNC_END:]),