2 # This is a wrapper for sel_ldr that annotates the backtrace it
3 # outputs with source code info.
10 def addr2line(obj_file
, addr
, indent
=""):
11 proc
= subprocess
.Popen(["addr2line", "-f", "-e", obj_file
, "%x" % addr
],
12 stdout
=subprocess
.PIPE
)
13 for line
in proc
.stdout
:
15 assert proc
.wait() == 0
20 maps
= [{"base": 0x20000, "offset": 0x20000, "size": 0x2d000,
21 "path": "install-stubout/lib/ld-linux.so.2", "file": "ld.so"}]
22 # TODO: don't assume executable's load address and size
23 maps
.append({"base": 0x1000000, "offset": 0, "size": 0x20000,
24 "path": executable
, "file": executable
})
31 m
= re
.search("trying file=(.*)", line
)
33 last_path
= m
.group(1)
35 m
= re
.search("file=(\S+).*generating link map", line
)
37 last_file
= m
.group(1)
39 m
= re
.search("base: (\S+)\s+size: (\S+)", line
)
41 # base value assumes this is an ET_DYN object.
42 info
= {"base": int(m
.group(1), 0),
43 "offset": int(m
.group(1), 0),
44 "size": int(m
.group(2), 0),
52 "install-stubout/lib/ld-linux.so.2",
53 "--", "--library-path", "install-stubout/lib",
55 proc
= subprocess
.Popen(
56 args
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
)
60 def decode_addr(addr
):
62 if obj
["base"] <= addr
< obj
["base"] + obj
["size"]:
63 offset
= addr
- obj
["offset"]
64 print " in %s: offset=%x" % (obj
["path"], offset
)
65 addr2line(obj
["path"], offset
, " ")
67 for line
in proc
.stdout
:
70 m
= re
.search("code_addr=(\S+)", line
)
72 decode_addr(int(m
.group(1), 16))
74 print "exit status:", proc
.wait()
75 print "libraries loaded:"
76 fmt
= " %(base)08x-%(end)08x size=%(size)08x file=%(file)s path=%(path)s"
77 for obj
in sorted(maps
, key
=lambda obj
: obj
["base"]):
78 obj
["end"] = obj
["base"] + obj
["size"]
82 if __name__
== "__main__":