]>
git.saurik.com Git - apple/xnu.git/blob - tools/symbolify.py
2 from subprocess
import Popen
, PIPE
, call
9 NM_FORMAT
= "([0-9a-f]+) ([UuAaTtDdBbCcSsIi]) (.*)"
11 nm_re
= re
.compile(NM_FORMAT
)
13 def parse_nm_output(str):
14 "returns (start, type, name)"
17 start
= int(m
.group(1), 16)
18 return (start
, m
.group(2), m
.group(3))
24 p
= Popen(cmd
, shell
=True, stdout
=PIPE
)
28 def __init__(self
, file, min_width
=16):
29 self
.min_width
= min_width
30 self
.symbols
= [parse_nm_output(l
) for l
in nm(file)]
31 self
.symbols
.sort(key
=lambda x
: x
[0])
33 def padded(self
, str):
34 return ("%%%ds" % self
.min_width
) % str
36 def __call__(self
, saddr
):
37 addr
= int(saddr
.group(0), 16)
38 last
= (0, ' ', '<start of file>')
41 # stupid linear search... feel free to improve
42 for s
in self
.symbols
:
44 return self
.padded(s
[2])
46 if last
[2] == "_last_kernel_symbol":
48 return self
.padded("<%s>+%x" % (last
[2], addr
- last
[0]))
51 if last
[2] == "_last_kernel_symbol":
53 return self
.padded("<%s>+%x" % (last
[2], addr
- last
[0]))
55 def symbolify(objfile
, input, *args
, **kargs
):
56 replacer
= SymbolLookup(objfile
, *args
, **kargs
)
58 print re
.sub("(0x)?[0-9a-f]{6,16}", replacer
, l
),
63 print "usage: %s [filename] [slide]" % sys
.argv
[0]
64 print "\tor speficy a filename in your SYMBOLIFY_KERNEL environment variable"
71 if( len(sys
.argv
) > 3 ):
74 if( len(sys
.argv
) == 3 ):
75 SLIDE
= int(sys
.argv
[2], 16)
77 if( len(sys
.argv
) >= 2 ):
78 KERNEL_FILE
= sys
.argv
[1]
80 if( KERNEL_FILE
is None ):
81 KERNEL_FILE
= os
.environ
.get("SYMBOLIFY_KERNEL")
83 if( KERNEL_FILE
is None ):
86 print "using kernel file '%s', slide 0x%x" % (KERNEL_FILE
, SLIDE
)
88 symbolify(KERNEL_FILE
, sys
.stdin
, min_width
=40)