Bugfix: Adjustments for Mac OS X 10.11 (El Capitan). Author: Martin Beaudoin. Merge...
[foam-extend-3.2.git] / bin / addr2line4Mac.py
blob54a40f1a886bc6ead37cdfdca9332b7d0eed7b9e
1 #! /usr/bin/python
3 import sys
4 filename=sys.argv[1]
5 address=sys.argv[2]
6 import re
7 from os import environ,path
9 fullFile=None
10 if path.exists(filename):
11 fullFile=filename
13 for v in ["PATH","LD_LIBRARY_PATH"]:
14 if not fullFile:
15 for d in environ[v].split(':'):
16 if path.exists(path.join(d,filename)):
17 fullFile=path.join(d,filename)
18 break
20 if not fullFile:
21 fullFile=filename
23 answer="??:0"
25 if path.exists(fullFile):
26 import subprocess
28 result=subprocess.Popen(["xcrun", "atos",
29 "-o",fullFile,
30 address],
31 stdout=subprocess.PIPE
32 ).communicate()[0]
33 match=re.compile('.+ \((.+)\) \((.+)\)').match(result)
34 if match:
35 answer=match.group(2)+" "+match.group(1)
36 else:
37 import os
38 result=subprocess.Popen(["xcrun", "atos",
39 "-p",str(os.getppid()),
40 address],
41 stdout=subprocess.PIPE
42 ).communicate()[0]
43 match=re.compile('.+ \((.+)\) \((.+)\)').match(result)
44 if match:
45 answer=match.group(2)+" "+match.group(1)
47 print answer,
49 sys.exit(255)