|
43 | 43 | import time |
44 | 44 | import uuid |
45 | 45 |
|
46 | | -def read_plist(s): |
47 | | - if sys.version_info.major == 3: |
48 | | - return plistlib.loads(s) |
49 | | - else: |
50 | | - return plistlib.readPlistFromString(s) |
51 | | - |
52 | 46 | try: |
53 | | - # Just try for LLDB in case PYTHONPATH is already correctly setup |
| 47 | + # First try for LLDB in case PYTHONPATH is already correctly setup. |
54 | 48 | import lldb |
55 | 49 | except ImportError: |
56 | | - lldb_python_dirs = list() |
57 | | - # lldb is not in the PYTHONPATH, try some defaults for the current platform |
58 | | - platform_system = platform.system() |
59 | | - if platform_system == 'Darwin': |
60 | | - # On Darwin, try the currently selected Xcode directory |
61 | | - xcode_dir = subprocess.check_output("xcode-select --print-path", shell=True).decode("utf-8") |
62 | | - if xcode_dir: |
63 | | - lldb_python_dirs.append( |
64 | | - os.path.realpath( |
65 | | - xcode_dir + |
66 | | - '/../SharedFrameworks/LLDB.framework/Resources/Python')) |
67 | | - lldb_python_dirs.append( |
68 | | - xcode_dir + '/Library/PrivateFrameworks/LLDB.framework/Resources/Python') |
69 | | - lldb_python_dirs.append( |
70 | | - '/System/Library/PrivateFrameworks/LLDB.framework/Resources/Python') |
71 | | - success = False |
72 | | - for lldb_python_dir in lldb_python_dirs: |
73 | | - if os.path.exists(lldb_python_dir): |
74 | | - if not (sys.path.__contains__(lldb_python_dir)): |
75 | | - sys.path.append(lldb_python_dir) |
76 | | - try: |
77 | | - import lldb |
78 | | - except ImportError: |
79 | | - pass |
80 | | - else: |
81 | | - print('imported lldb from: "%s"' % (lldb_python_dir)) |
82 | | - success = True |
83 | | - break |
84 | | - if not success: |
| 50 | + # Ask the command line driver for the path to the lldb module. Copy over |
| 51 | + # the environment so that SDKROOT is propagated to xcrun. |
| 52 | + env = os.environ.copy() |
| 53 | + env['LLDB_DEFAULT_PYTHON_VERSION'] = str(sys.version_info.major) |
| 54 | + command = ['xcrun', 'lldb', '-P'] if platform.system() == 'Darwin' else ['lldb', '-P'] |
| 55 | + # Extend the PYTHONPATH if the path exists and isn't already there. |
| 56 | + lldb_python_path = subprocess.check_output(command, env=env).decode("utf-8").strip() |
| 57 | + if os.path.exists(lldb_python_path) and not sys.path.__contains__(lldb_python_path): |
| 58 | + sys.path.append(lldb_python_path) |
| 59 | + # Try importing LLDB again. |
| 60 | + try: |
| 61 | + import lldb |
| 62 | + except ImportError: |
85 | 63 | print("error: couldn't locate the 'lldb' module, please set PYTHONPATH correctly") |
86 | 64 | sys.exit(1) |
87 | 65 |
|
88 | 66 | from lldb.utils import symbolication |
89 | 67 |
|
| 68 | + |
| 69 | +def read_plist(s): |
| 70 | + if sys.version_info.major == 3: |
| 71 | + return plistlib.loads(s) |
| 72 | + else: |
| 73 | + return plistlib.readPlistFromString(s) |
| 74 | + |
| 75 | + |
90 | 76 | PARSE_MODE_NORMAL = 0 |
91 | 77 | PARSE_MODE_THREAD = 1 |
92 | 78 | PARSE_MODE_IMAGES = 2 |
@@ -442,13 +428,13 @@ def __init__(self, path, verbose): |
442 | 428 | continue |
443 | 429 | elif line.startswith('Exception Subtype:'): # iOS |
444 | 430 | self.thread_exception_data = line[18:].strip() |
445 | | - continue |
| 431 | + continue |
446 | 432 | elif line.startswith('Crashed Thread:'): |
447 | 433 | self.crashed_thread_idx = int(line[15:].strip().split()[0]) |
448 | 434 | continue |
449 | 435 | elif line.startswith('Triggered by Thread:'): # iOS |
450 | 436 | self.crashed_thread_idx = int(line[20:].strip().split()[0]) |
451 | | - continue |
| 437 | + continue |
452 | 438 | elif line.startswith('Report Version:'): |
453 | 439 | self.version = int(line[15:].strip()) |
454 | 440 | continue |
|
0 commit comments