2 # Annotate the output of ncval with line numbers, taken from debugging
3 # information using binutils' addr2line.
12 ncval
= os
.path
.join(os
.path
.dirname(__file__
),
13 "../scons-out/dbg-linux/staging/ncval")
16 objdump_regexp
= re
.compile(r
"\s*([0-9a-f]+):")
22 def disassemble_address(addr
):
23 proc
= subprocess
.Popen(
24 ["objdump", "-d", obj_file
, "--start-address", "0x" + addr
,
25 "--stop-address", "0x%x" % (int(addr
, 16) + 16)],
26 stdout
=subprocess
.PIPE
)
27 for line
in proc
.stdout
:
28 match
= objdump_regexp
.match(line
)
30 sys
.stdout
.write(line
)
33 def decode_address(addr
):
34 proc
= subprocess
.Popen(
35 ["addr2line", "-f", "-i", "-e", obj_file
, addr
],
36 stdout
=subprocess
.PIPE
)
37 for info
in proc
.stdout
:
38 sys
.stdout
.write(" %s: %s" % (addr
, info
))
40 filename
, lineno
= info
.split(":", 1)
41 src_line
= linecache
.getline(filename
, int(lineno
))
43 sys
.stdout
.write(" " + src_line
.lstrip())
45 proc
= subprocess
.Popen([ncval
, obj_file
], stdout
=subprocess
.PIPE
)
46 regexp
= re
.compile("[0-9a-f]{3,}")
47 for line
in proc
.stdout
:
48 sys
.stdout
.write(line
)
49 if line
.startswith("VALIDATOR:"):
50 match
= regexp
.search(line
)
53 disassemble_address(addr
)
57 if __name__
== "__main__":