X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/3903760236c30e3b5ace7a4eefac3a269d68957c..c3c9b80d004dbbfdf763edeb97968c6997e3b45b:/tools/lldbmacros/core/xnu_lldb_init.py diff --git a/tools/lldbmacros/core/xnu_lldb_init.py b/tools/lldbmacros/core/xnu_lldb_init.py old mode 100644 new mode 100755 index 41dd202b9..c0f1a8002 --- a/tools/lldbmacros/core/xnu_lldb_init.py +++ b/tools/lldbmacros/core/xnu_lldb_init.py @@ -1,10 +1,15 @@ +from __future__ import absolute_import +from __future__ import print_function import os +import sys import re +PY3 = sys.version_info > (3,) + def GetSettingsValues(debugger, setting_variable_name): """ Queries the lldb internal settings params: - debugger : lldb.SBDebugger instance + debugger : lldb.SBDebugger instance setting_variable_name: str - string name of the setting(eg prompt) returns: [] : Array of strings. Empty array if setting is not found/set @@ -66,9 +71,16 @@ def __lldb_init_module(debugger, internal_dict): if "DEBUG_XNU_LLDBMACROS" in os.environ and len(os.environ['DEBUG_XNU_LLDBMACROS']) > 0: debug_session_enabled = True prev_os_plugin = "".join(GetSettingsValues(debugger, 'target.process.python-os-plugin-path')) - print "Loading kernel debugging from %s" % __file__ - print "LLDB version %s" % debugger.GetVersionString() - self_path = str(__file__) + if PY3: + print("#" * 30) + print("WARNING! Python version 3 is not supported for xnu lldbmacros.") + print("Please restart your debugging session with the following workaround") + print("\ndefaults write com.apple.dt.lldb DefaultPythonVersion 2\n") + print("#" * 30) + print("\n") + print("Loading kernel debugging from %s" % __file__) + print("LLDB version %s" % debugger.GetVersionString()) + self_path = "{}".format(__file__) base_dir_name = self_path[:self_path.rfind("/")] core_os_plugin = base_dir_name + "/lldbmacros/core/operating_system.py" osplugin_cmd = "settings set target.process.python-os-plugin-path \"%s\"" % core_os_plugin @@ -77,6 +89,7 @@ def __lldb_init_module(debugger, internal_dict): whitelist_trap_cmd = "settings set target.trap-handler-names %s %s" % (' '.join(intel_whitelist), ' '.join(arm_whitelist)) xnu_debug_path = base_dir_name + "/lldbmacros/xnu.py" xnu_load_cmd = "command script import \"%s\"" % xnu_debug_path + disable_optimization_warnings_cmd = "settings set target.process.optimization-warnings false" source_map_cmd = "" try: @@ -85,20 +98,40 @@ def __lldb_init_module(debugger, internal_dict): pass if debug_session_enabled : if len(prev_os_plugin) > 0: - print "\nDEBUG_XNU_LLDBMACROS is set. Skipping the setting of OS plugin from dSYM.\nYou can manually set the OS plugin by running\n" + osplugin_cmd + print("\nDEBUG_XNU_LLDBMACROS is set. Skipping the setting of OS plugin from dSYM.\nYou can manually set the OS plugin by running\n" + osplugin_cmd) else: - print osplugin_cmd + print(osplugin_cmd) debugger.HandleCommand(osplugin_cmd) - print "\nDEBUG_XNU_LLDBMACROS is set. Skipping the load of xnu debug framework.\nYou can manually load the framework by running\n" + xnu_load_cmd + print("\nDEBUG_XNU_LLDBMACROS is set. Skipping the load of xnu debug framework.\nYou can manually load the framework by running\n" + xnu_load_cmd) else: - print osplugin_cmd + print(osplugin_cmd) debugger.HandleCommand(osplugin_cmd) - print whitelist_trap_cmd + print(whitelist_trap_cmd) debugger.HandleCommand(whitelist_trap_cmd) - print xnu_load_cmd + print(xnu_load_cmd) debugger.HandleCommand(xnu_load_cmd) + print(disable_optimization_warnings_cmd) + debugger.HandleCommand(disable_optimization_warnings_cmd) if source_map_cmd: - print source_map_cmd + print(source_map_cmd) debugger.HandleCommand(source_map_cmd) - print "\n" + + load_kexts = True + if "XNU_LLDBMACROS_NOBUILTINKEXTS" in os.environ and len(os.environ['XNU_LLDBMACROS_NOBUILTINKEXTS']) > 0: + load_kexts = False + builtinkexts_path = os.path.join(os.path.dirname(self_path), "lldbmacros", "builtinkexts") + if os.access(builtinkexts_path, os.F_OK): + kexts = os.listdir(builtinkexts_path) + if len(kexts) > 0: + print("\nBuiltin kexts: %s\n" % kexts) + if load_kexts == False: + print("XNU_LLDBMACROS_NOBUILTINKEXTS is set, not loading:\n") + for kextdir in kexts: + script = os.path.join(builtinkexts_path, kextdir, kextdir.split('.')[-1] + ".py") + import_kext_cmd = "command script import \"%s\"" % script + print("%s" % import_kext_cmd) + if load_kexts: + debugger.HandleCommand(import_kext_cmd) + + print("\n")