-
Notifications
You must be signed in to change notification settings - Fork 1
/
Addr2line.py
80 lines (64 loc) · 2.32 KB
/
Addr2line.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# !/usr/bin/python3
# -*- coding: utf8 -*-
# author: moyichen
# date: 2020/6/1
from CmdHelper import *
from utils import *
class Addr2line(object):
class Dso(object):
def __init__(self):
self.symbol_to_address = {'mangled_name'}
def __init__(self):
self.so_map = {}
self.line_cache = {}
def get_so_map(self, so):
if so in self.so_map:
return self.so_map[so]
symbol_to_address = {}
symbols = GetCmdOutput(['arm-linux-androideabi-nm', '-DC', so])
symbols = symbols.split('\n')
for i in symbols:
m = re.match('(\\w+) [UVWTA] (.*)', i.strip())
if m:
addr = int(m.group(1), 16)
sym = m.group(2)
symbol_to_address[sym] = addr
self.so_map[so] = symbol_to_address
return symbol_to_address
def get_symbol_address(self, so, sym):
symbol_to_address = self.get_so_map(so)
if sym in symbol_to_address:
return symbol_to_address[sym]
return 0
def convert_one_rva(self, so, rva):
idx = so+hex(rva)
if idx in self.line_cache:
return self.line_cache[idx]
symbol_to_address = self.get_so_map(so)
if len(symbol_to_address) == 0:
return "" + hex(rva)
o = GetCmdOutput(['arm-linux-androideabi-addr2line', '-pifC', '-e', so, hex(rva)])
log_debug(o)
# o = o.strip().split('\n')
# f_name = o[0].strip()
# if f_name in symbol_to_address:
# f_name = f_name + '+' + hex(rva - symbol_to_address[f_name])
# source_line = o[1].strip()
result = o.strip()#f_name + " at " + source_line
self.line_cache[idx] = result
return result
def convert_rva_list(self, so_rva, so_path):
output = []
for so, rva in so_rva:
so = os.path.join(so_path, os.path.basename(so))
o = self.convert_one_rva(so, rva)
output.append(o)
return output
def convert_bacaktrace(self, so_rva_list, so_path):
backtraces = self.convert_rva_list(so_rva_list, so_path)
rvas = []
depth = 0
for (so, rva), f in zip(so_rva_list, backtraces):
rvas.append("#%02d pc 0x%08x : %s (%s)" % (depth, rva, so, f))
depth += 1
return rvas