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