-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresolve_addr.py
executable file
·48 lines (38 loc) · 1.12 KB
/
resolve_addr.py
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
#!/usr/bin/python
#
# Resolve symbol address from running process
#
import sys
import time
from sample_reader import Mappings, SymbolResolver
if __name__ == '__main__':
if len(sys.argv) != 3:
print "Usage: %s <pid> <addr>" % sys.argv[0]
sys.exit(1)
pid = int(sys.argv[1])
addr = int(sys.argv[2], 0)
mappings = Mappings()
fd = open('/proc/%d/maps' % pid)
for line in fd:
line = line.rstrip('\n')
mappings.parseLine(line)
fd.close()
resolver = SymbolResolver(mappings)
res = resolver.resolve(addr)
#print res
# result contains: {binPath, offsetInBin, frames}
if res.has_key('frames'):
for frame in res['frames']:
# frame contains: (function name, source file, source line number)
if frame[0] is None:
print "??"
else:
print frame[0]
if frame[1] is None:
sys.stdout.write("??:")
else:
sys.stdout.write(frame[1]+":")
if frame[2] is None:
print "??"
else:
print frame[2]