Bug 1282184 - Use lldb from Xcode install rather than system install if possible. r=ted
authorEric Rahm <erahm@mozilla.com>
Tue, 28 Jun 2016 11:50:16 -0700
changeset 382182 14663c45b49b8998e61c22c489357424948cfe6d
parent 382181 2b0a234db73110df9317a3d03fac6e58db83870e
child 382183 eef51590d89c21ed69e5186ba3f22c5183cbcf9d
push id21645
push userbmo:gasolin@mozilla.com
push dateWed, 29 Jun 2016 04:02:20 +0000
reviewersted
bugs1282184
milestone50.0a1
Bug 1282184 - Use lldb from Xcode install rather than system install if possible. r=ted This works around issues with System Integrity Protection kicking in on OSX when trying to run /usr/bin/lldb by attempting to using the version installed with XCode's command line utilities. In particular SIP prevents us from setting DYLD_LIBRARY_PATH which is needed to run DMD.
testing/mozbase/mozdebug/mozdebug/mozdebug.py
--- a/testing/mozbase/mozdebug/mozdebug/mozdebug.py
+++ b/testing/mozbase/mozdebug/mozdebug/mozdebug.py
@@ -3,16 +3,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import os
 import mozinfo
 from collections import namedtuple
 from distutils.spawn import find_executable
+from subprocess import check_output
 
 __all__ = ['get_debugger_info',
            'get_default_debugger_name',
            'DebuggerSearch',
            'get_default_valgrind_args']
 
 '''
 Map of debugging programs to information about them, like default arguments
@@ -75,16 +76,40 @@ def _windbg_installation_paths():
 
     for suffix in programFilesSuffixes:
         windowsKitsPrefix = os.path.join(programFiles + suffix,
                                          'Windows Kits')
         for version in windowsKitsVersions:
             yield os.path.join(windowsKitsPrefix, version,
                                'Debuggers', 'x86', 'windbg.exe')
 
+def get_debugger_path(debugger):
+    '''
+    Get the full path of the debugger.
+
+    :param debugger: The name of the debugger.
+    '''
+
+    if mozinfo.os == 'mac' and debugger == 'lldb':
+        # On newer OSX versions System Integrity Protections prevents us from
+        # setting certain env vars for a process such as DYLD_LIBRARY_PATH if
+        # it's in a protected directory such as /usr/bin. This is the case for
+        # lldb, so we try to find an instance under the Xcode install instead.
+
+        # Attempt to use the xcrun util to find the path.
+        try:
+            path = check_output(['xcrun', '--find', 'lldb']).strip()
+            if path:
+                return path
+        except:
+            # Just default to find_executable instead.
+            pass
+
+    return find_executable(debugger)
+
 def get_debugger_info(debugger, debuggerArgs = None, debuggerInteractive = False):
     '''
     Get the information about the requested debugger.
 
     Returns a dictionary containing the |path| of the debugger executable,
     if it will run in |interactive| mode, its arguments and whether it needs
     to escape arguments it passes to the debugged program (|requiresEscapedArgs|).
     If the debugger cannot be found in the system, returns |None|.
@@ -100,17 +125,17 @@ def get_debugger_info(debugger, debugger
 
     if debugger:
         # Append '.exe' to the debugger on Windows if it's not present,
         # so things like '--debugger=devenv' work.
         if (os.name == 'nt'
             and not debugger.lower().endswith('.exe')):
             debugger += '.exe'
 
-        debuggerPath = find_executable(debugger)
+        debuggerPath = get_debugger_path(debugger)
 
     if not debuggerPath:
         # windbg is not installed with the standard set of tools, and it's
         # entirely possible that the user hasn't added the install location to
         # PATH, so we have to be a little more clever than normal to locate it.
         # Just try to look for it in the standard installed location(s).
         if debugger == 'windbg.exe':
             for candidate in _windbg_installation_paths():