-
Notifications
You must be signed in to change notification settings - Fork 466
/
Copy pathdecode.py
executable file
·85 lines (72 loc) · 2.66 KB
/
decode.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
81
82
83
84
85
#!/usr/bin/env python
import sys,re
# given a java backtrace file ("hs_err_pidNNN.log") and a symbol
# file (produced by make nativelibs/libhzee.sym), print a decoded
# backtrace for EE code.
class Decoder:
"Decode native symbols in a java backtrace file"
def loadSymbols(self, symfile):
# read the .sym file and store a list of address and a list
# of textual symbol names.
f = open(symfile)
for line in f:
match = re.compile("([0-9a-e]+)\s[tT]\s(.*)").match(line)
if match != None:
self.symbols.append(match.group(1))
self.symbols_strings.append(match.group(2))
f.close()
def decodeSymbol(self, aSym):
# convert aSym to an integer. do a linear search for aSym.
# (self.symbols is sorted, could improve to binary search)
# print out the last symbol that less than aSym.
# (could search backwards if this state offends you)
nLast = 0
nSym = int(aSym,16)
for idx, sym in enumerate(self.symbols):
nAddr = int("0x"+sym, 16)
if nAddr > nSym:
print hex(nSym) + " " + hex(nLast) + " " + self.symbols_strings[idx-1]
return
nLast = nAddr
def decode(self, logfile):
printnext = False
decodenext = False
f = open(logfile)
for line in f:
if re.compile("Stack").match(line):
# look for the stack and print next two informational lines
print line.strip()
printnext = True
continue
elif printnext:
print line.strip()
printnext = False
decodenext = True
continue
elif decodenext:
# decode until blank line. if native symbol can't be
# found, just print the line from the log file
if line == "\n":
decodenext = False
else:
match = re.compile(".*libhzee.so\+(.*)\]").match(line)
if match != None:
self.decodeSymbol(match.group(1))
else:
print line.strip()
continue
def __init__(self, symfile):
self.symbols = []
self.symbols_strings = []
self.loadSymbols(symfile)
def main(argv=None):
if (argv==None):
argv = sys.argv
if (len(argv) < 3):
print "debug.py <hs_err_pidNNN.log> <path/to/libhzee.sym>"
return -1
decoder = Decoder(argv[2])
decoder.decode(argv[1])
return 0
if __name__ == "__main__":
sys.exit(main())